From patchwork Mon Mar 6 11:34:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9606063 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 2741B6046A for ; Mon, 6 Mar 2017 13:44:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15ADB2723E for ; Mon, 6 Mar 2017 13:44:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A68C28418; Mon, 6 Mar 2017 13:44:08 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9A5982723E for ; Mon, 6 Mar 2017 13:44:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=XbcEkJqn0v/0nmrVVZrb01JBTEvp4odu6Qs1Ti+5aiI=; b=puK2Lm4eQ7X8Z+gJPx4Pa9gBjo 2clgU3bxpTn07iiFhPcvsuCmlXp96iKr+k4UH8haasOazYINhuK6lBcl018EkXU9scyC20F8wDD8V mo/xnfsse0V2TK5MIv4hAYdP5I2RnBgXJxvxS/TFkTYso16b/tvb9VGyphzQsvsAu0wCJ5AYfq+it x8vTL6E0DJ3E55hs2LeYE/zkzmBJhClmaY9B2KHJRESX09o+K7vjJN1D6BjeZ4Hhv2AuyCrqhVeHb X3+ICcOnfyqidedtebf7LsfEv78SZnhrPnWTCkY2wikVO/11TywANjAhE/ILTI7ZbeEs53nnvZ2gD Uk+q+6aQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cksvl-0006BN-Ju; Mon, 06 Mar 2017 13:44:05 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cksvj-0006Ab-10 for linux-arm-kernel@bombadil.infradead.org; Mon, 06 Mar 2017 13:44:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=O5DDurPbwaRUob4udyumSFVxwGl7NgFyavMwOof8aIo=; b=UPjUD0530+9Y/qAA6grciKr4X 083mCZwpRX+l/TOb6UpgQz0SKnSbL2lR8L77XA08pGIGZLTK4I6Sli+WFdPSvYcrO0qwC3PRumGot UD+vMmqFX7X2poeXVjpO/JT3mFX+re/s0/kFmmbzG0ZzVN42CR48eysU+bvJJ44cmhcNZaWO3T5Jz Mr4WIiyK9kLRC2VLqmXl0EKF9IYRW7yrlg0meQZnKYulEItP91/YCCGycOdxpt2GpAt0g8eoMP96S RkdVZ4uVFApatZEzuyZHqWubgqUFjIy7BRnTKvJBJfkkFANy3C/eayHDkuJ4Djh0TpeKMW9IfFY29 3lKZE2SwA==; Received: from mx1.redhat.com ([209.132.183.28]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ckqwS-0005GV-VH for linux-arm-kernel@lists.infradead.org; Mon, 06 Mar 2017 11:36:46 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 95383C04B326; Mon, 6 Mar 2017 11:36:01 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-100.ams2.redhat.com [10.36.116.100]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26BYbni002618; Mon, 6 Mar 2017 06:35:57 -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 Subject: [PATCH v3 19/19] KVM: arm64: ITS: Pending table save/restore Date: Mon, 6 Mar 2017 12:34:34 +0100 Message-Id: <1488800074-21991-20-git-send-email-eric.auger@redhat.com> In-Reply-To: <1488800074-21991-1-git-send-email-eric.auger@redhat.com> References: <1488800074-21991-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 06 Mar 2017 11:36:01 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170306_063641_165754_F23D3230 X-CRM114-Status: GOOD ( 18.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: andre.przywara@arm.com, pbonzini@redhat.com, dgilbert@redhat.com, quintela@redhat.com, Prasun.Kapoor@cavium.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 27ebabd..24824be 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,