Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4222749rwd; Tue, 23 May 2023 05:08:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5f72Jck+7JYjXk3smrAjptEMQIJ8HxKsMRLj/PFVQ87KmkF+iBkDvWFni4/VQuMaJMPvMV X-Received: by 2002:a17:903:481:b0:1af:9b8a:9c7b with SMTP id jj1-20020a170903048100b001af9b8a9c7bmr9149754plb.47.1684843697834; Tue, 23 May 2023 05:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684843697; cv=none; d=google.com; s=arc-20160816; b=RhxWC6PEXBF+vDykgHYZqJwMVzSwteLgbdEkZ2sylX/zbC2rSMcnqYDW/sECk2dt1Y e5s/orzdajYGNsbF3iAztHd8o0bwIG4LTaJZMWWvvUKCFRkPSr9SOPvLBbJmM6nh4BXY CpMyauLvkxrN7jvRpD/XuWE9vQYZ8wLvujw+H1IS1PWwsOXTXqCu/KF7sZCbF8SWy0qP 4xtOboiuFILX8igtvnXwteO/Tib3Ex/kqkqY3cmC2jWHUX/820KChUyl9uNRc6xJMKK0 35E2NktF5V3FvH7OBebzJdgXuu6ylJJoIzmhw9i3i5/mBzMuB8tL/bzbFHc8Jcbuixaa fZ3A== 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; bh=8Dn+sqyN7vlSZAeiPgXb1RUTPWCcrTO4B9umX+x9SPs=; b=nmQu28L6P8eek8ffV10c4xikygnRz/LblKI9ntulQj76XboTmyj9M1wa2c2JNIsNN8 UbDfHVgw4qZQynBKXkFcqsFyTKWEdP32roT6eUMOby0fA/E+u+s8Po8iBBvr2ZwJ2Z4O w9cC1lkcKPyBx+/8cEASynET2qlQO2j82s0psg2mM7jpZwMHJ+T5jFhQ0N3YeB1cpG3c lEspoqVvfoX+v//V2GXicKbDvt7duINRRVaLNbTsQj7w+eYSkHT7ltAkHehljSr9ht6m euf9GjmQGBaO/b6JdiYEUT3t28L/G9NnB/YisrXkctRuDbPIZTfKXIF/beED3uNNe7SG eWlQ== ARC-Authentication-Results: i=1; mx.google.com; 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 l16-20020a170903245000b001aaec5cffb2si3140690pls.280.2023.05.23.05.08.02; Tue, 23 May 2023 05:08:17 -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; 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 S236671AbjEWL5d (ORCPT + 99 others); Tue, 23 May 2023 07:57:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229893AbjEWL53 (ORCPT ); Tue, 23 May 2023 07:57:29 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3A60E11F; Tue, 23 May 2023 04:57:23 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.170]) by gateway (Coremail) with SMTP id _____8CxZ_Ehqmxk6w4AAA--.223S3; Tue, 23 May 2023 19:57:21 +0800 (CST) Received: from [10.20.42.170] (unknown [10.20.42.170]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxMuUgqmxkoFFwAA--.55963S3; Tue, 23 May 2023 19:57:20 +0800 (CST) Message-ID: <94b7f3d6-e2e1-be0a-cd39-dd1b1f1f607e@loongson.cn> Date: Tue, 23 May 2023 19:57:20 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v10 00/30] Add KVM LoongArch support Content-Language: en-US To: WANG Xuerui , Paolo Bonzini , Huacai Chen Cc: Greg Kroah-Hartman , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Jens Axboe , Mark Brown , Alex Deucher , Oliver Upton , Xi Ruoyao , Tianrui Zhao References: <20230515021522.2445551-1-zhaotianrui@loongson.cn> <02f07d8e-e1c2-2ec0-59c3-f5b4ef0463dc@loongson.cn> <4529ee5b-364a-7819-c727-71cf94057b8b@xen0n.name> <99371487-717a-64d6-1c3d-aaeaee6f20db@loongson.cn> <90b2fc60-af26-4ba6-f775-7db2514a62f4@xen0n.name> <1218d3f9-4955-7176-afbd-a0dfa0bd7565@loongson.cn> <29a9c6b4-96b8-3fb5-9b7a-2f9dba97e06f@xen0n.name> From: maobibo In-Reply-To: <29a9c6b4-96b8-3fb5-9b7a-2f9dba97e06f@xen0n.name> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8CxMuUgqmxkoFFwAA--.55963S3 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjvJXoWxZF15KFWxXry5Ww47Kw45ZFb_yoW5Cr1fpr 1kGr15Ary5Wr1kJr17Xr18Xry3Jw1UK3WDJr1DGFy5tF4UJr10qr4UXr1Y9rnrJr48Jr15 Jr1Utw13ur17Jr7anT9S1TB71UUUUjDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bqxYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l n4kS14v26r126r1DM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6x ACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r126r1DMcIj6I8E 87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lc7I2V7IY0V AS07AlzVAYIcxG8wCY1x0262kKe7AKxVWUAVWUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCF s4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUAVWUtwC20s026c02F40E14v26r1j6r18MI 8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41l IxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIx AIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2 jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8Dl1DUUUUU== X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 在 2023/5/23 18:27, WANG Xuerui 写道: > On 2023/5/23 10:54, maobibo wrote: >> >> [snip] >> >> I hate parse_r helper also, it is hard to understand, the kernel about >> LoongArch has the same issue. How about using a fixed register like this? >> >> /* GCSR */ >> static __always_inline u64 gcsr_read(u32 reg) >> { >>     u64 val = 0; >> >>     BUILD_BUG_ON(!__builtin_constant_p(reg)); >>     /* Instructions will be available in binutils later */ >>     asm volatile ( >>         "parse_r __reg, %[val]\n\t" > > Isn't this still parse_r-ing things? ;-) > >>         /* >>          * read val from guest csr register %[reg] >>          * gcsrrd %[val], %[reg] >>          */ >>         ".word 0x5 << 24 | %[reg] << 10 | 0 << 5 | __reg\n\t" >>         : [val] "+r" (val) >>         : [reg] "i" (reg) >>         : "memory"); >> >>     return val; >> } >> >> /* GCSR */ >> static __always_inline u64 gcsr_read(u32 reg) >> { >>          register unsigned long val asm("t0"); > > I got what you're trying to accomplish here. At which point you may just refer to how glibc implements its inline syscall templates and hardcode both the input and output arguments, then simply hard-code the whole instruction word. If others don't have opinions about doing things this way, I wouldn't either. > > (CSR operations are not expected to become performance-sensitive in any case, so you may freely choose registers here, and t0 for output seems okay. I'd recommend stuffing "reg" to a temporary value bound to a0 though.) a0 is ok for me. riscv has better method than both parse_r helper and using tmp register as follows, maybe we can use the similiar method. .macro insn_r, opcode, func3, func7, rd, rs1, rs2 .4byte ((\opcode << INSN_R_OPCODE_SHIFT) | \ (\func3 << INSN_R_FUNC3_SHIFT) | \ (\func7 << INSN_R_FUNC7_SHIFT) | \ (.L__gpr_num_\rd << INSN_R_RD_SHIFT) | \ (.L__gpr_num_\rs1 << INSN_R_RS1_SHIFT) | \ (.L__gpr_num_\rs2 << INSN_R_RS2_SHIFT)) .endm #define HINVAL_VVMA(vaddr, asid) \ INSN_R(OPCODE_SYSTEM, FUNC3(0), FUNC7(19), \ __RD(0), RS1(vaddr), RS2(asid)) asm volatile(HINVAL_VVMA(%0, %1) : : "r" (pos), "r" (asid) : "memory"); Regards Bibo, Mao > >> >>          BUILD_BUG_ON(!__builtin_constant_p(reg)); >>          /* Instructions will be available in binutils later */ >>          asm volatile ( >>                  "parse_r __reg, %[val]\n\t" >>                  /* >>                   * read val from guest csr register %[reg] >>                   * gcsrrd %[val], %[reg] >>                   */ >>                  ".word 0x5 << 24 | %[reg] << 10 | 0 << 5 | 12 \n\t" >>                  : : [reg] "i" (reg) >>                  : "memory", "t0"); >> >>          return val; >> } >