From patchwork Tue May 9 10:44:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9717583 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 D239160237 for ; Tue, 9 May 2017 10:48:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C479720683 for ; Tue, 9 May 2017 10:48:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B92A1283F2; Tue, 9 May 2017 10:48:06 +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 3C22920683 for ; Tue, 9 May 2017 10:48:06 +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=xaT4YabeNDZVVwxKN4LDrrpV1jg1uCMXWa8Ujen+DLk=; b=AjMsgBmtGdb7f+g3SBfPxv0wVm KkaCGUNkzJxYN2djs/XDpHYmsEp6HHFmzL35RrBWDH/MgIU9AejlcovxQiqyT5a9HwbjgWYr+TwIw YJ6OVw2ba7ahkhUETq+7FTh8Ej4VXEp5RKPST01fNuYd5Y6U0SJSPvnNkOngK5uJwN6CzlIeesEAj t9wbgBLGv7Ew7NoYqYTjwDtvirsU5wwgW42Q0hRTjeg3i5tiM/JDC07CtZa7y/CyJPutcUxrUudBX 8OYyPFZMRIvbPigaGCpxoj08zLJkgGBBJCSfy8KjaIsBD8PxplUjujQD9MAH7LQHLJwjSJwmf9U6d nQDqNP1w==; 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 1d82gX-0005zJ-4x; Tue, 09 May 2017 10:48:05 +0000 Received: from mail-qk0-x233.google.com ([2607:f8b0:400d:c09::233]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d82eD-0002qk-9z for linux-arm-kernel@lists.infradead.org; Tue, 09 May 2017 10:45:47 +0000 Received: by mail-qk0-x233.google.com with SMTP id y201so42662076qka.0 for ; Tue, 09 May 2017 03:45:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6EjQuHtLrMGfjC4PW70A1Ned1z4wsTSsDaRF2qoc4WM=; b=EhFhSgCsY0NJOUF4pHb6itIWPNiJgWKVfst7KSBR8V8urVNRuJh33OFh3xHxpjKBCu yaAWkTzXqSTTdKMwHmEBaowC//glJerjDuo0we2mvFEqN3ml5Zx+RdLbK1Rbh71jIU2l p2VVv1tncB8yHRxOWS/zN6GPUKkJg7EuHs8Hc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6EjQuHtLrMGfjC4PW70A1Ned1z4wsTSsDaRF2qoc4WM=; b=Frqq4EoRUo/GwfFq9haXNAbgTC5KiBFHcfdusJcDKK63YT9Y6QHw4dd6ANWEeGNoJY fShQnlDcYwCnS5AT1TVyzixp0G9aEycm1y72W14vo4YAsaAAtEeclp8tLIXXl+Dca/nw z2S6ChuhJRGxKe17COJ9z94RKGDDmtDlk/An9qssG09cbv7ySr8aRvsiEb2iC33VbGq9 +o4ZCw6+2q5+tjI8BQVF8mb0AWapPieOkdeuINYUvqomigyk5LXdKkDOmo5iWOgzTMTk 8JylfcQ+AR81XdgWdwYGL5Somww9ZNVKrjBdc/SNJqQipwutOjruUYLoDKK/NU/T+VU6 vj3w== X-Gm-Message-State: AN3rC/7mdukliiwZJUUm1/BwBMwC2Jk6lUexKCAaoP+1FOjKAugOZe9B rOuG9KZnkzpKtOon X-Received: by 10.80.172.122 with SMTP id w55mr25122665edc.120.1494326724309; Tue, 09 May 2017 03:45:24 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id o30sm2331510edc.42.2017.05.09.03.45.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 May 2017 03:45:23 -0700 (PDT) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PULL 12/37] KVM: arm64: vgic-its: Implement vgic_mmio_uaccess_write_its_iidr Date: Tue, 9 May 2017 12:44:41 +0200 Message-Id: <20170509104506.30929-13-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170509104506.30929-1-cdall@linaro.org> References: <20170509104506.30929-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170509_034541_637674_737F74EB X-CRM114-Status: GOOD ( 12.15 ) 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: Marc Zyngier , Eric Auger , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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 From: Eric Auger 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 forces the ABI revision to be used and this must be less than or equal to the max revision KVM supports. Signed-off-by: Eric Auger Reviewed-by: Christoffer Dall --- include/linux/irqchip/arm-gic-v3.h | 5 +++++ virt/kvm/arm/vgic/vgic-its.c | 23 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h index 81ebe43..2eaea30 100644 --- a/include/linux/irqchip/arm-gic-v3.h +++ b/include/linux/irqchip/arm-gic-v3.h @@ -242,6 +242,11 @@ #define GITS_TYPER_PTA (1UL << 19) #define GITS_TYPER_HWCOLLCNT_SHIFT 24 +#define GITS_IIDR_REV_SHIFT 12 +#define GITS_IIDR_REV_MASK (0xf << GITS_IIDR_REV_SHIFT) +#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 4f6ea46..9338efb 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -434,7 +434,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); + u32 val; + + val = (its->abi_rev << GITS_IIDR_REV_SHIFT) & GITS_IIDR_REV_MASK; + val |= (PRODUCT_ID_KVM << GITS_IIDR_PRODUCTID_SHIFT) | IMPLEMENTER_ARM; + return val; +} + +static int vgic_mmio_uaccess_write_its_iidr(struct kvm *kvm, + struct vgic_its *its, + gpa_t addr, unsigned int len, + unsigned long val) +{ + u32 rev = GITS_IIDR_REV(val); + + if (rev >= NR_ITS_ABIS) + return -EINVAL; + return vgic_its_set_abi(its, rev); } static unsigned long vgic_mmio_read_its_idregs(struct kvm *kvm, @@ -1415,8 +1431,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,