From patchwork Fri Apr 14 10:15:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9681125 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 4C08F60326 for ; Fri, 14 Apr 2017 10:45:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D36828664 for ; Fri, 14 Apr 2017 10:45:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 314C628676; Fri, 14 Apr 2017 10:45:30 +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 DA78228664 for ; Fri, 14 Apr 2017 10:45:29 +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=6TT4gp2OZC9tyPZuiU6lG7AQgnlxGY6QRXjkeWw7pdo=; b=LOHj85/EakSFHPprkOhKdBEW4q SGaXcfmY9kbiEVapLTNrQG+zytU9f+Z2BxF/FEfZ31cM83THsoX8cYl6VIkG8GDr9tCE20E2EtBF2 0NEq8IQGdIbR/YPm+/XWJcWxhOm3dPuBi5LcLwWJF+rprWysAiH75XJR/C78uiS511Al3R5NssAgT zpQoSFX8fPmkuim1oEr+bhaPAIw2xo6AUONsWxidoEeLh1YuuhSAi9QEuKhjecQc1sUCVKTH7yWA5 NQIw8t+89m7E0ksHMmJGsV9L903hwWdOXtOA+c93y3hmoVCWrSul/z6BCoMgTi5gDrlThVpYrRsbi Hu6Dv3VQ==; 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 1cyyjI-0000IN-1J; Fri, 14 Apr 2017 10:45:28 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cyyiJ-000634-3L for linux-arm-kernel@bombadil.infradead.org; Fri, 14 Apr 2017 10:44:27 +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=O+K+mClWz8ULsaWF+7YMfetE1N68ZvBYrRD1YGS2pNw=; b=PNZC4rN61SXsIbdOT1JXuZ5D9 HEogiuGRAVtYiBSVrKGpMHjBDyFvze1yjPJXycjJ7Uo4HGh0maUuygk7+uJWAc3hmV/vfI7p1MBSp 1jufTtaeF/6Id1fwxL9yhvREi2F401NykVgiIbN7Q5SJ0gd/HOBZIEjIrPHNL1WZKOvrpPwZgDEql enjh8QRixiULp4qcQvcA1mc3dv5bAYUW524UUesZGkRXQJFA1Hvrm+Plwkg2kJchj6FsP6n3F/ReV AxZQoDV3lckdU5EWAjYJdvxrW4LaRL2QFFQXU/krONSYyF5eZJtVnFtSpxuOms5uyAXLcE0jJkBWv PoVQyurxw==; Received: from mx1.redhat.com ([209.132.183.28]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cyyIL-0005YB-Ng for linux-arm-kernel@lists.infradead.org; Fri, 14 Apr 2017 10:17:38 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 757CC80F7D; Fri, 14 Apr 2017 10:16:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 757CC80F7D Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eric.auger@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 757CC80F7D Received: from localhost.localdomain.com (ovpn-117-27.ams2.redhat.com [10.36.117.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BE6618214; Fri, 14 Apr 2017 10:16:46 +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 v5 10/22] KVM: arm64: vgic-its: Implement vgic_mmio_uaccess_write_its_iidr Date: Fri, 14 Apr 2017 12:15:22 +0200 Message-Id: <1492164934-988-11-git-send-email-eric.auger@redhat.com> In-Reply-To: <1492164934-988-1-git-send-email-eric.auger@redhat.com> References: <1492164934-988-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 14 Apr 2017 10:16:51 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170414_061738_021710_6BEA95BC X-CRM114-Status: GOOD ( 15.50 ) 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 The GITS_IIDR revision field is used to encode the migration ABI revision. So we need to restore it to check the table layout is readable by the destination. By writing the IIDR, userspace thus force the ABI revision to be used and this msut be less or equal than the max revision KVM supports. Signed-off-by: Eric Auger Tested-by: Prakash, Brahmajyosyula --- v4 -> v5 - rename user_revision into abi_rev and REV into MAX_ABI_REV - IIDR reports abi_rev set by userspace if any. - If value set by userspace exceeds the max supported revision, an error is reported. - add some defines v4: creation --- include/linux/irqchip/arm-gic-v3.h | 4 ++++ virt/kvm/arm/vgic/vgic-its.c | 23 ++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h index 9648bad..54c20bd 100644 --- a/include/linux/irqchip/arm-gic-v3.h +++ b/include/linux/irqchip/arm-gic-v3.h @@ -241,6 +241,10 @@ #define GITS_TYPER_PTA (1UL << 19) #define GITS_TYPER_HWCOLLCNT_SHIFT 24 +#define GITS_IIDR_REV_SHIFT 12 +#define GITS_IIDR_REV(r) (((r) >> GITS_IIDR_REV_SHIFT) & 0xf) +#define GITS_IIDR_PRODUCTID_SHIFT 24 + #define GITS_CBASER_VALID (1ULL << 63) #define GITS_CBASER_SHAREABILITY_SHIFT (10) #define GITS_CBASER_INNER_CACHEABILITY_SHIFT (59) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index 69ecfe4..1b5797e 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -401,7 +401,23 @@ static unsigned long vgic_mmio_read_its_iidr(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len) { - return (PRODUCT_ID_KVM << 24) | (IMPLEMENTER_ARM << 0); + return (PRODUCT_ID_KVM << GITS_IIDR_PRODUCTID_SHIFT) | + (its->abi_rev << GITS_IIDR_REV_SHIFT) | IMPLEMENTER_ARM; +} + +static int vgic_mmio_uaccess_write_its_iidr(struct kvm *kvm, + struct vgic_its *its, + gpa_t addr, unsigned int len, + unsigned long val) +{ + u64 tmp = 0; + + tmp = update_64bit_reg(tmp, addr & 3, len, val); + tmp = GITS_IIDR_REV(tmp); + + if (tmp > MAX_ABI_REV) + return -EINVAL; + return vgic_its_set_abi(its, tmp); } static unsigned long vgic_mmio_read_its_idregs(struct kvm *kvm, @@ -1382,8 +1398,9 @@ static struct vgic_register_region its_registers[] = { REGISTER_ITS_DESC(GITS_CTLR, vgic_mmio_read_its_ctlr, vgic_mmio_write_its_ctlr, 4, VGIC_ACCESS_32bit), - REGISTER_ITS_DESC(GITS_IIDR, - vgic_mmio_read_its_iidr, its_mmio_write_wi, 4, + REGISTER_ITS_DESC_UACCESS(GITS_IIDR, + vgic_mmio_read_its_iidr, its_mmio_write_wi, + vgic_mmio_uaccess_write_its_iidr, 4, VGIC_ACCESS_32bit), REGISTER_ITS_DESC(GITS_TYPER, vgic_mmio_read_its_typer, its_mmio_write_wi, 8,