Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp903238rdb; Sun, 18 Feb 2024 18:41:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUkEu5+qgMblu+YrZfGFPjgczDdhMShJqizncCNPAlRnq7CYP5O+mIH+Vn391CgcWPhcDcxxQLsow4kDbBXQMmcF9hflIRc3di29KWrXg== X-Google-Smtp-Source: AGHT+IEL4j2tCC6obInKKcTsqU1+L43A9oU5ij/TNWrkK6NxwesSnMYfMzoD1pfLQiHtEjRZkDJx X-Received: by 2002:a05:6870:280c:b0:21e:b2ee:75a1 with SMTP id gz12-20020a056870280c00b0021eb2ee75a1mr4738315oab.55.1708310489424; Sun, 18 Feb 2024 18:41:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708310489; cv=pass; d=google.com; s=arc-20160816; b=RBVawnl/4OmuVROh1QLGwoDj9KlPMlskD0FiCs1OMzJAChmUWCCKaqm7gELZdTOWO2 wYEDbbfpNB42ZwEMul2L5a9e09GSSftMg+yqVVxBxXlLB7WT9hxV/dkt5IycG+Fp3/or sA8Ro3yeXE29Fw+wAqPi27e04OE7lD1YPb893tvtYMeWjsPYk4K10eWkBTXb6j4hCl0u 5GdqzRMDZifMnJ/YaaF+Vb6wna2tsEtsWXRKu0/Y8jxQ214hdN1RfLlWkdgVBxKOwwJZ 0gZirCtHii97WbtqsQsEYZ2b9BHopfGAySIG98tyYoLd0GGHs/woKzX/N46HPLZv0vN7 qrZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=5KmZFhNwjrHn2O++ypc9vA0mlaHxppLu/KWqGb01euo=; fh=8uQjUHm7nJItLFsZhPvFTLNhW/gawaXpqymmW1SWpDA=; b=QdafeBwO5PW9f6R4ll+23k2in5/TxC7/08GOuIY2OPn4r+M/wVlebA9zNSZSRewpt0 uJBX4+wsLZJN2kt/t4KiDJcZWd3tGlloAFPCI1aI9KwNRkOQjT9ftZzKwe5Pe7yvSM6N llqgRoFF+elQ0uiYJNyOqoo+oBHRdozkyKrMOSfPb0hRFeSjg+2bIYagDGwAht49xHMM HeP5u6vsA3M6rdMOvmzQHvgaUgL2XmZZre0aBjjObA2t0G6X5WaVc+0R3+LS+acFP5sH rI4HQTCEXs8h253jEbTckN+5w8hjtWhBRqGjs4/DBS+d5jFHlgTFdKuybF2zIV4O+95D k2Uw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=S+OGnFGN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-70660-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70660-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 a65-20020a639044000000b005dc8372020esi3651836pge.580.2024.02.18.18.41.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 18:41:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70660-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=S+OGnFGN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-70660-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70660-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 0AFCDB20B2E for ; Mon, 19 Feb 2024 02:41:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC030440E; Mon, 19 Feb 2024 02:41:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S+OGnFGN" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9722BEDD; Mon, 19 Feb 2024 02:41:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708310472; cv=none; b=s1R8H3wTOEPn9wvvlSM0FtCFBbIsFZOpNyU4lNZoRuz0urR4g6ZmcVxgZpkPEtKrz7HDOvrm+oHDTdYwFEsM//2L09UkuIY5857t6db1dP3E9HTAHWMBgEytiK0rrVq86gWtuPf4uKLQZsKNmX269egWVRd4Un49bhsLZMN6LMI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708310472; c=relaxed/simple; bh=n/DOB7UnLd+txgeMjMhK1a3w80QrfLgIcdMDu/kmSzg=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=mG+EnxwE+F5rUSggWUjMZUdtnecw+I607VSAQnHQenXEeFy7lDKAItuQMyI2FDilaNygr/m/QtpZLb3gBV+I5k2BVlmW7yDwVNLtJ/mhfLlUNhtf/Cg/QEPqmBWZyuq3CU/tabP5fIKejOC7av+cJz1j9bcGCKPlQF4Vts7CKNQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S+OGnFGN; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 127CAC43394; Mon, 19 Feb 2024 02:41:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708310472; bh=n/DOB7UnLd+txgeMjMhK1a3w80QrfLgIcdMDu/kmSzg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=S+OGnFGNjWQfCbxi9spgZO3ZgUu3iOx4/IVtMC2fFZ1mdPkopxJNgaGV7YNl5O7X+ mEVDqZweuwbhJ6sX2pScf6dvDARQ4l2kEomupAXAGWFr3K+ynwdjQ2cke5DT4AkfrF R/wpzatt+FZBsoo3Y6rMTePM6W8ZoD0bqdV6sqK1rSwQ6dcLVRWn1iZOi9GzTpKfiB BM22TPSOuMhGC59jx0aXXcsrHyyyWw4z9duVkfuC2qlqsTlvOxEdZujISm3LdvaMFP fdhZ1heA5dujJoTOaIhh4fEb5cTOZHYVmjR+FB1uzIgOCE2CIMpIjUjUMpDNOnmy2K Z4U7QbFqnnZew== Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-512b700c8ebso249391e87.0; Sun, 18 Feb 2024 18:41:11 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWQobqZhGdFsMc7FnEXUQ0YVSkNl7m1vRWllC/7Zgj9hLXkuJhW735sUuRpbcWnFeZLqX9gsKFwKd7iWwUolqzdPvPe4rMvZUP0CGtwUDusaGsMmayFg42QMSxFkt0BNJ2P X-Gm-Message-State: AOJu0YxEUmW3wB8RMOcVeqHtD8zkh3uIZqQVhhCg6s6g9LTqAlkFKlyU IWQsvo20GZpJ62G3gPtBXBPq83mNHdjM2UuFICqtSMfOlgGdVKptlnGaxQrbs8YK2kQbsQKTVMz CFv0E/PDrZq7LU/NV7VlpNY1xftM= X-Received: by 2002:a05:6512:3d9e:b0:511:61b4:65c1 with SMTP id k30-20020a0565123d9e00b0051161b465c1mr8974984lfv.39.1708310470192; Sun, 18 Feb 2024 18:41:10 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240201031950.3225626-1-maobibo@loongson.cn> <20240201031950.3225626-3-maobibo@loongson.cn> In-Reply-To: <20240201031950.3225626-3-maobibo@loongson.cn> From: Huacai Chen Date: Mon, 19 Feb 2024 10:41:07 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 2/6] LoongArch: KVM: Add hypercall instruction emulation support To: Bibo Mao Cc: Tianrui Zhao , Juergen Gross , Paolo Bonzini , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Bibo, On Thu, Feb 1, 2024 at 11:19=E2=80=AFAM Bibo Mao wrot= e: > > On LoongArch system, hypercall instruction is supported when system > runs on VM mode. This patch adds dummy function with hypercall > instruction emulation, rather than inject EXCCODE_INE invalid > instruction exception. > > 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/a= sm/Kbuild > index 93783fa24f6e..22991a6f0e2b 100644 > --- a/arch/loongarch/include/asm/Kbuild > +++ b/arch/loongarch/include/asm/Kbuild > @@ -23,4 +23,3 @@ generic-y +=3D poll.h > generic-y +=3D param.h > generic-y +=3D posix_types.h > generic-y +=3D resource.h > -generic-y +=3D kvm_para.h > diff --git a/arch/loongarch/include/asm/kvm_para.h b/arch/loongarch/inclu= de/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 Maybe using "hypercall" in comments is better. > + */ > +#define KVM_HC_STATUS_SUCCESS 0 > +#define KVM_HC_INVALID_CODE -1UL > +#define KVM_HC_INVALID_PARAMETER -2UL Maybe KVM_HCALL_SUCCESS/KVM_HCALL_INVALID_CODE/KVM_HCALL_PARAMETER is bette= r. Huacai > + > +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/incl= ude/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 +=3D kvm_para.h > diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c > index ed1d89d53e2e..d15c71320a11 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_hypcall(struct kvm_vcpu *vcpu) > +{ > + update_pc(&vcpu->arch); > + > + /* Treat it as noop intruction, only set return value */ > + vcpu->arch.gprs[LOONGARCH_GPR_A0] =3D KVM_HC_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_ST= ART] =3D { > [EXCCODE_LSXDIS] =3D kvm_handle_lsx_disabled, > [EXCCODE_LASXDIS] =3D kvm_handle_lasx_disabled, > [EXCCODE_GSPR] =3D kvm_handle_gspr, > + [EXCCODE_HVC] =3D kvm_handle_hypcall, > }; > > int kvm_handle_fault(struct kvm_vcpu *vcpu, int fault) > -- > 2.39.3 >