From patchwork Wed Nov 29 17:21:52 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: 120030 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3326502qgn; Wed, 29 Nov 2017 09:23:24 -0800 (PST) X-Google-Smtp-Source: AGs4zMbVBsq0Wr35Y8vEHMmob7nGhgSillfP2K+e420J/8wkAUcl7eetb46tCx107j+Oo+iYCd00 X-Received: by 10.98.46.7 with SMTP id u7mr3732854pfu.37.1511976204492; Wed, 29 Nov 2017 09:23:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511976204; cv=none; d=google.com; s=arc-20160816; b=jZJ1I8mbGwNxs7DWUo9xTfCB8rg1N7ALdp3A9taUq5JAvxv9r8ico+0CKfgUj816Bm tDgnlZPbXOr3MaNpWBhy4NJiGAAxiAWXSSZ8VaanFibxwgJTdu5+6o+Jh0fWNKoFK61n wMYBWZpi2qZ0arK1FsXukyuIacBGoSSDYhVH7pIMtXiNVhgZtKfxGUwgbTPAl5nopzEM VryDU5jM5niQh0pdzvRyWwl07bvFhCvYhAFrsuBWRyntsHa8WUfad1hRCcLnw88tmTLi a+G+IzVI4tdy364IhHIG4u8N/Vxthr8/6PDLVlJs2XXrT+uMfnt85RfdrwPqbqW7Y92u 5K1g== 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=SYSRLhA71OtZNc4dsMxe8TFz5C45lj80qKPSioQGa0g=; b=WpkAvd9RmY5l19X7XzqyIMuhwOx3o0dFskLkY1VZICVDDmqrpCsP58AQ0vKb5y3/Qi DtlJGm54/jRQ/OvQgCAggbiE/4beg5Z+sF4tYM+Ay+gR3I4hxigUjJyBhF1zEbZ4kQi1 ixLTdVkhv+o9VoQpNSJDyGUdDZPmEeMVg3ojw/wBen0AkA+TjiaskicpDz1sgZJPYW2t IHz0FPY+rSq9x84PY8rdjS56m034gtGVfyE5+aMTIOUTeZTHPiseEkxzoWp5LL+muIoq wpji+iBoMYfgz/PIFL4wsYnpT2AhgPsKEBdffu2LlafApaiEkluYxsDA142gym5Oio44 D96g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@verizon.com header.s=corp header.b=RMZi+qVh; dkim=fail header.i=@verizon.com header.s=corp header.b=W3jy6Cuq; dkim=fail header.i=@verizon.com header.s=corp header.b=uP2Aath+; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 z11si1571318pgc.454.2017.11.29.09.23.24; Wed, 29 Nov 2017 09:23:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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=RMZi+qVh; dkim=fail header.i=@verizon.com header.s=corp header.b=W3jy6Cuq; dkim=fail header.i=@verizon.com header.s=corp header.b=uP2Aath+; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 S934250AbdK2RXV (ORCPT + 9 others); Wed, 29 Nov 2017 12:23:21 -0500 Received: from omzsmtpe03.verizonbusiness.com ([199.249.25.208]:27081 "EHLO omzsmtpe03.verizonbusiness.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934220AbdK2RXR (ORCPT ); Wed, 29 Nov 2017 12:23:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1511976196; x=1543512196; h=from:cc:to:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=tP1TJyYzKAbvu1oOHRrfuNigC5mkKC3Xt1xv1bzZ7LQ=; b=RMZi+qVh7Ri2MnM0bHK7x6xbsQoFlAk8i9Nu5lgXni5PmsqKbts9pjPP IN3+PGHGsvrpne57asdSPeUCLLEVRLAPI/ZgYQEKcv2TcNKWwK94ayzaO IB6TUV9Kx+v5x2aTA6KwDYlPrWy69e9zMJcrXOm89UYflt8TXb/cTUvPu U=; Received: from unknown (HELO fldsmtpi02.verizon.com) ([166.68.71.144]) by omzsmtpe03.verizonbusiness.com with ESMTP; 29 Nov 2017 17:23:13 +0000 Received: from rogue-10-255-192-101.rogue.vzwcorp.com (HELO apollo.verizonwireless.com) ([10.255.192.101]) by fldsmtpi02.verizon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 29 Nov 2017 17:22:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1511976178; x=1543512178; h=from:cc:to:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=tP1TJyYzKAbvu1oOHRrfuNigC5mkKC3Xt1xv1bzZ7LQ=; b=W3jy6CuqgvjETUtAVXOcz7TzesUs00fSsyQDeYQNCeuTAt4wPpitOOsE Qg+yFU3uUfKdd2myPAlZQUJizHuDbxIiCRSHfHo3m4XfGAnL13EgnS4q2 6K5PnTbmzbIackSm4SBH51fVEEPmFTUkPlBOum+TIABAJO3HWY2QXhlP8 w=; Received: from surveyor.tdc.vzwcorp.com (HELO eris.verizonwireless.com) ([10.254.88.83]) by apollo.verizonwireless.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 29 Nov 2017 12:22:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1511976177; x=1543512177; h=to:subject:date:message-id:references:in-reply-to: content-transfer-encoding:mime-version:from:cc; bh=tP1TJyYzKAbvu1oOHRrfuNigC5mkKC3Xt1xv1bzZ7LQ=; b=uP2Aath+OK4NnEPL/vop8OnVAZHsVEGb/G+uc4atUsw+MAYDSNDbo6Lo fa0ppz1YY4ubBfAMzyC5VrPLXPuGEy0nWUJQYU5vRUkfDsXhPUwBl8I28 4hejM6UyX+QyYAzhdZSLS+PQAt6CkV64+f6lTW9yjfzPDVnn2oGeaPsMt 8=; From: alexander.levin@verizon.com Cc: Mark Rutland , Dave Martin , Suzuki K Poulose , Marc Zyngier , alexander.levin@verizon.com X-Host: surveyor.tdc.vzwcorp.com Received: from ohtwi1exh002.uswin.ad.vzwcorp.com ([10.144.218.44]) by eris.verizonwireless.com with ESMTP/TLS/AES128-SHA256; 29 Nov 2017 17:22:57 +0000 Received: from OHTWI1EXO912.uswin.ad.vzwcorp.com (10.144.218.211) by OHTWI1EXH002.uswin.ad.vzwcorp.com (10.144.218.44) with Microsoft SMTP Server (TLS) id 14.3.248.2; Wed, 29 Nov 2017 12:22:57 -0500 Received: from OMZP1LUMXCA15.uswin.ad.vzwcorp.com (144.8.22.190) by OHTWI1EXO912.uswin.ad.vzwcorp.com (10.144.218.211) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Wed, 29 Nov 2017 12:22:57 -0500 Received: from OMZP1LUMXCA17.uswin.ad.vzwcorp.com (144.8.22.195) by OMZP1LUMXCA15.uswin.ad.vzwcorp.com (144.8.22.190) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Wed, 29 Nov 2017 11:22:56 -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:22:56 -0600 To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Subject: [PATCH AUTOSEL for 4.4 18/32] arm: KVM: Survive unknown traps from guests Thread-Topic: [PATCH AUTOSEL for 4.4 18/32] arm: KVM: Survive unknown traps from guests Thread-Index: AQHTaTaMLuwbleLyqE6OsYVL4//2aQ== Date: Wed, 29 Nov 2017 17:21:52 +0000 Message-ID: <20171129172141.28925-18-alexander.levin@verizon.com> References: <20171129172141.28925-1-alexander.levin@verizon.com> In-Reply-To: <20171129172141.28925-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: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 dc641ddf0784..dd1715268543 100644 --- a/arch/arm/include/asm/kvm_arm.h +++ b/arch/arm/include/asm/kvm_arm.h @@ -209,6 +209,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 95f12b2ccdcb..f36b5b1acd1f 100644 --- a/arch/arm/kvm/handle_exit.c +++ b/arch/arm/kvm/handle_exit.c @@ -100,7 +100,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, @@ -122,13 +134,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]; }