Skip to content

Commit 09e6be1

Browse files
Marc Zyngierctmarinas
authored andcommitted
arm/arm64: KVM: Advertise SMCCC v1.1
The new SMC Calling Convention (v1.1) allows for a reduced overhead when calling into the firmware, and provides a new feature discovery mechanism. Make it visible to KVM guests. Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 58e0b22 commit 09e6be1

5 files changed

Lines changed: 39 additions & 4 deletions

File tree

‎arch/arm/kvm/handle_exit.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run)
3636
kvm_vcpu_hvc_get_imm(vcpu));
3737
vcpu->stat.hvc_exit_stat++;
3838

39-
ret = kvm_psci_call(vcpu);
39+
ret = kvm_hvc_call_handler(vcpu);
4040
if (ret < 0) {
4141
vcpu_set_reg(vcpu, 0, ~0UL);
4242
return 1;

‎arch/arm64/kvm/handle_exit.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run)
5252
kvm_vcpu_hvc_get_imm(vcpu));
5353
vcpu->stat.hvc_exit_stat++;
5454

55-
ret = kvm_psci_call(vcpu);
55+
ret = kvm_hvc_call_handler(vcpu);
5656
if (ret < 0) {
5757
vcpu_set_reg(vcpu, 0, ~0UL);
5858
return 1;

‎include/kvm/arm_psci.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
#define KVM_ARM_PSCI_LATEST KVM_ARM_PSCI_1_0
2828

2929
int kvm_psci_version(struct kvm_vcpu *vcpu);
30-
int kvm_psci_call(struct kvm_vcpu *vcpu);
30+
int kvm_hvc_call_handler(struct kvm_vcpu *vcpu);
3131

3232
#endif /* __KVM_ARM_PSCI_H__ */

‎include/linux/arm-smccc.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@
6060
#define ARM_SMCCC_QUIRK_NONE 0
6161
#define ARM_SMCCC_QUIRK_QCOM_A6 1 /* Save/restore register a6 */
6262

63+
#define ARM_SMCCC_VERSION_1_0 0x10000
64+
#define ARM_SMCCC_VERSION_1_1 0x10001
65+
66+
#define ARM_SMCCC_VERSION_FUNC_ID \
67+
ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \
68+
ARM_SMCCC_SMC_32, \
69+
0, 0)
70+
71+
#define ARM_SMCCC_ARCH_FEATURES_FUNC_ID \
72+
ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \
73+
ARM_SMCCC_SMC_32, \
74+
0, 1)
75+
6376
#ifndef __ASSEMBLY__
6477

6578
#include <linux/linkage.h>

‎virt/kvm/arm/psci.c‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18+
#include <linux/arm-smccc.h>
1819
#include <linux/preempt.h>
1920
#include <linux/kvm_host.h>
2021
#include <linux/wait.h>
@@ -339,6 +340,7 @@ static int kvm_psci_1_0_call(struct kvm_vcpu *vcpu)
339340
case PSCI_0_2_FN_SYSTEM_OFF:
340341
case PSCI_0_2_FN_SYSTEM_RESET:
341342
case PSCI_1_0_FN_PSCI_FEATURES:
343+
case ARM_SMCCC_VERSION_FUNC_ID:
342344
val = 0;
343345
break;
344346
default:
@@ -393,7 +395,7 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu)
393395
* Errors:
394396
* -EINVAL: Unrecognized PSCI function
395397
*/
396-
int kvm_psci_call(struct kvm_vcpu *vcpu)
398+
static int kvm_psci_call(struct kvm_vcpu *vcpu)
397399
{
398400
switch (kvm_psci_version(vcpu)) {
399401
case KVM_ARM_PSCI_1_0:
@@ -406,3 +408,23 @@ int kvm_psci_call(struct kvm_vcpu *vcpu)
406408
return -EINVAL;
407409
};
408410
}
411+
412+
int kvm_hvc_call_handler(struct kvm_vcpu *vcpu)
413+
{
414+
u32 func_id = smccc_get_function(vcpu);
415+
u32 val = PSCI_RET_NOT_SUPPORTED;
416+
417+
switch (func_id) {
418+
case ARM_SMCCC_VERSION_FUNC_ID:
419+
val = ARM_SMCCC_VERSION_1_1;
420+
break;
421+
case ARM_SMCCC_ARCH_FEATURES_FUNC_ID:
422+
/* Nothing supported yet */
423+
break;
424+
default:
425+
return kvm_psci_call(vcpu);
426+
}
427+
428+
smccc_set_retval(vcpu, val, 0, 0, 0);
429+
return 1;
430+
}

0 commit comments

Comments
 (0)