From patchwork Mon Dec 5 09:32:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9460699 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 D1D5160459 for ; Mon, 5 Dec 2016 09:33:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEB742094D for ; Mon, 5 Dec 2016 09:33:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B33B3252D5; Mon, 5 Dec 2016 09:33:50 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 578082094D for ; Mon, 5 Dec 2016 09:33:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cDpdS-0004Pe-UG; Mon, 05 Dec 2016 09:32:34 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cDpdP-0004Hy-Eu for linux-arm-kernel@lists.infradead.org; Mon, 05 Dec 2016 09:32:32 +0000 Received: by mail-wm0-x234.google.com with SMTP id a197so87493101wmd.0 for ; Mon, 05 Dec 2016 01:32:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=FT695CqBUnm6dzqDbWJ7L021XmRYHuv6URkVLA14kcw=; b=PQWEi3SscMpMpP+zBUwAlKG/sRasoIddrc6HPKxwdlNwRhS0HIwELV8Bp/nktQRgA0 lHbGj+5TU1gC5t2nxS6PMZGVlTKQr3hfV96XBgsQ1t+KCX+xVgw7HCLJ4wDXP0zk8z/J S+HgRy4FyihNRWIQyEICBGqMUWCPopAzwMjIY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=FT695CqBUnm6dzqDbWJ7L021XmRYHuv6URkVLA14kcw=; b=DqCYp5m3TCfFYBwvciN/GwGRv5CrxJ10TqRqAKbbrTy3FHZ0s8xwVTqymQoqWWZ4Du cYdnHp3TN/a+VbLV4Dm+bXPK/uZKTdV79geMRR2kHIGmsdUIMTmuQSurgS8fAmn4mBU5 E2dxEmMcW1D0b4pl99c/wqh/TdHxnFWqKP5nn4UEF7KIOe0xyaYlMp15YF8qtCQQD/We wqPb+F0CGHwPS+c1fy1y9xY5F3xjvi4HGopORbeBCgug6qixUI4WqD0I6a9X8XY3n+Rq DR40TvDoZuFb6lhwRVnSenND2zJ5i3jO7vDIC+MX+pBSraVmAdYEJzQH/tPl1zrJ32XE CQzg== X-Gm-Message-State: AKaTC0398A/LD+bdAnXG484Fn0y4vhDNoAJz6yp60lUqjeRC/F+7owBXL938hnmAtFWdsbVh X-Received: by 10.46.76.18 with SMTP id z18mr26650641lja.38.1480930329211; Mon, 05 Dec 2016 01:32:09 -0800 (PST) Received: from localhost.localdomain (x1-6-50-6a-03-de-ec-c2.cpe.webspeed.dk. [2.108.209.202]) by smtp.gmail.com with ESMTPSA id c2sm2774012ljb.8.2016.12.05.01.32.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Dec 2016 01:32:08 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Subject: [PATCH] arm/arm64: KVM: Check for properly initialized timer on init Date: Mon, 5 Dec 2016 10:32:11 +0100 Message-Id: <20161205093211.11870-1-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.9.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161205_013231_707393_011A9C48 X-CRM114-Status: GOOD ( 10.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , Shih-Wei Li , Christoffer Dall 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 When the arch timer code fails to initialize (for example because the memory mapped timer doesn't work, which is currently seen with the AEM model), then KVM just continues happily with a final result that KVM eventually does a NULL pointer dereference of the uninitialized cycle counter. Check directly for this in the init path and give the user a reasonable error in this case. Cc: Shih-Wei Li Signed-off-by: Christoffer Dall --- virt/kvm/arm/arch_timer.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index 27a1f63..5c12f53 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -425,6 +425,11 @@ int kvm_timer_hyp_init(void) info = arch_timer_get_kvm_info(); timecounter = &info->timecounter; + if (!timecounter->cc) { + kvm_err("arch_timer: uninitialized timecounter\n"); + return -ENODEV; + } + if (info->virtual_irq <= 0) { kvm_err("kvm_arch_timer: invalid virtual timer IRQ: %d\n", info->virtual_irq);