From patchwork Mon Mar 27 09:31:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9646311 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 E7EF6602BF for ; Mon, 27 Mar 2017 10:09:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D123F228C9 for ; Mon, 27 Mar 2017 10:09:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C596B2833B; Mon, 27 Mar 2017 10:09:17 +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 6CD3F228C9 for ; Mon, 27 Mar 2017 10:09:17 +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=nsTTlVMyYTzf38fz7/pWXb6LQgKFHk6RfaOXMyuC6fY=; b=K6AeqAjI6q+bse/xG/FztkcHLy /WrPxFYVwzekWgNgH2FDMtuRXrjGlYvqUWJUWoWNFcbMcmaECcTcYv1yOK8qoiPbmkQf9nAw12Qg0 kAJ0yWw01Q7UJh/g/n5JRxKf9aLU/ATepxjyNfRFMRO+HDU4LaUgYtrBp3nIo1C20tLlM2A9RjOao PBX34UIpg8mBZBd5V43i11COI5KMDcCSbCd5LCPFRoWLtqeoBggxYzb0C8pwZ2cEMA0xbmWTS8S/c mQM15P/ooHto8lf6oBdfVORuCdSL1h9SP6WuzqhoWLscKo31nbU/BJUCLtYMto2l4g58sgunkPoqe LPtVgiIw==; 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 1csRaO-00080F-0m; Mon, 27 Mar 2017 10:09:16 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1csRVn-0002f9-P0 for linux-arm-kernel@bombadil.infradead.org; Mon, 27 Mar 2017 10:04:31 +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=4X1eSL7wnm5ngTfw70uz+savAZByF0sS3vzDi8YXKu8=; b=EwaYBnq+2wzBUSmk9IrqwWMRe HMAHpaPZvGR4O3RqXZftz7+h6QizFlDwbP9/Pb2yPEq4OB/kZuEly4K8dbcTVD9UYeCQ3GKTTv0hZ E81JiODtYzLS5lXxvPXRDL6SYQITIZP8wf2Q6UlQ1exMQTYug5hik5jQNGsuY3VF8GqRcoKackS7G 9w+zBG7IvYHnPGhte7gobnHHvC+0LHKyNa+xfeFEQG98dzyRDOfXWy/47R5D2DBWTRMFKBuGDGUVb swrEQy8VNgxhRwhSp3e8uVrm+cANHZaPZbs1YMbCRm1fwylthGzaBdJmTkWORLuFmHixG40etSqwi waTakpQEA==; Received: from mx1.redhat.com ([209.132.183.28]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1csR1l-0006ub-6c for linux-arm-kernel@lists.infradead.org; Mon, 27 Mar 2017 09:33:29 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0D0DB437F7D; Mon, 27 Mar 2017 09:33:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0D0DB437F7D Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eric.auger@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0D0DB437F7D Received: from localhost.localdomain.com (ovpn-117-27.ams2.redhat.com [10.36.117.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FB8517C46; Mon, 27 Mar 2017 09:33:04 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, marc.zyngier@arm.com, christoffer.dall@linaro.org, andre.przywara@arm.com, vijayak@caviumnetworks.com, Vijaya.Kumar@cavium.com, peter.maydell@linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Subject: [PATCH v4 22/22] KVM: arm64: ITS: Pending table save/restore Date: Mon, 27 Mar 2017 11:31:12 +0200 Message-Id: <1490607072-21610-23-git-send-email-eric.auger@redhat.com> In-Reply-To: <1490607072-21610-1-git-send-email-eric.auger@redhat.com> References: <1490607072-21610-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 27 Mar 2017 09:33:10 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170327_053329_388252_470B6885 X-CRM114-Status: GOOD ( 16.88 ) 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: Prasun.Kapoor@cavium.com, drjones@redhat.com, quintela@redhat.com, dgilbert@redhat.com, pbonzini@redhat.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 --- v3 -> v4: - remove the wrong comment about locking - pass kvm struct instead of its handle - add comment about restore method - remove GITR_PENDABASER.PTZ check - continue if target_vcpu == NULL - new locking strategy v1 -> v2: - do not care about the 1st KB which should be zeroed according to the spec. --- virt/kvm/arm/vgic/vgic-its.c | 66 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index a516bbb..e10aa81 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -1804,16 +1804,78 @@ static int lookup_table(struct vgic_its *its, gpa_t base, int size, int esz, */ static int vgic_its_flush_pending_tables(struct kvm *kvm) { - return -ENXIO; + struct vgic_dist *dist = &kvm->arch.vgic; + struct vgic_irq *irq; + int ret; + + 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) + continue; + + 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; } /** * vgic_its_restore_pending_tables - Restore the pending tables from guest * RAM to internal data structs + * + * Does not scan the whole pending tables but just loop on all registered + * LPIS and scan their associated pending bit. This obviously requires + * the ITEs to be restored before. */ static int vgic_its_restore_pending_tables(struct kvm *kvm) { - return -ENXIO; + struct vgic_dist *dist = &kvm->arch.vgic; + struct vgic_irq *irq; + 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) + continue; + + 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,