Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3216096rdb; Tue, 26 Dec 2023 23:09:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IFIIhseBx8EOdc6lKCt5g4GT7oUHFudZdRYreAjU4d2IjovH0Z/gPMPu/+jz4H1uokYJMD+ X-Received: by 2002:a50:cd82:0:b0:54c:5d36:42e6 with SMTP id p2-20020a50cd82000000b0054c5d3642e6mr4309180edi.81.1703660981211; Tue, 26 Dec 2023 23:09:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703660981; cv=none; d=google.com; s=arc-20160816; b=DIuKoeuBjcCPg/nM4QP8uRmxMN7pFaCtymJYZMzdrT6uV+iYNTEhTa4rHglG+XFyzR 1J2ru/4VjSD4KflGLr2WCacGDNc7lNjdNiQPILAsYPaLykEOmjtYqvb53rLAUQPw4hHo esNorvTx08BkbXXThZWvf6JF+wcgkZnu2vzWBbFEzLjrNmUo/UZeaAGs3lrG4YjOIJv3 DvVOEgezVPtmNYVDwSl4miD1badNpuEqFtwsfiUdiLzguNP8Epn1kbP94SqDVobOxpvU sIXvDVYHETcSkLeTrD+MoVm/45cLTNQ67TOpSuSwaBBjevti9l5sYUmo1Oybr5p/A3iF N+zA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=NRr0eAWs/yHzMvVwQy8+MIYhoR1Kw7To12FkmV3xRTk=; fh=ARu4TK12lORFZw6wDzpgJhsE9RDInc2w9DEq/BtTOMk=; b=BVXq6X5yRbs3NlcpQoTN5VWt5twXp3MCG7INP0tRfaFX4kXs3XoCzs4PnKg7efd5dc Bus9uCsatL1QursXYDxI+I0CLyj3nLEGcHkrBCdTSos6ou9/iWxQizeUTTksDAgBeGit iADQTRe0OS9euSpQohnksQE0qDzZvJIMf27wKZUcEJ3OmpHFvNHWgd4YAwsd59++V5fV 74asyP6kX28D0YXZpmm0rK4B9FIMGvxeGjtayE5QEpfXz6MpjI8/bEQNOEJb0TmhX/QK i/44hX2feTJTkkbE1YI6NkN3EtzPNBKDoWIWNfQfIE62H/PVlZN/r5ZHJxEe+gXP4SxX XGRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-11877-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11877-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v18-20020a50d592000000b00553fad4c99csi6021770edi.399.2023.12.26.23.09.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 23:09:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11877-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-11877-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11877-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id F1D831F22D03 for ; Wed, 27 Dec 2023 07:09:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0DE2B5662; Wed, 27 Dec 2023 07:09:29 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C22B6118; Wed, 27 Dec 2023 07:09:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8AxG+mjzYtljvMEAA--.23631S3; Wed, 27 Dec 2023 15:09:23 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bxrr6izYtlJHYMAA--.37462S2; Wed, 27 Dec 2023 15:09:22 +0800 (CST) From: Bibo Mao To: Huacai Chen , Tianrui Zhao Cc: WANG Xuerui , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH] LoongArch: KVM: Add hypercall instruction emulation support Date: Wed, 27 Dec 2023 15:09:22 +0800 Message-Id: <20231227070922.1411467-1-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:AQAAf8Bxrr6izYtlJHYMAA--.37462S2 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxXryDXFyxtFWkCFWktr4xAFc_yoW5Zr1DpF 93Cr1kGr48GryfCFy3twn8Wr13Ars7K342gFW2k3y5AF12qF1Fyr4kKryDZFy5Ja1rXF1S gFWftw1Y9F4UtagCm3ZEXasCq-sJn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv 67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07jUsqXUUUUU= On LoongArch system, hypercall instruction is supported when system runs on VM mode. This patch adds dummy function for hypercall instruction emulation, rather than inject EXCCODE_INE invalid instruction exception to VM. Signed-off-by: Bibo Mao --- arch/loongarch/include/asm/Kbuild | 1 - arch/loongarch/include/asm/kvm_para.h | 26 ++++++++++++++++++++++++++ arch/loongarch/include/uapi/asm/Kbuild | 2 -- arch/loongarch/kvm/exit.c | 10 ++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 arch/loongarch/include/asm/kvm_para.h delete mode 100644 arch/loongarch/include/uapi/asm/Kbuild diff --git a/arch/loongarch/include/asm/Kbuild b/arch/loongarch/include/asm/Kbuild index 93783fa24f6e..22991a6f0e2b 100644 --- a/arch/loongarch/include/asm/Kbuild +++ b/arch/loongarch/include/asm/Kbuild @@ -23,4 +23,3 @@ generic-y += poll.h generic-y += param.h generic-y += posix_types.h generic-y += resource.h -generic-y += kvm_para.h diff --git a/arch/loongarch/include/asm/kvm_para.h b/arch/loongarch/include/asm/kvm_para.h new file mode 100644 index 000000000000..9425d3b7e486 --- /dev/null +++ b/arch/loongarch/include/asm/kvm_para.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_LOONGARCH_KVM_PARA_H +#define _ASM_LOONGARCH_KVM_PARA_H + +/* + * LoongArch hypcall return code + */ +#define KVM_HC_STATUS_SUCCESS 0 +#define KVM_HC_INVALID_CODE -1UL +#define KVM_HC_INVALID_PARAMETER -2UL + +static inline unsigned int kvm_arch_para_features(void) +{ + return 0; +} + +static inline unsigned int kvm_arch_para_hints(void) +{ + return 0; +} + +static inline bool kvm_check_and_clear_guest_paused(void) +{ + return false; +} +#endif /* _ASM_LOONGARCH_KVM_PARA_H */ diff --git a/arch/loongarch/include/uapi/asm/Kbuild b/arch/loongarch/include/uapi/asm/Kbuild deleted file mode 100644 index 4aa680ca2e5f..000000000000 --- a/arch/loongarch/include/uapi/asm/Kbuild +++ /dev/null @@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -generic-y += kvm_para.h diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c index ce8de3fa472c..f453a3e40cab 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -659,6 +659,15 @@ static int kvm_handle_fpu_disabled(struct kvm_vcpu *vcpu) return RESUME_GUEST; } +static int kvm_handle_hypcall(struct kvm_vcpu *vcpu) +{ + update_pc(&vcpu->arch); + + /* Treat it as noop intruction, only set return value */ + vcpu->arch.gprs[LOONGARCH_GPR_A0] = KVM_HC_INVALID_CODE; + return RESUME_GUEST; +} + /* * LoongArch KVM callback handling for unimplemented guest exiting */ @@ -688,6 +697,7 @@ static exit_handle_fn kvm_fault_tables[EXCCODE_INT_START] = { [EXCCODE_TLBM] = kvm_handle_write_fault, [EXCCODE_FPDIS] = kvm_handle_fpu_disabled, [EXCCODE_GSPR] = kvm_handle_gspr, + [EXCCODE_HVC] = kvm_handle_hypcall, }; int kvm_handle_fault(struct kvm_vcpu *vcpu, int fault) -- 2.39.3