Received: by 10.223.176.5 with SMTP id f5csp948983wra; Tue, 6 Feb 2018 09:58:26 -0800 (PST) X-Google-Smtp-Source: AH8x2265uwLpOirCCHG+uZCLwETCsppcLNdCW2rMSn17/3mH0zkjsdsFye0I8kuYKpWdSiVagg4p X-Received: by 10.98.57.131 with SMTP id u3mr3186880pfj.237.1517939906684; Tue, 06 Feb 2018 09:58:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517939906; cv=none; d=google.com; s=arc-20160816; b=So0TdpPu9St+Q/HF0qSnS6L1HnesQ1wwdBg6r9W95FRqscL9SlY4Wq9E4OeZv1N1Tc QTo8icxJvgSpKQMnMARL8SxWB2/jEa0Pm2co+TiVmics4KgNn9pI/JQwxdMy/3kdNHQx Et23MuVSPypDvzmL3fKkIDWZGTLaS6q1mjb54mYdHO4zOsiyDG0CsgSN05YyEvb7rlT0 OXdDiqgeMe9/2FnwwmpgRz1b4ERx+xNFR1KEOgcWLcV9eJhnK530YMVN5E448o81do+J m2Sk+VyyEmtXsGQbysL28GQk3Xcr9pJ8aCaQ7NSqLAexfaTXd4m5Ncsh3m8npr2Yh/cv w5vA== 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=nwUrUx0K4/dvBNK6rmZIXyVia6qPD43PU0tvEsc7MOA=; b=mCatM4lnGF/RrpbJIk425nogEQDdPAkfqmD16AMVSAs9Q6BHLywEca7eDmte4CP4bp ZXcMFuH31gNhBSZMIR6sPDr8gJLLCJwumYHGlPaD7WqRRgm11TsFUbWQny20f4zITahE vVC+90W49HrOGGCk3O1h+uCa8krPm5L6C83XGvVimw2pmoqMnNhx4VnEmv7geh1nI2sN OM+CTaYIHnAnSbfhwQyZnTgFUkgqlDuYyFpgePilgB46i1HcpgRiPbCVptwortSZkPKz U8V2j+FZbhbJSbTQN75ZngNIVy6hcvLw3j6xawI0+TluFmA/SNJZ9YmOoZyvy+Aks2Vj jmcQ== 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 x2-v6si184741plv.672.2018.02.06.09.58.13; Tue, 06 Feb 2018 09:58:26 -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 S1752799AbeBFR5M (ORCPT + 99 others); Tue, 6 Feb 2018 12:57:12 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:40964 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752680AbeBFR4x (ORCPT ); Tue, 6 Feb 2018 12:56:53 -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 7BCAF1610; Tue, 6 Feb 2018 09:56:52 -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 CE63F3F25C; Tue, 6 Feb 2018 09:56:49 -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 v4 02/17] arm: KVM: Fix SMCCC handling of unimplemented SMC/HVC calls Date: Tue, 6 Feb 2018 17:56:06 +0000 Message-Id: <20180206175621.929-3-marc.zyngier@arm.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180206175621.929-1-marc.zyngier@arm.com> References: <20180206175621.929-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: Tested-by: Ard Biesheuvel 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