From patchwork Wed Nov 29 17:22:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Levin, Alexander \(Sasha Levin\)" X-Patchwork-Id: 120035 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3334543qgn; Wed, 29 Nov 2017 09:31:05 -0800 (PST) X-Google-Smtp-Source: AGs4zMbohs12Y9WSwkEAcA2SKlUWhHTARcQmUoelhZT7tGPeBXeF1jXxokINhfjDNBt3G58Mso23 X-Received: by 10.98.10.77 with SMTP id s74mr3775266pfi.104.1511976665480; Wed, 29 Nov 2017 09:31:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511976665; cv=none; d=google.com; s=arc-20160816; b=uIJb0Oi0tfxRWMVfu9HXO+GUrq3hrHNDGrXgiGG4fX6QOcxlFMuP7CKrB/PWokrx81 x5DV3q9nbSsN00T9+WX8NXKQcLx+e88OISTXjkbsxH2EjmjP8Jdh+/Rns/wKQXWU6QKf hEbw5j0uUsLJaaLIlDA5ltSgL2PmK+bCpBEgILL84F3bK+verV5BKAarnk/D7IAUd8Li /WXyS6gz12orRuAd01W6k4hTsgXBSLGdoidOlaouc2NJLoIkL/K0aQp85cgfixuD97im kZQqWnXit7XExzAVNU3t6qvxGPCvOGI1tXUQ51W4D5T71NfwTZyZL9NmXJNq+uQCSbe+ JwRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:to:cc:from:dkim-signature :dkim-signature:dkim-signature:arc-authentication-results; bh=aR0nacGFbUmYMRh3dC32hFg37QwIgruQT71toqYkKfU=; b=GF4oMgcDlMzITPAeZxMPzv1fKJIPQqWJK8O9aAqle3sdi7ISAS8Pp3XDX8dxsAVYce LjWVtdFB7IEbQEs3dq1aK/5qufF9a85kTpgeJ+HAo1V/AUplDK3foVAjsE6N0dQQI3Xs IDZ1vuuluw3zjC1E7ck0tP6JRfhDq5b8bpAzUofmoNfWLtO0tR4AELH1NG43+L0XJeHt MDh2y18Cfs+XciYNVl9H+dvuV4gySwllaIKlGxup7kdOxjONaBzcBbksoejga6OT6A1e qoYtjoXr/SOMbIyd4syaRf7xQowieiCqGnTD00ezzXjoOIUIpU4zGbRENxlEsCvWqGL0 diVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@verizon.com header.s=corp header.b=F9Oe8PXU; dkim=fail header.i=@verizon.com header.s=corp header.b=lCKMr6uW; dkim=fail header.i=@verizon.com header.s=corp header.b=kgvUGvbk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=verizon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o11si82318pgp.238.2017.11.29.09.31.05; Wed, 29 Nov 2017 09:31:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@verizon.com header.s=corp header.b=F9Oe8PXU; dkim=fail header.i=@verizon.com header.s=corp header.b=lCKMr6uW; dkim=fail header.i=@verizon.com header.s=corp header.b=kgvUGvbk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=verizon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934353AbdK2RXr (ORCPT + 28 others); Wed, 29 Nov 2017 12:23:47 -0500 Received: from fldsmtpe03.verizon.com ([140.108.26.142]:30144 "EHLO fldsmtpe03.verizon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934332AbdK2RXo (ORCPT ); Wed, 29 Nov 2017 12:23:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1511976224; x=1543512224; h=from:cc:to:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=dsiElFQMnVcPbnFE8pOvgtFmZlGh7Ai/cOQwaMCCvPY=; b=F9Oe8PXU5tzJAKKMjTcmeWFgCl48IvxXuVWFBGRm2Nv0+FhiQ/lhxyuS kHldvDEhrcI6SH4xYiKD39JQGdbzH/cK71QjMM1VZpGKcawObhumniiCP bpO7yX6dawbB0L18DIdArxj97ELGxZOY5KI6UsCuvJm60sDkkT3pM0jeH g=; Received: from unknown (HELO fldsmtpi02.verizon.com) ([166.68.71.144]) by fldsmtpe03.verizon.com with ESMTP; 29 Nov 2017 17:23:42 +0000 Received: from rogue-10-255-192-101.rogue.vzwcorp.com (HELO atlantis.verizonwireless.com) ([10.255.192.101]) by fldsmtpi02.verizon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 29 Nov 2017 17:23:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1511976222; x=1543512222; h=from:cc:to:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=dsiElFQMnVcPbnFE8pOvgtFmZlGh7Ai/cOQwaMCCvPY=; b=lCKMr6uWpiqD2JAUnUew8fHPdI/dDKzOdmE+Jbkpr/5eflfD5YqYferP WfhgLUU+umiE78Rryi3QHpLd82sVesVmsguc4ZJypDckhLrrg4e/qllSJ NXHPzNOjnN+sg4GU8LtHCDeeRyVi2/1pkipmJ0Yaxl3y+wqfK8CK1qLbe Q=; Received: from endeavour.tdc.vzwcorp.com (HELO eris.verizonwireless.com) ([10.254.88.163]) by atlantis.verizonwireless.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 29 Nov 2017 12:23:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1511976222; x=1543512222; h=to:subject:date:message-id:references:in-reply-to: content-transfer-encoding:mime-version:from:cc; bh=dsiElFQMnVcPbnFE8pOvgtFmZlGh7Ai/cOQwaMCCvPY=; b=kgvUGvbkjRSQERxQ9hi0g5++IHXoZKCMfFCprDxgajjm4ZlMwJV6P1Yo euydrBOLymJAfFMT4KWcu6K9egBnuvX22e5GRBoQ5NI9nSx19L9ygma24 KHBDei77VVjT4/EU2nZjNCS55N7Mex5oscSWiDpHCJKAwa322d2v/cr5O Q=; From: alexander.levin@verizon.com Cc: Mark Rutland , Dave Martin , Suzuki K Poulose , Marc Zyngier , alexander.levin@verizon.com X-Host: endeavour.tdc.vzwcorp.com Received: from ohtwi1exh003.uswin.ad.vzwcorp.com ([10.144.218.45]) by eris.verizonwireless.com with ESMTP/TLS/AES128-SHA256; 29 Nov 2017 17:23:42 +0000 Received: from tbwexch18apd.uswin.ad.vzwcorp.com (153.114.162.42) by OHTWI1EXH003.uswin.ad.vzwcorp.com (10.144.218.45) with Microsoft SMTP Server (TLS) id 14.3.248.2; Wed, 29 Nov 2017 12:23:42 -0500 Received: from OMZP1LUMXCA14.uswin.ad.vzwcorp.com (144.8.22.189) by tbwexch18apd.uswin.ad.vzwcorp.com (153.114.162.42) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Wed, 29 Nov 2017 12:23:41 -0500 Received: from OMZP1LUMXCA17.uswin.ad.vzwcorp.com (144.8.22.195) by OMZP1LUMXCA14.uswin.ad.vzwcorp.com (144.8.22.189) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Wed, 29 Nov 2017 11:23:40 -0600 Received: from OMZP1LUMXCA17.uswin.ad.vzwcorp.com ([144.8.22.195]) by OMZP1LUMXCA17.uswin.ad.vzwcorp.com ([144.8.22.195]) with mapi id 15.00.1263.000; Wed, 29 Nov 2017 11:23:40 -0600 To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Subject: [PATCH AUTOSEL for 3.18 09/16] arm: KVM: Survive unknown traps from guests Thread-Topic: [PATCH AUTOSEL for 3.18 09/16] arm: KVM: Survive unknown traps from guests Thread-Index: AQHTaTad1jifppjf00WUSV9OzVJU1A== Date: Wed, 29 Nov 2017 17:22:21 +0000 Message-ID: <20171129172213.29007-9-alexander.levin@verizon.com> References: <20171129172213.29007-1-alexander.levin@verizon.com> In-Reply-To: <20171129172213.29007-1-alexander.levin@verizon.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.144.60.250] MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Rutland [ Upstream commit f050fe7a9164945dd1c28be05bf00e8cfb082ccf ] Currently we BUG() if we see a HSR.EC value we don't recognise. As configurable disables/enables are added to the architecture (controlled by RES1/RES0 bits respectively), with associated synchronous exceptions, it may be possible for a guest to trigger exceptions with classes that we don't recognise. While we can't service these exceptions in a manner useful to the guest, we can avoid bringing down the host. Per ARM DDI 0406C.c, all currently unallocated HSR EC encodings are reserved, and per ARM DDI 0487A.k_iss10775, page G6-4395, EC values within the range 0x00 - 0x2c are reserved for future use with synchronous exceptions, and EC values within the range 0x2d - 0x3f may be used for either synchronous or asynchronous exceptions. The patch makes KVM handle any unknown EC by injecting an UNDEFINED exception into the guest, with a corresponding (ratelimited) warning in the host dmesg. We could later improve on this with with a new (opt-in) exit to the host userspace. Cc: Dave Martin Cc: Suzuki K Poulose Reviewed-by: Christoffer Dall Signed-off-by: Mark Rutland Signed-off-by: Marc Zyngier Signed-off-by: Sasha Levin --- arch/arm/include/asm/kvm_arm.h | 1 + arch/arm/kvm/handle_exit.c | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) -- 2.11.0 diff --git a/arch/arm/include/asm/kvm_arm.h b/arch/arm/include/asm/kvm_arm.h index 816db0bf2dd8..151464c6bfdb 100644 --- a/arch/arm/include/asm/kvm_arm.h +++ b/arch/arm/include/asm/kvm_arm.h @@ -208,6 +208,7 @@ #define HSR_EC_IABT_HYP (0x21) #define HSR_EC_DABT (0x24) #define HSR_EC_DABT_HYP (0x25) +#define HSR_EC_MAX (0x3f) #define HSR_WFI_IS_WFE (1U << 0) diff --git a/arch/arm/kvm/handle_exit.c b/arch/arm/kvm/handle_exit.c index a96a8043277c..b6ac50b85d72 100644 --- a/arch/arm/kvm/handle_exit.c +++ b/arch/arm/kvm/handle_exit.c @@ -98,7 +98,19 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu, struct kvm_run *run) return 1; } +static int kvm_handle_unknown_ec(struct kvm_vcpu *vcpu, struct kvm_run *run) +{ + u32 hsr = kvm_vcpu_get_hsr(vcpu); + + kvm_pr_unimpl("Unknown exception class: hsr: %#08x\n", + hsr); + + kvm_inject_undefined(vcpu); + return 1; +} + static exit_handle_fn arm_exit_handlers[] = { + [0 ... HSR_EC_MAX] = kvm_handle_unknown_ec, [HSR_EC_WFI] = kvm_handle_wfx, [HSR_EC_CP15_32] = kvm_handle_cp15_32, [HSR_EC_CP15_64] = kvm_handle_cp15_64, @@ -120,13 +132,6 @@ static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu) { u8 hsr_ec = kvm_vcpu_trap_get_class(vcpu); - if (hsr_ec >= ARRAY_SIZE(arm_exit_handlers) || - !arm_exit_handlers[hsr_ec]) { - kvm_err("Unknown exception class: hsr: %#08x\n", - (unsigned int)kvm_vcpu_get_hsr(vcpu)); - BUG(); - } - return arm_exit_handlers[hsr_ec]; }