Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1146577lqh; Sun, 5 May 2024 19:41:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUkMYDIjRKM63dg/gNLoi3b7o11o3SbiT91eaRnO0p4hwhUitqi0XLoFuBbPmMRNBivWOiqEst4kKFwpvea2t3Vv82FcNbc8KWIq2Gkpw== X-Google-Smtp-Source: AGHT+IETHSjtfsaeZ5SjsT49Mz+YbFZCbwqpf2fBLFA62RqfrOF/JzhBkmBUFhRJ5musBPZs9eRF X-Received: by 2002:a05:6808:2908:b0:3c6:9c5:7b6 with SMTP id ev8-20020a056808290800b003c609c507b6mr10009371oib.23.1714963291939; Sun, 05 May 2024 19:41:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714963291; cv=pass; d=google.com; s=arc-20160816; b=EazpT0Ti63K731S+RA8ZRvbL5mTMbAWfdd7Yq1dKSeAbSQnvbo/4BrxsxPMtDYj2e6 9NE3by3zHXxpsW4msbKfTGFiJ7i24c6sEOPt3l4+PZI99a0RaHoDHsoZiQxdUBYHiP+J M4RzOYV0spTigP09wF2SlzyUkhYyqSSb8ANK/RiD96LuQ+efCKYOncrwJSLDva0+XkKu 9TuOfk6EFYpSfQposyYfor3nuu9zLTs4nReK/sC3X8n4a30nyfDtzDchmRFKtYkfjPM5 +HMilTzntB0BVjVFJfoKtb3aitC3k7v/kLpFVlYR9sGQSAKHbvFbq611VuP+uj3R6bfI Buww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent:date :message-id:from:references:cc:to:subject; bh=h8lUlTlpX5tW0eP+mR+EkxaLGVneP7kIy75619cC1zo=; fh=CXs9v6wxz1RS3jNhqU8uet3La6EKRrcyqg/6VK5sq6E=; b=IGThEr581J5Y0TkWWP5DTWdiSu8ahZv5PxoxvISfOb919jiOtulWu9O01dfICOoH5q OwG3hntaadOtkRJ2DCGaUhMcV3t+R3Ywxot8NmhRuvqCmoveErWxFZFFy4CSjY2RlIZb DV2pbjz+ed1mgWnhyHosJQccM/66hAYJfZfCR5ZdaEpKciTy9pvRXmCctA77DZ1H2VvD 3lwPI1xOhtdcMEKbYIGLYBrRHX7m3RH+MeEhWcj6JfOIljJgRxNaY36hLjFYZhUlxsCL BJlb+6S/O36DnhP32WSH2m7FbL7ZOcWfFCCa202wB1LCfIPgaYPI2u4cHnKLWNlym3YB 4xsg==; 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-169264-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169264-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 u4-20020a056a00124400b006f443f53addsi6629585pfi.66.2024.05.05.19.41.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 May 2024 19:41:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169264-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-169264-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169264-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 C4033B21916 for ; Mon, 6 May 2024 02:41:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D5A341741; Mon, 6 May 2024 02:41:15 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 178D7181; Mon, 6 May 2024 02:41:10 +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=1714963275; cv=none; b=UneGyPDbk2Zcsw7QLTQOKafwKQtcZHCeGJ7yPd2h0B95RPmV9ak3quyqvwvBCluyr5kKa8/Wrj1sLOIAv3TPjgb3XzCd4cfe8AgjxI6hghGvSagyARXNeXbIbOwuGe7uTmdkxw6gKzwYlBJI4IdF6iwDRehEYcupZI41Z95dJb8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714963275; c=relaxed/simple; bh=FrQ3Q4c+zpCTWdWoQPf9Jye9fRyoe4zWRs8w0j8CC9Y=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=lDgi/wxx5DhRX4oZ8xKzfnkfG+NxFRgSdrW3XE5uIYExn1743XIg/PCRPzfArxeIrQmidg/24lcQlgq6jXban5IvLOWVFRslaxT0RH+OVjOKef6uawMg1FIziTEVpAP8pUo746JUlSqlfun9zpwds5O5fVDAw+t7CAwsHQ/jJhs= 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.20.42.173]) by gateway (Coremail) with SMTP id _____8Bx3+tEQzhmmN8HAA--.22454S3; Mon, 06 May 2024 10:41:08 +0800 (CST) Received: from [10.20.42.173] (unknown [10.20.42.173]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxU1ZAQzhms_MRAA--.19845S3; Mon, 06 May 2024 10:41:06 +0800 (CST) Subject: Re: [PATCH v8 2/6] LoongArch: KVM: Add hypercall instruction emulation support To: Huacai Chen Cc: Tianrui Zhao , Juergen Gross , Paolo Bonzini , Jonathan Corbet , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, kvm@vger.kernel.org References: <20240428100518.1642324-1-maobibo@loongson.cn> <20240428100518.1642324-3-maobibo@loongson.cn> From: maobibo Message-ID: Date: Mon, 6 May 2024 10:41:02 +0800 User-Agent: Mozilla/5.0 (X11; Linux loongarch64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-CM-TRANSID:AQAAf8BxU1ZAQzhms_MRAA--.19845S3 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxGF17Cw18XrWrCF13AFyruFX_yoWrXFW3pF ykCrn5Ga18KryxCF13t3Z0grnxArs5Kr129Fy7K34jyFsFqr18tr4kKrZ8uFy5Gw4rZF1S qFyFqw13uF4UtacCm3ZEXasCq-sJn29KB7ZKAUJUUUU7529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUB0b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcVAKI48JMx k0xIA0c2IEe2xFo4CEbIxvr21l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67 AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8I cVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI 8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v2 6r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxU4AhLUUUUU On 2024/5/6 上午9:54, Huacai Chen wrote: > Hi, Bibo, > > On Sun, Apr 28, 2024 at 6:05 PM Bibo Mao wrote: >> >> 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 > This file shouldn't be removed. yes, uapi kvm_param.h is needed for Loongarch, and there will be problem if it is removed. And it should kept unchanged. Regards Bibo Mao > > Huacai > >> 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 >> >>