From patchwork Thu Jan 18 21:00:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 125045 Delivered-To: patch@linaro.org Received: by 10.46.64.27 with SMTP id n27csp296223lja; Thu, 18 Jan 2018 13:04:07 -0800 (PST) X-Google-Smtp-Source: ACJfBovvC1t9QRbKsnKxX7Kmlbp5fOB9Mho+0ZFiMJJXvHp2OwnjdwHeS67JJp4sSCqNFM07ZAuA X-Received: by 10.98.247.19 with SMTP id h19mr23791209pfi.77.1516309447465; Thu, 18 Jan 2018 13:04:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516309447; cv=none; d=google.com; s=arc-20160816; b=bfVVitdLmwhiDCev9bSK6+zNLYP5uyAQTZjhsZOVZvXvZ65vrSoSxhlXAJ2Shwd2xH 6nm6YcxdrnOa2YzAUveqQxKVp6bLsopSPHY55paBDkLXS2QWI5HHpEZu8hqgY1WrsW6z 0c4gZ0V28Z4NKgfZEYGUH6EA5rW7fnUgMOxP9OjJVZbg++ulF5rdA3IAvahzDD+2kCfP Wc9iMRyRyyl1zMIpRC1PNzV4G2FWGqMk+tU3HMdvLYElzkAbjZipSPLmnlyzZ3TaNMBO L33QbvmOm2e5y1b/D0gf+xVzqTaTw8nS7zqgbdg8fjHemHoIiwQ1YWazgu+TML/2daGj Kk4A== 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 :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=jWnNySF4p7iTuKt88ntvl+Fr7bdxDErelRfquKlCRGk=; b=MeLfjUkpbxqp4mFytjvNkUvRInuhwY8YsCG9g/Ruy0+2/S9uWrzIGBGRzr11u/0rUy o8tMs9ofdJvftN9GXuuhyr162Ac4jFUzrteogrcxPU/w+z8Ro5id5NIae7wWz7Ua85F1 L8uQ8rokT7rGbc3W7/OqAPChlRP2CcT7LFRDg2Q3FNAjtZWlQjvqypjvFfkI+PCi0ff9 z3EFBro10A1FteJvI3VPrGnJIlPObhSaozDYTlVL05FopVd2AOx+qVF0yRF48CJr5Bsq zxjpEt9f+dfFc/VsUDSv/gXd8B3L9Olvled8D9IdyjTftOaVBeZyRajLCMXDjhasL2Ep XIhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=XF9MXo2h; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s22si6131684pfh.396.2018.01.18.13.04.07; Thu, 18 Jan 2018 13:04:07 -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=pass header.i=@microsoft.com header.s=selector1 header.b=XF9MXo2h; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932287AbeARVEG (ORCPT + 10 others); Thu, 18 Jan 2018 16:04:06 -0500 Received: from mail-cys01nam02on0131.outbound.protection.outlook.com ([104.47.37.131]:44165 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932540AbeARVD6 (ORCPT ); Thu, 18 Jan 2018 16:03:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=jWnNySF4p7iTuKt88ntvl+Fr7bdxDErelRfquKlCRGk=; b=XF9MXo2hpuZkEQWWP/iveuf5G3IYMeAFQGbUsO8XoT968DRHzMytedQjdcoe3CglZIX0IC7rEwUZFgbuJQiAdUziJ3lP05Fp582rQs88DDp9peQqdSdflOxnsi0cmgxi8ZfeQvqQP6g+xunYnCclQ2NNP848ETI8ANvaqfcF8Cs= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0728.namprd21.prod.outlook.com (10.167.110.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.428.7; Thu, 18 Jan 2018 21:03:55 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7%2]) with mapi id 15.20.0428.008; Thu, 18 Jan 2018 21:03:55 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Mark Rutland , Marc Zyngier , Sasha Levin Subject: [added to the 4.1 stable tree] arm: KVM: Survive unknown traps from guests Thread-Topic: [added to the 4.1 stable tree] arm: KVM: Survive unknown traps from guests Thread-Index: AQHTkJ9xt4QnKfk2C0GTNL+ojb5LHg== Date: Thu, 18 Jan 2018 21:00:59 +0000 Message-ID: <20180118205908.3220-179-alexander.levin@microsoft.com> References: <20180118205908.3220-1-alexander.levin@microsoft.com> In-Reply-To: <20180118205908.3220-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [167.220.98.9] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM5PR2101MB0728; 7:Np8GOGjvbtbyjpW6nHt1o/6IgxIS4UDoojjEuri22bJ5y3c5iN29TL+GthYrsOEXG++77MEXYA0AIsabM6cQaA4f5K6cHcawa3ihKCvU+5ngB+QxJ/ZU0IE/Pi/LQ77O5cYZl8fNkfk4bhT56q8GqECTuKGlr616Uy+O6HiyJtlPq0uUqYNVbuyYYiXE0pe4RgI9xn2G+Lz6s4fGmGRxPWS3AIPQhi80s4Ekd7W/svKq5WP2hKkfC9Q/txaF3WqI x-ms-office365-filtering-correlation-id: f71d234b-38cb-40fb-36e3-08d55eb6fc3f x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(48565401081)(4534125)(4602075)(4627221)(201703031133081)(201702281549075)(2017052603307)(7193020); SRVR:DM5PR2101MB0728; x-ms-traffictypediagnostic: DM5PR2101MB0728: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(180628864354917)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(61425038)(6040495)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(93001095)(3231046)(2400067)(944501161)(6055026)(61426038)(61427038)(6041282)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(20161123564045)(20161123562045)(6072148)(201708071742011); SRVR:DM5PR2101MB0728; BCL:0; PCL:0; RULEID:(100000803126)(100110400120); SRVR:DM5PR2101MB0728; x-forefront-prvs: 05568D1FF7 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(39860400002)(346002)(376002)(366004)(39380400002)(189003)(199004)(2950100002)(6436002)(10290500003)(3280700002)(478600001)(305945005)(8936002)(2906002)(86612001)(36756003)(72206003)(3660700001)(4326008)(7736002)(99286004)(97736004)(26005)(22452003)(6486002)(86362001)(6346003)(59450400001)(316002)(6512007)(102836004)(5660300001)(68736007)(54906003)(1076002)(106356001)(14454004)(2501003)(10090500001)(76176011)(6116002)(110136005)(105586002)(25786009)(53936002)(5250100002)(6506007)(81156014)(66066001)(2900100001)(81166006)(107886003)(8676002)(3846002)(22906009); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR2101MB0728; H:DM5PR2101MB1032.namprd21.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: R9LcYtVqj7undgqlKrTYS5ZqCh9/YuXDZzmWq1d+GVRQK8ejvliEzxr20vP50YCZiKzPhNeZc10AypfmKrQAmg== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: f71d234b-38cb-40fb-36e3-08d55eb6fc3f X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2018 21:00:59.4774 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0728 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Mark Rutland This patch has been added to the stable tree. If you have any objections, please let us know. -- 2.11.0 =============== [ 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(-) diff --git a/arch/arm/include/asm/kvm_arm.h b/arch/arm/include/asm/kvm_arm.h index d995821f1698..aacd6668d1a0 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]; }