Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp322062rdf; Tue, 21 Nov 2023 03:57:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVS8sw7B95rsKL8bCEZej4Xlg0YIejtSnAE+8pxM9W91bwEQQg0FrnJV/axaZ8SqRl14Ac X-Received: by 2002:a17:902:ea8c:b0:1cc:688e:5b24 with SMTP id x12-20020a170902ea8c00b001cc688e5b24mr7906160plb.39.1700567866098; Tue, 21 Nov 2023 03:57:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700567866; cv=none; d=google.com; s=arc-20160816; b=sy6pRmzvt5jDUb9wSY9bJ2B4z8QCjdDOzefl4YlpyHsbV7yrJst1YqA6CAtzexoARS lbA/WBQm9IcXMKzagQ1mFw0hsLXp3YK69nQ054IT9VPYEcdO6b8sZQcEoN891h9qB1fP 91AFIzGi6e524XFn66JEDpuVx+IOorcD14vp1PPgMr07PhjePwtFwCW/t5qUaneB8iEO 01KGUGGQD2sJTK2kj/gIQTQjNpL7RtLVDXqgDNpqECZqp2c4nKjzmCDKzW4yEF74LIGD 83UuVyltWWXRXS4QZeRKwS7MAsqOgjmcasbvsJ8l2kFIVKMfJS7EXR3rOnUvRCp3pNkf 0rdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=oET+FrhZJu50+9YF0KI1J1qQdG/kPsJlUp7UNchOOrE=; fh=Gt3HzafkaiiQsicPvMTehvCS3aQ3AcfHDceC7RNW5g0=; b=FNkUoNaqxxooFmAfAMjAiVauxMLWrpzIF6obFyGHFLBnG3mqD+nwYSxfIJfex0G1vv 24rbTkjPoAwQyJ7M50KeVUISjyxRteAGIWbjkoZO72rAcgZmn3hyiOqEhfpGTqACen65 AdJJuOFk2xUNAV4EW0kR7Kg/RdT+wx5rDPOUwinSwjXlNiGUnmGewiuqJ+UGue/3R74Y DSjYTBP25KHtVLy1rJXAB6c55vuHsls/sPrIqBsYYBGVqwwm7KirGakDWV1PK988OAA6 rlEvVQ9SMGQlrjXRnUvbN0feEniN/yTP1aSw4ZSX8S9pvEdeNceTVjGylGVA4DOaBiRy teKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Rym6yS6I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id ja1-20020a170902efc100b001c9b5d2c406si9874906plb.403.2023.11.21.03.57.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 03:57:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Rym6yS6I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 3A9B680ACCD5; Tue, 21 Nov 2023 03:56:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234198AbjKULz4 (ORCPT + 99 others); Tue, 21 Nov 2023 06:55:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234357AbjKULzh (ORCPT ); Tue, 21 Nov 2023 06:55:37 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 534AC137 for ; Tue, 21 Nov 2023 03:55:33 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0931C433C7; Tue, 21 Nov 2023 11:55:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700567733; bh=NbNT5zN14ASPakIUDj5Dgbng3gBVPQPgEtJ+oGscF5w=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Rym6yS6I+UjdTyS9eiu/es8/cT3FGCS9H1ybruTpI9QxIJSRo4oHhOzYDRLNzCvRj 51lFp4qq9YZalaUsTtA6TQkChUp4S8+DZrSHB0cdP2NeJb7xtWrBT9s6/kEBXf6+rO /m/w/wDBJTMjHHQC+/3oyDoNNYH8cgEtSEXzpB2+XO5CSCBN2RyxyM4YJu+I0WIJRr 4djjaXiXj42VKlFIxXKNCASWTXrKdqOsj3KSi7i2eiMzKR/BX/aJtyoTJcCQFCppe0 rC2dIM19J8QKfbY67yfatQAdiW2qfDdzBLBIgpq48yps6j/7cFXbtukmKY8KpU8D47 INIY/YU6pWvpQ== Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-53e2308198eso7742666a12.1; Tue, 21 Nov 2023 03:55:32 -0800 (PST) X-Gm-Message-State: AOJu0YwlAjza2Nf3Fmkbs1VoMu8ND/eGvDS9Dk1xu/Hu05L0v8meaZe2 NcZk0y1OMhOs0T7gOlwD8DIiDFdvrMVGemxibkE= X-Received: by 2002:aa7:da0d:0:b0:548:d29d:a4ca with SMTP id r13-20020aa7da0d000000b00548d29da4camr1495144eds.42.1700567731470; Tue, 21 Nov 2023 03:55:31 -0800 (PST) MIME-Version: 1.0 References: <20231115091921.85516-1-zhaotianrui@loongson.cn> <20231115091921.85516-3-zhaotianrui@loongson.cn> <6d9395b5-e8f1-3990-adb0-a52d03411fc6@loongson.cn> In-Reply-To: <6d9395b5-e8f1-3990-adb0-a52d03411fc6@loongson.cn> From: Huacai Chen Date: Tue, 21 Nov 2023 19:55:19 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v1 2/2] LoongArch: KVM: Add lasx support To: zhaotianrui Cc: WANG Xuerui , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Greg Kroah-Hartman , loongarch@lists.linux.dev, Jens Axboe , Mark Brown , Alex Deucher , Oliver Upton , maobibo@loongson.cn, Xi Ruoyao Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 21 Nov 2023 03:56:15 -0800 (PST) On Tue, Nov 21, 2023 at 5:59=E2=80=AFPM zhaotianrui wrote: > > > =E5=9C=A8 2023/11/16 =E4=B8=8B=E5=8D=883:19, WANG Xuerui =E5=86=99=E9=81= =93: > > 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.) > It is needed to be exported, as it is called by kvm_own_lasx. However > the "_restore_lsx_upper" is not used in kvm. To keep consistency it is better to export both. Huacai > > Thanks > Tianrui Zhao >