Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17348725rwd; Tue, 27 Jun 2023 01:32:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7/ocOSzDxEWpUeNIRVTdgSkDWV4hF4B1Yd85YTObVahiNJ2SGV85/kZ17fsB6NX5A/dRLD X-Received: by 2002:a2e:3508:0:b0:2b4:5b9c:a019 with SMTP id z8-20020a2e3508000000b002b45b9ca019mr19108248ljz.8.1687854749265; Tue, 27 Jun 2023 01:32:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687854749; cv=none; d=google.com; s=arc-20160816; b=mwZyLUqulgwNvonf3R+RfRx7mmYFYLvnzQS8SG7azKlpdaVjrtV0r529O6XnV05CtP RZ9nvxIexS5QV+K3hcESqFl6IgPeQKtS/RwQ2SeV0j2EvldZbr3jvuPKfOq/0zhSoTbx W9JH5Dx27zqExRcc6kdwZ6bs5pK8m9KpN1hxBuqxczd3mEkB94N/q+3P+1pwo0WVdB17 J/Ek18+x9xdgq7p0NhUC5IR+y5siRfW2WWDISWCcbmWlbjrYj6e0Fm9SdOsHjGQIZ/G3 5N7JiPOubMhDk/oV844tVsqRveB3tVLOIiWCPh9wrCO6C2qsfO+RNRgp6Xr5SQVNrjfr tUCg== 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 :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=txwQFNrfao6fCbap4SYDrehoIq2Q7yksmmP7bRwh6XA=; fh=odeLnhe8hBuFsozpCnx+oDA+9nOv5DMM061BzlZAQDc=; b=TKd06BdBjlchKK9hlJn8RpEF/1OABgz765Q7jlyrJLgOXv/QtTc/GelRCcusDukepv mynLDkW6vhbyWGAKAA7ZbW1PVoBeTD1yF5RxGLZmwV9putM01DRlvYsMou9BE6IiSi7Y N9Oyx3voR3IogFgV2yGpyaiuVrDhuqeaJy8EAnlr288V3AC16ZNrKz2pMoomhwuM+pqr HwqVeX5FM/Ma+1tfoQwm3hJJu8c0sdKEGhsDOON6WyJGq60TlohLPkNgdwGeFxQEsJeg YA3NRILPokbfL4m6dpFGZ+GrwniTTZakdeyIHKRs6/Dm1THqV1v3qV0VDstWw8HBGy5+ sMkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=xoWamd7V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g20-20020a50ee14000000b0051dab455837si571843eds.310.2023.06.27.01.32.03; Tue, 27 Jun 2023 01:32:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=xoWamd7V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231552AbjF0IUH (ORCPT + 99 others); Tue, 27 Jun 2023 04:20:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230054AbjF0IUE (ORCPT ); Tue, 27 Jun 2023 04:20:04 -0400 Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 108EDE5; Tue, 27 Jun 2023 01:20:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1687853998; bh=FNm89gkdhid/F9i0RK3rbfD/L/HwpUHHCTG+95nssus=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=xoWamd7VJHJpaAmhRrr9sJ9Ih38xFEyD6qLt6k/qDNKZOVjq1NqVRIKh07ClO53M9 kaBZux4vXrf3vFscj2Oa33lclnuqe6k4TRkqNXF1WgHj2roXq5gPmfQx1bCO381a/Y bE+/Tg3JgyUQoRqUGPibLrrFr5mDYAGoy26Tzibw= Received: from [100.100.34.13] (unknown [220.248.53.61]) (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 017D96011B; Tue, 27 Jun 2023 16:19:57 +0800 (CST) Message-ID: <18bc1f6b-5299-2628-82b7-55f3848e856a@xen0n.name> Date: Tue, 27 Jun 2023 16:19:56 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v15 05/30] LoongArch: KVM: Add vcpu related header files 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 , tangyouling@loongson.cn References: <20230626084752.1138621-1-zhaotianrui@loongson.cn> <20230626084752.1138621-6-zhaotianrui@loongson.cn> Content-Language: en-US From: WANG Xuerui In-Reply-To: <20230626084752.1138621-6-zhaotianrui@loongson.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/6/26 16:47, Tianrui Zhao wrote: > Add LoongArch vcpu related header files, including vcpu csr > information, irq number defines, and some vcpu interfaces. > > Reviewed-by: Bibo Mao > Signed-off-by: Tianrui Zhao > --- > arch/loongarch/include/asm/insn-def.h | 55 ++++++ > arch/loongarch/include/asm/kvm_csr.h | 231 +++++++++++++++++++++++++ > arch/loongarch/include/asm/kvm_vcpu.h | 97 +++++++++++ > arch/loongarch/include/asm/loongarch.h | 20 ++- > arch/loongarch/kvm/trace.h | 168 ++++++++++++++++++ > 5 files changed, 566 insertions(+), 5 deletions(-) > create mode 100644 arch/loongarch/include/asm/insn-def.h > create mode 100644 arch/loongarch/include/asm/kvm_csr.h > create mode 100644 arch/loongarch/include/asm/kvm_vcpu.h > create mode 100644 arch/loongarch/kvm/trace.h > > diff --git a/arch/loongarch/include/asm/insn-def.h b/arch/loongarch/include/asm/insn-def.h > new file mode 100644 > index 000000000000..e285ee108fb0 > --- /dev/null > +++ b/arch/loongarch/include/asm/insn-def.h > @@ -0,0 +1,55 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#ifndef __ASM_INSN_DEF_H > +#define __ASM_INSN_DEF_H > + > +#include > +#include > +#include > + > +#define INSN_STR(x) __stringify(x) > +#define CSR_RD_SHIFT 0 > +#define CSR_RJ_SHIFT 5 > +#define CSR_SIMM14_SHIFT 10 > +#define CSR_OPCODE_SHIFT 24 > + > +#define DEFINE_INSN_CSR \ > + __DEFINE_ASM_GPR_NUMS \ > +" .macro insn_csr, opcode, rj, rd, simm14\n" \ > +" .4byte ((\\opcode << " INSN_STR(CSR_OPCODE_SHIFT) ") |" \ > +" (.L__gpr_num_\\rj << " INSN_STR(CSR_RJ_SHIFT) ") |" \ > +" (.L__gpr_num_\\rd << " INSN_STR(CSR_RD_SHIFT) ") |" \ > +" (\\simm14 << " INSN_STR(CSR_SIMM14_SHIFT) "))\n" \ > +" .endm\n" > + > +#define UNDEFINE_INSN_CSR \ > +" .purgem insn_csr\n" > + > +#define __INSN_CSR(opcode, rj, rd, simm14) \ > + DEFINE_INSN_CSR \ > + "insn_csr " opcode ", " rj ", " rd ", " simm14 "\n" \ > + UNDEFINE_INSN_CSR > + > + > +#define INSN_CSR(opcode, rj, rd, simm14) \ > + __INSN_CSR(LARCH_##opcode, LARCH_##rj, LARCH_##rd, \ > + LARCH_##simm14) > + > +#define __ASM_STR(x) #x > +#define LARCH_OPCODE(v) __ASM_STR(v) > +#define LARCH_SIMM14(v) __ASM_STR(v) > +#define __LARCH_REG(v) __ASM_STR(v) > +#define LARCH___RD(v) __LARCH_REG(v) > +#define LARCH___RJ(v) __LARCH_REG(v) > +#define LARCH_OPCODE_GCSR LARCH_OPCODE(5) > + > +#define GCSR_read(csr, rd) \ > + INSN_CSR(OPCODE_GCSR, __RJ(zero), __RD(rd), SIMM14(csr)) > + > +#define GCSR_write(csr, rd) \ > + INSN_CSR(OPCODE_GCSR, __RJ($r1), __RD(rd), SIMM14(csr)) > + > +#define GCSR_xchg(csr, rj, rd) \ > + INSN_CSR(OPCODE_GCSR, __RJ(rj), __RD(rd), SIMM14(csr)) > + > +#endif /* __ASM_INSN_DEF_H */ I still find this unnecessarily complex. First of all this is reinventing infra that's already available as the "parse_r" helper (check out include/asm/tlb.h in v6.4), but the only usage of the helper has just been removed, so it's probably a signal saying this practice may not last for long -- people are no longer in a situation like back in the MIPS era when toolchain support are not guaranteed (or even allowed upstream). Secondly, while support for older compilers is nice-to-have, but users of upstream kernels also already effectively depend on very recent toolchains (if not bleeding-edge). So we can just probe for support and just use proper mnemonics and automatically get support soon, because we can expect most of them to pick up upstream changes very quickly. That's to say, if we have something like: # arch/loongarch/Kconfig config LOONGARCH # ... select HAVE_KVM if AS_HAS_LVZ_EXTENSION config AS_HAS_LVZ_EXTENSION def_bool $(as-instr,gcsrrd \$t0$(comma)\$t1$(comma)123) Then support is guaranteed for all KVM code and this cruft can go away, and then the feature will likely be available in a few months. FYI, support for LSX and LASX instructions are already posted by your fellow toolchain folks [1], so it's 100% doable for them to add support despite the manuals not being available yet. Just coordinate with them a bit... [1]: https://sourceware.org/pipermail/binutils/2023-June/127990.html -- WANG "xen0n" Xuerui Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/