Received: by 10.223.176.5 with SMTP id f5csp2643683wra; Thu, 1 Feb 2018 03:52:50 -0800 (PST) X-Google-Smtp-Source: AH8x226a8P6CLRlIcrcLtcyrLFgz6sOaniwksVTipJhXVFKZy2nB8FZ8Xe2EPTWUEDMHke0rN2Qb X-Received: by 2002:a17:902:8c81:: with SMTP id t1-v6mr31048110plo.363.1517485970075; Thu, 01 Feb 2018 03:52:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517485970; cv=none; d=google.com; s=arc-20160816; b=jyPkvFwY648ZCDOoesUL5KDj8jQUysYcTv7PAO7xdPIeJRL1FH0W+HmqNbIrbCig35 hhsVKJMBpayfTXwXGJkV7QznQ+zIgOoGbvfZ9M4jcbQ/hVXmrkvAinYus2B02T8qRwtu lk3/Va7Pee3ClU8+Fsli8PvRj3bu+ikstaiLvLj4cn0j4SH7wiboUQuaIFd4T3ln+bQR Mnhv4BU4WumrZvtgg/CG/7175TSw7qEsDc2mWKvnlmi/JPKaV7ggbUVdK3CQ2SFmo+NU yVcSBFto05qajPkJKY4H1go2oY/X9OYPIy4ZS7rJH/cEYbmgTLciXDDJvHZMz8yfA/Sn tBsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=O0dzyMwkP62fGbopo7T17L1qdyq/cfPimkW8DfHf3wE=; b=Ig9kSG5co8JDBA5oFFfZL6G8To2+FXEcokv7jAtloyPyc4yyG9h1yY5zvmI5RyK+fh kpWspPZFy3qFjyyVgrejDbSRZgp6qk+1cwsLv2lezK32Q4gPPZUPh0M6iW2zncuVgLR8 flPvRXSXu4OiQc4lbsqQaQ73KE3IU9XNy8KNTkLS4EdbBPLHF5sPuQfpSfWZGZXA9Gy+ z+RkjhdWcZBpAEENmmo6Pp7H7CdqmaR5ilNEt2McCqXt+FS7AdmyeUFVaZN8PERnx5J0 NUhdjo3+8EkB9/DgVOl/dO8+VSFc4fyvXydr/7arD0TdRfPHkHdIGv8ndxnErTe3GseM Y8xg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bj9-v6si1554568plb.464.2018.02.01.03.52.35; Thu, 01 Feb 2018 03:52:50 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752584AbeBALvk (ORCPT + 99 others); Thu, 1 Feb 2018 06:51:40 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:48322 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752337AbeBALrn (ORCPT ); Thu, 1 Feb 2018 06:47:43 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B181F1596; Thu, 1 Feb 2018 03:47:42 -0800 (PST) Received: from approximate.cambridge.arm.com (approximate.cambridge.arm.com [10.1.207.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E8A373F25C; Thu, 1 Feb 2018 03:47:39 -0800 (PST) From: Marc Zyngier To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Cc: Catalin Marinas , Will Deacon , Peter Maydell , Christoffer Dall , Lorenzo Pieralisi , Mark Rutland , Robin Murphy , Ard Biesheuvel , Andrew Jones , Hanjun Guo , Jayachandran C , Jon Masters , Russell King - ARM Linux Subject: [PATCH v3 02/18] arm: KVM: Fix SMCCC handling of unimplemented SMC/HVC calls Date: Thu, 1 Feb 2018 11:46:41 +0000 Message-Id: <20180201114657.7323-3-marc.zyngier@arm.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180201114657.7323-1-marc.zyngier@arm.com> References: <20180201114657.7323-1-marc.zyngier@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org KVM doesn't follow the SMCCC when it comes to unimplemented calls, and inject an UNDEF instead of returning an error. Since firmware calls are now used for security mitigation, they are becoming more common, and the undef is counter productive. Instead, let's follow the SMCCC which states that -1 must be returned to the caller when getting an unknown function number. Cc: Signed-off-by: Marc Zyngier --- arch/arm/kvm/handle_exit.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/arm/kvm/handle_exit.c b/arch/arm/kvm/handle_exit.c index cf8bf6bf87c4..a4bf0f6f024a 100644 --- a/arch/arm/kvm/handle_exit.c +++ b/arch/arm/kvm/handle_exit.c @@ -38,7 +38,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run) ret = kvm_psci_call(vcpu); if (ret < 0) { - kvm_inject_undefined(vcpu); + vcpu_set_reg(vcpu, 0, ~0UL); return 1; } @@ -47,7 +47,16 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run) static int handle_smc(struct kvm_vcpu *vcpu, struct kvm_run *run) { - kvm_inject_undefined(vcpu); + /* + * "If an SMC instruction executed at Non-secure EL1 is + * trapped to EL2 because HCR_EL2.TSC is 1, the exception is a + * Trap exception, not a Secure Monitor Call exception [...]" + * + * We need to advance the PC after the trap, as it would + * otherwise return to the same address... + */ + vcpu_set_reg(vcpu, 0, ~0UL); + kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); return 1; } -- 2.14.2