Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5132598rdb; Tue, 12 Dec 2023 22:40:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVQ5CIvDJh2ZD51XRt/MFlcxStvLkASFWL2UAElDLbdpJ+hA8OJT1AfM0Et2ip9bQUEuyA X-Received: by 2002:a05:6808:1998:b0:3b9:de63:f514 with SMTP id bj24-20020a056808199800b003b9de63f514mr9582280oib.12.1702449653122; Tue, 12 Dec 2023 22:40:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702449653; cv=none; d=google.com; s=arc-20160816; b=mLnMDfDUbc20SKUEnjQvJTXD45mt4vs1n5VZPLN4V8AXjj8JfcBf6525x57l7lSHIM xXtX4X6kyrijUkFtwz+rT8cwazg7eKl5OLzirbwQGmQatTObHYCSU1d0R5W8mQafrEpg H/FFVBUC4mXNXo+Uuyi6owC528LCoFbs99B9z/ew/B0UOsRveVoaeTpX7UfBE/Yf4VyF hOJ76YPVQkEQ0Ln6oPBHNjee4n2lCNQPHUB8mMKb6XIJP2AsmUQpVHRALppgqOHZ1PSl nKzlBpY1el5s3WvIEED30Zb++Wzl/QToowvTKS/J/X75krV6s8fUhMM+LdKAJG9Ogvil 1phg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=PAKIQX+TbuhMmrOj6Au3NfLnOyRgBm6xKwlYA0NLEAY=; fh=f6ooZv6UjLKGOCu2LJy27xByoBqvGep417I4c5GOaYE=; b=ZWseNTDFHXmnL4rphw+hkoaQHr3vJHenNnttsMC0kmPYLT5LvkE9OHocVwi602iK79 mQFl6SzpLOpTe1FaBgEqJu8HhMdzw4zwHPp15iCHXTckY8acErAornbWW+M3oARM3nts 1mS1do8qO3gdQRdN1Q3ZRDQH/NaATPuGSEYkTCdtDsOGqylORn90DheJY+na7enCD+9x PlQE42Ka8/atkqP3A1MW5LSWwHZqvkRl302E4SXmCd6bXdUuXB+y1IOpIw3a0O0tCwWk 0R29V/LYTBUDHtatApJ8jrvlMbc4v1XUu5Jd+QxOne3/W5VU4T6mLmJQKRVEgbPfg5QU dRsg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id a11-20020a65640b000000b0056949ba3f3fsi9078655pgv.253.2023.12.12.22.40.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 22:40:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 6059E8044373; Tue, 12 Dec 2023 22:40:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378619AbjLMGkd (ORCPT + 99 others); Wed, 13 Dec 2023 01:40:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378624AbjLMGkc (ORCPT ); Wed, 13 Dec 2023 01:40:32 -0500 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0DACAAD; Tue, 12 Dec 2023 22:40:37 -0800 (PST) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxZfDjUXll_pUAAA--.3703S3; Wed, 13 Dec 2023 14:40:35 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxvnPhUXllJvMBAA--.12195S2; Wed, 13 Dec 2023 14:40:33 +0800 (CST) From: Tianrui Zhao To: Paolo Bonzini , Huacai Chen , maobibo@loongson.cn, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: WANG Xuerui , Greg Kroah-Hartman , loongarch@lists.linux.dev, Jens Axboe , Mark Brown , Alex Deucher , Oliver Upton , Xi Ruoyao , zhaotianrui@loongson.cn Subject: [PATCH v4 0/2] LoongArch: KVM: Add LSX,LASX support Date: Wed, 13 Dec 2023 14:27:38 +0800 Message-Id: <20231213062740.4175002-1-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8DxvnPhUXllJvMBAA--.12195S2 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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 groat.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 (groat.vger.email [0.0.0.0]); Tue, 12 Dec 2023 22:40:50 -0800 (PST) This patch series add LSX,LASX support for LoongArch KVM. There will be LSX,LASX exception in KVM when guest use the LSX,LASX instructions. KVM will enable LSX,LASX and restore the vector registers for guest then return to guest to continue running. Changes for v4: 1. Supplement vcpu features checking when cpucfg2 is passed from user space. (1) The LLFTP must be set, as guest must has a constant timer. (2) Single and double float point must both be set when enable FP. (3) FP should be set when enable LSX. (4) LSX,FP should be set when enable LASX. Changes for v3: 1. Use KVM_GET_DEVICE_ATTR interface to return CPUCFG2 features which are supported by KVM to user space. 2. Remove version checking in kvm_check_cpucfg. Changes for v2: 1. Add interface to return CPUCFG2 features which have been supported by current KVM to user space. So that user space can get CPU features such as FPU,LSX,LASX whether support by KVM. 2. Add CPUCFG2 checking interface to check that if the value which is passed from user space has any errors. 3. Export both _restore_lsx_upper and _restore_lasx_upper to keep consistency. 4. Use "jr ra" instruction to repalce "jirl zero, ra, 0". Changes for v1: 1. Add LSX support for LoongArch KVM. 2. Add LASX support for LoongArch KVM. Tianrui Zhao (2): LoongArch: KVM: Add LSX support LoongArch: KVM: Add LASX support arch/loongarch/include/asm/kvm_host.h | 17 ++ arch/loongarch/include/asm/kvm_vcpu.h | 22 +++ arch/loongarch/include/uapi/asm/kvm.h | 1 + arch/loongarch/kernel/fpu.S | 2 + arch/loongarch/kvm/exit.c | 37 ++++ arch/loongarch/kvm/switch.S | 36 ++++ arch/loongarch/kvm/trace.h | 6 +- arch/loongarch/kvm/vcpu.c | 271 +++++++++++++++++++++++++- 8 files changed, 386 insertions(+), 6 deletions(-) -- 2.39.1