Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp759364lqa; Sun, 28 Apr 2024 03:06:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWF62u/38HCPKiqhkLRCHTN5+I8lOUxLfBsujcS4EXW8qeBxiZNKUu0TCGF/twisbKhTpzRV+8c+y/KGbEkQ4eBUsu2/gJcEsSi/AC+eg== X-Google-Smtp-Source: AGHT+IGKRkSE4xcMO945vl8h6QeOaKJBQlP3oKil2XBzRTB1SG19d7nvYNgO+QQCc1/9K8hAN2tm X-Received: by 2002:a05:6a00:188a:b0:6ed:5655:a02a with SMTP id x10-20020a056a00188a00b006ed5655a02amr9451427pfh.30.1714298806859; Sun, 28 Apr 2024 03:06:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714298806; cv=pass; d=google.com; s=arc-20160816; b=RNJNzziNOgctlu2uz7wY2W+CV5EXfQkZW4TRK5bTKa5GvmO6aZQp56CReuDF/W3AKV ouGJhVNMUEFoxOMcU6hHOtfJhZLNJ6Tm+KGh8zGmAfPP6I3o8v1AHRynmr/fGjufBU62 Y37v7p0XlGsrCiBfVF2lnwdA+WYNU1YpWkJX92z8A6gd6wwlXFSVeurb4/A9823KyHLO PSmnEUS0rVfSevqc7Si6s4Iy09EeSOTysq/HlZHOxDf2O/BZakc6HePY/r5oZ0i75HpA YIBW8cbMIB7gYoASekE3PWRUPcKZp0s5CJgXfrRYvqxgDrvyZMQNAPUS2TxfmrSBzmCA 3K/g== ARC-Message-Signature: i=2; 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:references:in-reply-to:message-id :date:subject:cc:to:from; bh=3A4tpPuXGee4slTMscH2WBYh+2LTtzIKE2jzFVsEtWs=; fh=gX94dkNqn304bMpoKWQ3H95iV7TmWzUlV3lg4yusrXk=; b=lGjIREsHPTMsjWjuRKJ418YCT/LjTRLX9fAoeijJz7XTaiwWP4UZKSJUKEFTheHiPe Qr7KuXpp7Os7/MLQvOMIG4gUIaQ2rZTC0HNozoGeoiUvoBVPIc4RkHnr/5unhD6wKkyC RIuML7pDQHd3BEy07LXJ6f34HnDlF2B88ezjdAaveasKql73vsBIIieeyQHFPbluzdwG kyvRLHOi09OvSGzjyrZDgmqKSHQluxLpULXp81gKSX12dLJ2H5c4JuJd9rXr4FIixib/ nONSmi+cnCi+e8Tp9hLwtyWhBrRg2wRZNhl3MVESU4kIvJVQOLDtfwIZA3FI/8gAts42 VNPw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-161363-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161363-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id jo35-20020a056a0090a300b006f3eca5bf33si2749309pfb.99.2024.04.28.03.06.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Apr 2024 03:06:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-161363-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-161363-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161363-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id B0F70B21477 for ; Sun, 28 Apr 2024 10:06:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3DDB05C611; Sun, 28 Apr 2024 10:05:29 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2F51155E6C; Sun, 28 Apr 2024 10:05:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714298728; cv=none; b=YuZt9PhmtXi8PtcoguR0BgVGJOb6jTH7x4Ov9kMb5UsX9DSBl0n7O/xC6O9oinMGmCNBazOTQfMIl5s3jpLmePFX6nkA5jYqUQ+7cqlAkRY6c6HSQjo8dMW7yDkwYeux5wii+B6nWVRA1EMGRktjvfyxsiUnTLeLfAbLlu1q6UA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714298728; c=relaxed/simple; bh=2FbE4jj+ugZfEAfok1kYC2xiS/f7hM14i+zVMXzSj54=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L2PWqwZycho1Qen3j7WoF/MMjwI3q/l2MryS+VsK0JbigmV2UHTxD3rvNPHlErzXkrQWxcapRGtgJEo6SIbnCLVbBi47JfREHs4pm/gds+b4aH3bmnp7TZY0W6I198CG5aCvWdGm+JIXPRy0ijoaYgSMAiaAOhfb4F0zlzGT8dg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 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 _____8Bx+uliHy5mr10EAA--.3628S3; Sun, 28 Apr 2024 18:05:22 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxsFVeHy5maTIIAA--.5646S4; Sun, 28 Apr 2024 18:05:21 +0800 (CST) From: Bibo Mao To: Huacai Chen , Tianrui Zhao , Juergen Gross , Paolo Bonzini , Jonathan Corbet Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, kvm@vger.kernel.org Subject: [PATCH v8 2/6] LoongArch: KVM: Add hypercall instruction emulation support Date: Sun, 28 Apr 2024 18:05:14 +0800 Message-Id: <20240428100518.1642324-3-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240428100518.1642324-1-maobibo@loongson.cn> References: <20240428100518.1642324-1-maobibo@loongson.cn> 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:AQAAf8DxsFVeHy5maTIIAA--.5646S4 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== On LoongArch system, there is hypercall instruction special for virtualization. When system executes this instruction on host side, there is illegal instruction exception reported, however it will trap into host when it is executed in VM mode. When hypercall is emulated, A0 register is set with value KVM_HCALL_INVALID_CODE, rather than inject EXCCODE_INE invalid instruction exception. So VM can continue to executing the next code. 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 2dbec7853ae8..c862672ed953 100644 --- a/arch/loongarch/include/asm/Kbuild +++ b/arch/loongarch/include/asm/Kbuild @@ -26,4 +26,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..d48f993ae206 --- /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 hypercall return code + */ +#define KVM_HCALL_STATUS_SUCCESS 0 +#define KVM_HCALL_INVALID_CODE -1UL +#define KVM_HCALL_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 ed1d89d53e2e..923bbca9bd22 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -685,6 +685,15 @@ static int kvm_handle_lasx_disabled(struct kvm_vcpu *vcpu) return RESUME_GUEST; } +static int kvm_handle_hypercall(struct kvm_vcpu *vcpu) +{ + update_pc(&vcpu->arch); + + /* Treat it as noop intruction, only set return value */ + vcpu->arch.gprs[LOONGARCH_GPR_A0] = KVM_HCALL_INVALID_CODE; + return RESUME_GUEST; +} + /* * LoongArch KVM callback handling for unimplemented guest exiting */ @@ -716,6 +725,7 @@ static exit_handle_fn kvm_fault_tables[EXCCODE_INT_START] = { [EXCCODE_LSXDIS] = kvm_handle_lsx_disabled, [EXCCODE_LASXDIS] = kvm_handle_lasx_disabled, [EXCCODE_GSPR] = kvm_handle_gspr, + [EXCCODE_HVC] = kvm_handle_hypercall, }; int kvm_handle_fault(struct kvm_vcpu *vcpu, int fault) -- 2.39.3