From patchwork Wed Nov 29 17:21:20 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: 120039 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3355602qgn; Wed, 29 Nov 2017 09:51:10 -0800 (PST) X-Google-Smtp-Source: AGs4zMaMP/gZbS3dMjaH0azvnNf3G8RQOLdWKgTIABaDrV9inH49nVOOO1YhnIE8KxMbm/KneeM5 X-Received: by 10.84.198.67 with SMTP id o61mr3552453pld.261.1511977870427; Wed, 29 Nov 2017 09:51:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511977870; cv=none; d=google.com; s=arc-20160816; b=Y2F0zlKlJ7Bjd+69YNjBIFqO6SEHyqJSOyFbuGN/KeTDHQTGQdg0tLfteZED704Pd3 ifej4xf+jkIYghUomu4wQ2PAnmXKnz4rmqU1+p57//lZxS+s1ItkN4l9v4Z7NNwePDpO Bex1PD3ltuegvJyaGGbCHtAgiG1Ktr9/X15xVmA/Ebu1T8sTQa2AvZn8vEH67TuiHNeH IcWfoc5MsqBobIiUM/KssDYTTYlaraIPghU1CR2y1oSNDaDtXKJMjhC/hOgK4kEteLXA absxHMvUOiD7vWuAwfrqfLT7DVVUsqN9pKOF8RGowG3wKmFxIoxeAl//T9l5muBadzfu rBJg== 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=HPwc+TjdPqQl0S0RjTxxxW04J+A8j9v6hdsISWYcv6g=; b=MR2BL845tczJwQPG6cB0p54x14PQhmIRUC4IbqUlTywVR0wBRuj6xwN6HMfaO2/pbN FsJFuGGtsZCZh+Bfq9Db7cSyTgodesAOD2hwwZ0NGGXQKs8YpATHZozKSkN+SMuDP8V2 RhJgyRC8lBFQvCvBN23vHE/wpiQY2BJ0rgJpqq1VI3H5YkO66CRnTMxqLBDn/sdeAt7R FgqB28xBqbelGV/EPTa/CMslmagoDVr1oaM/MsyCoBECpqhyM+eK/H7YapOA3NqH5yo+ WzJgXWjQ4hs6xOm1VDBmLDDRca/0dZa9QaR8SS/RmEoIbREAUXokRtQp9Ro8CSj8Nhy1 zjHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@verizon.com header.s=corp header.b=WVqJgcMv; dkim=fail header.i=@verizon.com header.s=corp header.b=hDh7BJi1; dkim=fail header.i=@verizon.com header.s=corp header.b=BsKBkmzq; 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 w2si1580058pgc.754.2017.11.29.09.51.10; Wed, 29 Nov 2017 09:51:10 -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=WVqJgcMv; dkim=fail header.i=@verizon.com header.s=corp header.b=hDh7BJi1; dkim=fail header.i=@verizon.com header.s=corp header.b=BsKBkmzq; 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 S934778AbdK2RvI (ORCPT + 28 others); Wed, 29 Nov 2017 12:51:08 -0500 Received: from omzsmtpe02.verizonbusiness.com ([199.249.25.209]:10293 "EHLO omzsmtpe02.verizonbusiness.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933971AbdK2RWT (ORCPT ); Wed, 29 Nov 2017 12:22:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1511976139; x=1543512139; h=from:cc:to:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=x+kKlI912bvlmDmAzhO0NiBbLUIDtg6Tw3U3fm0VKXk=; b=WVqJgcMvzy4dEaod1i2XGe/+tS+Cg3oW8rkxI1aaWz7mZmTXUXbrav5x vVCydG9QE3IM/r43FxNJ0+uNqT6XV4BhnH1/VgO6dF+K1kRcbdknbzmNa AwJWlvco8zNye94NZfoNEeypXwMPNe4gpDRO0tbnhMA+NCF7K6xpMF4yC Y=; Received: from unknown (HELO fldsmtpi02.verizon.com) ([166.68.71.144]) by omzsmtpe02.verizonbusiness.com with ESMTP; 29 Nov 2017 17:22:06 +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:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1511976124; x=1543512124; h=from:cc:to:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=x+kKlI912bvlmDmAzhO0NiBbLUIDtg6Tw3U3fm0VKXk=; b=hDh7BJi1GJTG6BoZs2Uk3I0kH0aK/GUDjPOw5FKJiBG79SVLmJMr6dfz HmEa2u3bNRk2wkxL4Kb12RwKmbPROWQXX0LqcbGlzC8CuLBp/498E1VrA 3IkMwAaYfuVIIdiBJkf78A/y9YuYOb7dnMNVJQnMHG/xPX7MLMeWzQAse E=; Received: from mariner.tdc.vzwcorp.com (HELO eris.verizonwireless.com) ([10.254.88.84]) by apollo.verizonwireless.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 29 Nov 2017 12:22:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1511976123; x=1543512123; h=to:subject:date:message-id:references:in-reply-to: content-transfer-encoding:mime-version:from:cc; bh=x+kKlI912bvlmDmAzhO0NiBbLUIDtg6Tw3U3fm0VKXk=; b=BsKBkmzquh/4hwuT9VUNbEm20cuKocS6SA+57amUD7lv/oyUTb0DD9Hb Wp+Pk9QkTEnDx87BDK+RDK/jp1ryyzIOdXHkxGzA7+xqdTt8WH2sRrCUq 8zlgnHFJqJ0Iy+Ae02yfmQ2SgMWGqCFIl/0wW/UuKEJuPds36KyiFgFAk w=; From: alexander.levin@verizon.com Cc: Mark Rutland , Dave Martin , Suzuki K Poulose , Marc Zyngier , alexander.levin@verizon.com X-Host: mariner.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:22:03 +0000 Received: from tbwexch25apd.uswin.ad.vzwcorp.com (153.114.162.49) 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:22:03 -0500 Received: from OMZP1LUMXCA17.uswin.ad.vzwcorp.com (144.8.22.195) by tbwexch25apd.uswin.ad.vzwcorp.com (153.114.162.49) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Wed, 29 Nov 2017 12:22:02 -0500 Received: from OMZP1LUMXCA17.uswin.ad.vzwcorp.com (144.8.22.195) by OMZP1LUMXCA17.uswin.ad.vzwcorp.com (144.8.22.195) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Wed, 29 Nov 2017 11:22:02 -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:02 -0600 To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Subject: [PATCH AUTOSEL for 4.9 32/52] arm64: KVM: Survive unknown traps from guests Thread-Topic: [PATCH AUTOSEL for 4.9 32/52] arm64: KVM: Survive unknown traps from guests Thread-Index: AQHTaTZ5wtew0EzS3k2bOZLUJW0wzw== Date: Wed, 29 Nov 2017 17:21:20 +0000 Message-ID: <20171129172100.28819-32-alexander.levin@verizon.com> References: <20171129172100.28819-1-alexander.levin@verizon.com> In-Reply-To: <20171129172100.28819-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 ba4dd156eabdca93501d92a980ba27fa5f4bbd27 ] Currently we BUG() if we see an ESR_EL2.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 0487A.k_iss10775, page D7-1937, 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/arm64/kvm/handle_exit.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) -- 2.11.0 diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index a204adf29f0a..85baadab02d3 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -125,7 +125,19 @@ static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu, struct kvm_run *run) return ret; } +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 -- %s\n", + hsr, esr_get_class_string(hsr)); + + kvm_inject_undefined(vcpu); + return 1; +} + static exit_handle_fn arm_exit_handlers[] = { + [0 ... ESR_ELx_EC_MAX] = kvm_handle_unknown_ec, [ESR_ELx_EC_WFx] = kvm_handle_wfx, [ESR_ELx_EC_CP15_32] = kvm_handle_cp15_32, [ESR_ELx_EC_CP15_64] = kvm_handle_cp15_64, @@ -151,13 +163,6 @@ static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu) u32 hsr = kvm_vcpu_get_hsr(vcpu); u8 hsr_ec = ESR_ELx_EC(hsr); - if (hsr_ec >= ARRAY_SIZE(arm_exit_handlers) || - !arm_exit_handlers[hsr_ec]) { - kvm_err("Unknown exception class: hsr: %#08x -- %s\n", - hsr, esr_get_class_string(hsr)); - BUG(); - } - return arm_exit_handlers[hsr_ec]; }