From patchwork Tue May 9 10:44:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9717597 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 7FFD960237 for ; Tue, 9 May 2017 10:50:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F9F32845E for ; Tue, 9 May 2017 10:50:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58D1B2844B; Tue, 9 May 2017 10:50: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 0E93B28400 for ; Tue, 9 May 2017 10:50:26 +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=NzYkOkfeJYlc2Cz3SefZAQUrTR5AUK38GnBTL9qvOYQ=; b=qJNabZiFxZNlEzBbzynJ3AT78i Zj316kBrFnu63S0mzix412PXf2RZxJAwravJwiF+pcWRf3sU/l2nxBGNVF0F331luatTx4i0AuqDJ nxziWG2wa97b8Xl6+PEAFfF/IJDYKjP07iqM4jVsXAeWKiKkPbF2CQencJx8kmKLLb+a+d1j8ydro zJe/EXCi3GY8c9sib1FCX6yyu3Il0NRbT8g4uAx0lfFaM/+UIqoVSHnOeJIoJMIePJ6JsX/21+2qx 6njx6UGOTN5KWqFb3lUdbq2EJMSmkT4SobRu8Af3ASM4CXtX/OZQfkxsBrYAh0yEh1KhWXMnBzgr2 4El2iUAQ==; 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 1d82io-0001Az-0w; Tue, 09 May 2017 10:50:26 +0000 Received: from mail-qk0-x229.google.com ([2607:f8b0:400d:c09::229]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d82eK-0002r0-DB for linux-arm-kernel@lists.infradead.org; Tue, 09 May 2017 10:46:01 +0000 Received: by mail-qk0-x229.google.com with SMTP id u75so75012979qka.3 for ; Tue, 09 May 2017 03:45:28 -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=Br/qtXWAdWA4MesKznmOjpOZNL6BWyeJ9+V4lxztsH8=; b=GDbTbcOY2rHFrXg1TGPsfyCUASrhO6oDhWZR1ua03LUqX0wlz9dSz2UdyHVFmiC9Dm qd9vL1ZzYEL+A0q8aaSe6IhPGUxb/f8aeozRZL4iP0BRYSvnz5MipBdA6JJcFXEXtodP vw9Pi93RcpApLcZU4h/B32EOMMhxsygrw99gM= 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=Br/qtXWAdWA4MesKznmOjpOZNL6BWyeJ9+V4lxztsH8=; b=Spm7p0+m7TTfvumr9LExj/s7HrD2wFEPIHR30/4LrRw1xI2jU2O/DlywopVExVSuvt 1WdZJ1vbYrjth7fu6z6DdhYiuOrszlMQNiN5WFd3n9mAku/WnUN3HDEvmtyTicfegcyp TUKU03YYmxICMskwsnR7NywooZe9emhxuu/gnyTpi0Zlo1nMEEtTNLiIhGKVErsAQHKv TVirYGkyI2PvNxHlFmK6p1Mhdz18vYVTgVVgde+25/Gclu3dUIvcs4aDSdrnVVIX0FWr nZJEN7a9tG7orE4T6RlppwQBWU88EVOZs2ZM3KsTaJwVsEujPzvtpeJNuhCmdLGa8Ujm 9V7A== X-Gm-Message-State: AN3rC/7g0lO3WW9dbbVgWjFaBZN8lw0WdOPsC8ylEP7wd9mgqJQZnvwZ 0sRFklrcqug8F1l8 X-Received: by 10.80.177.86 with SMTP id l22mr26189537edd.45.1494326727101; Tue, 09 May 2017 03:45:27 -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.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 May 2017 03:45:26 -0700 (PDT) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PULL 15/37] KVM: arm64: vgic-its: Check the device id matches TYPER DEVBITS range Date: Tue, 9 May 2017 12:44:44 +0200 Message-Id: <20170509104506.30929-16-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_034549_055273_B508C491 X-CRM114-Status: GOOD ( 15.99 ) 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 On MAPD we currently check the device id can be stored in the device table. Let's first check it can be encoded within the range defined by TYPER DEVBITS. Also check the collection ID belongs to the 16 bit range as GITS_TYPER CIL field equals to 0. Signed-off-by: Eric Auger Reviewed-by: Christoffer Dall Reviewed-by: Marc Zyngier --- virt/kvm/arm/vgic/vgic-its.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index 7b95b73..bd1362e 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -227,6 +227,7 @@ static struct its_ite *find_ite(struct vgic_its *its, u32 device_id, #define GIC_LPI_OFFSET 8192 #define VITS_TYPER_IDBITS 16 +#define VITS_TYPER_DEVBITS 16 /* * Finds and returns a collection in the ITS collection table. @@ -427,7 +428,7 @@ static unsigned long vgic_mmio_read_its_typer(struct kvm *kvm, * To avoid memory waste in the guest, we keep the number of IDBits and * DevBits low - as least for the time being. */ - reg |= 0x0f << GITS_TYPER_DEVBITS_SHIFT; + reg |= GIC_ENCODE_SZ(VITS_TYPER_DEVBITS, 5) << GITS_TYPER_DEVBITS_SHIFT; reg |= GIC_ENCODE_SZ(VITS_TYPER_IDBITS, 5) << GITS_TYPER_IDBITS_SHIFT; reg |= GIC_ENCODE_SZ(abi->ite_esz, 4) << GITS_TYPER_ITT_ENTRY_SIZE_SHIFT; @@ -672,16 +673,30 @@ static int vgic_its_cmd_handle_movi(struct kvm *kvm, struct vgic_its *its, * Check whether an ID can be stored into the corresponding guest table. * For a direct table this is pretty easy, but gets a bit nasty for * indirect tables. We check whether the resulting guest physical address - * is actually valid (covered by a memslot and guest accessbible). + * is actually valid (covered by a memslot and guest accessible). * For this we have to read the respective first level entry. */ -static bool vgic_its_check_id(struct vgic_its *its, u64 baser, int id) +static bool vgic_its_check_id(struct vgic_its *its, u64 baser, u32 id) { int l1_tbl_size = GITS_BASER_NR_PAGES(baser) * SZ_64K; + u64 indirect_ptr, type = GITS_BASER_TYPE(baser); + int esz = GITS_BASER_ENTRY_SIZE(baser); int index; - u64 indirect_ptr; gfn_t gfn; - int esz = GITS_BASER_ENTRY_SIZE(baser); + + switch (type) { + case GITS_BASER_TYPE_DEVICE: + if (id >= BIT_ULL(VITS_TYPER_DEVBITS)) + return false; + break; + case GITS_BASER_TYPE_COLLECTION: + /* as GITS_TYPER.CIL == 0, ITS supports 16-bit collection ID */ + if (id >= BIT_ULL(16)) + return false; + break; + default: + return false; + } if (!(baser & GITS_BASER_INDIRECT)) { phys_addr_t addr;