Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp3102522rdb; Wed, 15 Nov 2023 23:19:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQdsMRlGKbj9clhoBruVERtY1ptmYDvvtz/CxV/uS3frtzAkxOTs/PJG9BsZupPm4XSeLi X-Received: by 2002:a05:6808:16a8:b0:3ab:8956:ad95 with SMTP id bb40-20020a05680816a800b003ab8956ad95mr21908768oib.9.1700119185197; Wed, 15 Nov 2023 23:19:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700119185; cv=none; d=google.com; s=arc-20160816; b=Erexf13ALDewKp5oI95pqELhfRP0GocuZ7yr6TdGrn2u7e5OtlJaZE7626Kj6O+gSn hmgQPl7E9OWsIJJq+QjhR1hzR2N7K0MFzcm+MJEWCqB7InkvJc6JUgNXnHUUdd9NU37k ErtBgQJmpSgT3lPidvk+ZSivlmETlzu7/sIfmpA6pHciWn3fNHQESTdrt8MO41Dyt1I3 Hxvp8ONcy7mIiIlnudFssUVj66w1PynNbuaVkIWaIuwJ990Cc5SJk4Ltyrl0Nl+4gHQh gv92KMWA+pjtFqwxT9nhOaaTgOxpUcEfK8hqQgkIH/DHeekx2EY/YwQvobHtsJtOw3Ka lZyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=EVv7r/UPrQmE4W9AwaT4aSt+8QnYKe5K7s5EQuN7Wlk=; fh=jnlkXsFS1OMQ/VTh32C0rJeIAmxK/E6VzUhq5tA4Q34=; b=MzvOXwodYjevyubu+N1N6AttiGCgTPrPEA/9O7GME9L23y7uRlqY13CDaMw0y9jviJ krwhdfikR9vHnXQt0eaP+rW8hGabSZWDeS6QHesuha+cMXKGGET2Ct5oelwRE0l6Jv51 yVXGplynEA17rE3MDaOW7kUBSf89104klMwmNw72FL5RA6RyMN+bJiVWcvold0yq3dQq 2IFcKuZ2thNC5JhJbLA9JCdzfYrdwywe8YZZN4ysPw+dVcXquJjrJeUFQ+3nv9xK2i8m PIDBAtAoM2nd0scR2zg2pqKaD4/LH0USKSI3txSQBrdyj78qPLZKOstdOPNJfdk6tk+O r1tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b="KA5J/G4U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id n189-20020a6327c6000000b005b8f61fcb98si12462901pgn.629.2023.11.15.23.19.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 23:19:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b="KA5J/G4U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 5C2F981113A2; Wed, 15 Nov 2023 23:19:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234622AbjKPHTa (ORCPT + 99 others); Thu, 16 Nov 2023 02:19:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229638AbjKPHT3 (ORCPT ); Thu, 16 Nov 2023 02:19:29 -0500 X-Greylist: delayed 263 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 15 Nov 2023 23:19:25 PST Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81A96C5; Wed, 15 Nov 2023 23:19:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1700119163; bh=q2AuehPSVg0PAMSpgfi8EJzOTmrs6NwGqXh97Sh11+Y=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=KA5J/G4UWDHFRE1c0EwMstzoUwRQYy+31GHqhkrgTtAWX/o/FY1SZ+czziBtEZvQ0 dzHnpB3y4OGJwtuBJ/hJQJBBEjd23BRQcHBVdWZBvPa+ZiQPPfGTYO8rqqRe3g7Tt8 dWbA+U4QiRy6lUamE8A0a7NCfw+BNQmftIqM97r8= Received: from [IPV6:240e:388:8d26:bf00:6f50:1e00:d62c:dcf9] (unknown [IPv6:240e:388:8d26:bf00:6f50:1e00:d62c:dcf9]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id 79AC16018A; Thu, 16 Nov 2023 15:19:23 +0800 (CST) Message-ID: Date: Thu, 16 Nov 2023 15:19:23 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 2/2] LoongArch: KVM: Add lasx support Content-Language: en-US To: Tianrui Zhao , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Huacai Chen , Greg Kroah-Hartman , loongarch@lists.linux.dev, Jens Axboe , Mark Brown , Alex Deucher , Oliver Upton , maobibo@loongson.cn, Xi Ruoyao References: <20231115091921.85516-1-zhaotianrui@loongson.cn> <20231115091921.85516-3-zhaotianrui@loongson.cn> From: WANG Xuerui In-Reply-To: <20231115091921.85516-3-zhaotianrui@loongson.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 15 Nov 2023 23:19:42 -0800 (PST) On 11/15/23 17:19, Tianrui Zhao wrote: > This patch adds LASX support for LoongArch KVM. The LASX means > LoongArch 256-bits vector instruction. > There will be LASX exception in KVM when guest use the LASX > instruction. KVM will enable LASX and restore the vector > registers for guest then return to guest to continue running. > > Signed-off-by: Tianrui Zhao > --- > arch/loongarch/include/asm/kvm_host.h | 6 ++++ > arch/loongarch/include/asm/kvm_vcpu.h | 10 +++++++ > arch/loongarch/kernel/fpu.S | 1 + > arch/loongarch/kvm/exit.c | 18 +++++++++++ > arch/loongarch/kvm/switch.S | 16 ++++++++++ > arch/loongarch/kvm/trace.h | 4 ++- > arch/loongarch/kvm/vcpu.c | 43 ++++++++++++++++++++++++++- > 7 files changed, 96 insertions(+), 2 deletions(-) > > diff --git a/arch/loongarch/include/asm/kvm_host.h b/arch/loongarch/include/asm/kvm_host.h > index 6c65c25169..4c05b5eca0 100644 > --- a/arch/loongarch/include/asm/kvm_host.h > +++ b/arch/loongarch/include/asm/kvm_host.h > @@ -95,6 +95,7 @@ enum emulation_result { > #define KVM_LARCH_SWCSR_LATEST (0x1 << 1) > #define KVM_LARCH_HWCSR_USABLE (0x1 << 2) > #define KVM_LARCH_LSX (0x1 << 3) > +#define KVM_LARCH_LASX (0x1 << 4) > > struct kvm_vcpu_arch { > /* > @@ -181,6 +182,11 @@ static inline bool kvm_guest_has_lsx(struct kvm_vcpu_arch *arch) > return arch->cpucfg[2] & CPUCFG2_LSX; > } > > +static inline bool kvm_guest_has_lasx(struct kvm_vcpu_arch *arch) > +{ > + return arch->cpucfg[2] & CPUCFG2_LASX; > +} > + > /* Debug: dump vcpu state */ > int kvm_arch_vcpu_dump_regs(struct kvm_vcpu *vcpu); > > diff --git a/arch/loongarch/include/asm/kvm_vcpu.h b/arch/loongarch/include/asm/kvm_vcpu.h > index c629771e12..4f87f16018 100644 > --- a/arch/loongarch/include/asm/kvm_vcpu.h > +++ b/arch/loongarch/include/asm/kvm_vcpu.h > @@ -67,6 +67,16 @@ static inline void kvm_restore_lsx(struct loongarch_fpu *fpu) { } > static inline void kvm_restore_lsx_upper(struct loongarch_fpu *fpu) { } > #endif > > +#ifdef CONFIG_CPU_HAS_LASX > +void kvm_own_lasx(struct kvm_vcpu *vcpu); > +void kvm_save_lasx(struct loongarch_fpu *fpu); > +void kvm_restore_lasx(struct loongarch_fpu *fpu); > +#else > +static inline void kvm_own_lasx(struct kvm_vcpu *vcpu) { } > +static inline void kvm_save_lasx(struct loongarch_fpu *fpu) { } > +static inline void kvm_restore_lasx(struct loongarch_fpu *fpu) { } > +#endif > + > void kvm_acquire_timer(struct kvm_vcpu *vcpu); > void kvm_init_timer(struct kvm_vcpu *vcpu, unsigned long hz); > void kvm_reset_timer(struct kvm_vcpu *vcpu); > diff --git a/arch/loongarch/kernel/fpu.S b/arch/loongarch/kernel/fpu.S > index d53ab10f46..f4524fe866 100644 > --- a/arch/loongarch/kernel/fpu.S > +++ b/arch/loongarch/kernel/fpu.S > @@ -384,6 +384,7 @@ SYM_FUNC_START(_restore_lasx_upper) > lasx_restore_all_upper a0 t0 t1 > jr ra > SYM_FUNC_END(_restore_lasx_upper) > +EXPORT_SYMBOL(_restore_lasx_upper) Why the added export? It doesn't seem necessary, given the previous patch doesn't have a similar export added for _restore_lsx_upper. (Or if it's truly needed it should probably become EXPORT_SYMBOL_GPL.) -- WANG "xen0n" Xuerui Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/