Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4388286rdb; Mon, 11 Dec 2023 19:06:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpgfZeOUfd3B/B5cNsNUxgDaV99cZ2QjBuKU60Q0IaPvRJofVDv/DgCwqUk9EJy7TrjI99 X-Received: by 2002:a05:6870:2803:b0:1fb:14a3:c642 with SMTP id gz3-20020a056870280300b001fb14a3c642mr7409393oab.42.1702350396124; Mon, 11 Dec 2023 19:06:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702350396; cv=none; d=google.com; s=arc-20160816; b=KRdrcDD72PYQ4dQ1316AbRn+5Xy9HTffR7M57Vz/f3Hxb0Az91WWhIOm9Dz1gxw92j J1aQ6d2ISa4qGEcLEIdOLqxU1IyN7C1o1hmNDk4GVIjz62uxe6H13SW3PutiFOYjMwHh sPTsLsnV2w//vUDUflNBJo8wuvdptEX810FbOtO/nFqp88IAu/NXJXmay629P9pCPGpG QKVvBaqy8YEibU2ZTILCj6Yc9iLFODmu7T/kJNJPbcPxvYc1ZPgGIklVB/FnX9aoBEAn EouHkmhuPGd6QeFV70qEWXFK2zKH8CrdSNd7LjOHGV4+ZrjbsubhMDGQCLwBpvLnue9z lWXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=QOa6dusrY/vFETRYIiLegh3bXElDqNLb4qHffBF1qWU=; fh=0/ExNHxdEV0fLmSPuojjKTsHFOGKXn6GlK7HVSyZh/Y=; b=OSU4CzWsRd55UcF2QkMBi2zSIK7YT/pZHIqH/4NEgWvlBw1eBNEBoiU7n+aD4cCJqL 0YoABnxooiXgPEIWe+8V/P0C+vWa9MvHMRHmHpcanoOrvWebLKKLx4TlWN0ybhSGiA95 XK46cneUHR7vnzRHQPbLDxkcHb6QBIybA/Q1q80dyPLvZ7nA2Oq4g67b0Z40gLYBgN/o LvVJtyK5XCKwCAGN6fvpwGnDwl4nKI5jBJFR5c90Ep1J/7ALpJecaeFucDTdODiauosL Y64af/WJYiPED3zF6Q0JrBz9JJ/504ArB/m9F+cqBxccOB584WmhKKcCJfey2Q8dNH8t FKtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id j8-20020a635948000000b005c5ff4675d8si7016595pgm.734.2023.12.11.19.06.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 19:06:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 703968057982; Mon, 11 Dec 2023 19:06:33 -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 S1345713AbjLLDGU (ORCPT + 99 others); Mon, 11 Dec 2023 22:06:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229562AbjLLDGT (ORCPT ); Mon, 11 Dec 2023 22:06:19 -0500 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 02CFCB5; Mon, 11 Dec 2023 19:06:23 -0800 (PST) Received: from loongson.cn (unknown [10.20.42.183]) by gateway (Coremail) with SMTP id _____8Ax2uguzndl1zwAAA--.1533S3; Tue, 12 Dec 2023 11:06:22 +0800 (CST) Received: from [10.20.42.183] (unknown [10.20.42.183]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxXeEqzndl6BQAAA--.709S3; Tue, 12 Dec 2023 11:06:20 +0800 (CST) Subject: Re: [PATCH v5 1/4] KVM: selftests: Add KVM selftests header files for LoongArch To: Sean Christopherson Cc: Shuah Khan , Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Vishal Annapurve , Huacai Chen , WANG Xuerui , loongarch@lists.linux.dev, Peter Xu , Vipin Sharma , maobibo@loongson.cn References: <20231130111804.2227570-1-zhaotianrui@loongson.cn> <20231130111804.2227570-2-zhaotianrui@loongson.cn> From: zhaotianrui Message-ID: Date: Tue, 12 Dec 2023 11:08:41 +0800 User-Agent: Mozilla/5.0 (X11; Linux loongarch64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20231130111804.2227570-2-zhaotianrui@loongson.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID: AQAAf8CxXeEqzndl6BQAAA--.709S3 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBj93XoW3XrW3Ar4UKryxuFW8Xr1rZrc_yoWxZFy5pF WjkFy0kr48tF47K348KFn5Z3W7Gr4xAF18K347XrWj9F45X34kGr12gF45JFy5Xrs5XFyU Ar1vqw4a9rZrW3cCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUP2b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y 6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr4 1lc7I2V7IY0VAS07AlzVAYIcxG8wCY1x0262kKe7AKxVWUAVWUtwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC20s026c02F40E14 v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkG c2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4U MIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8m9aDUUUU U== X-Spam-Status: No, score=-3.3 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,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]); Mon, 11 Dec 2023 19:06:33 -0800 (PST) Hi, Sean: I want to change the definition of  DEFAULT_GUEST_TEST_MEM in the common file "memstress.h", like this: /* Default guest test virtual memory offset */ +#ifndef DEFAULT_GUEST_TEST_MEM #define DEFAULT_GUEST_TEST_MEM 0xc0000000 +#endif As this address should be re-defined in LoongArch headers. So, do you have any suggesstion? Thanks Tianrui Zhao 在 2023/11/30 下午7:18, Tianrui Zhao 写道: > Add KVM selftests header files for LoongArch, including processor.h > and kvm_util_base.h. Those mainly contain LoongArch CSR register defines > and page table information. And change DEFAULT_GUEST_TEST_MEM base addr > for LoongArch. > > Signed-off-by: Tianrui Zhao > --- > .../selftests/kvm/include/kvm_util_base.h | 5 + > .../kvm/include/loongarch/processor.h | 133 ++++++++++++++++++ > .../testing/selftests/kvm/include/memstress.h | 2 + > 3 files changed, 140 insertions(+) > create mode 100644 tools/testing/selftests/kvm/include/loongarch/processor.h > > diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h > index a18db6a7b3c..97f8b24741b 100644 > --- a/tools/testing/selftests/kvm/include/kvm_util_base.h > +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h > @@ -218,6 +218,11 @@ extern enum vm_guest_mode vm_mode_default; > #define MIN_PAGE_SHIFT 12U > #define ptes_per_page(page_size) ((page_size) / 8) > > +#elif defined(__loongarch__) > +#define VM_MODE_DEFAULT VM_MODE_P36V47_16K > +#define MIN_PAGE_SHIFT 14U > +#define ptes_per_page(page_size) ((page_size) / 8) > + > #endif > > #define MIN_PAGE_SIZE (1U << MIN_PAGE_SHIFT) > diff --git a/tools/testing/selftests/kvm/include/loongarch/processor.h b/tools/testing/selftests/kvm/include/loongarch/processor.h > new file mode 100644 > index 00000000000..cea6b284131 > --- /dev/null > +++ b/tools/testing/selftests/kvm/include/loongarch/processor.h > @@ -0,0 +1,133 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#ifndef SELFTEST_KVM_PROCESSOR_H > +#define SELFTEST_KVM_PROCESSOR_H > + > +#define _PAGE_VALID_SHIFT 0 > +#define _PAGE_DIRTY_SHIFT 1 > +#define _PAGE_PLV_SHIFT 2 /* 2~3, two bits */ > +#define _CACHE_SHIFT 4 /* 4~5, two bits */ > +#define _PAGE_PRESENT_SHIFT 7 > +#define _PAGE_WRITE_SHIFT 8 > + > +#define PLV_KERN 0 > +#define PLV_USER 3 > +#define PLV_MASK 0x3 > + > +#define _PAGE_VALID (0x1UL << _PAGE_VALID_SHIFT) > +#define _PAGE_PRESENT (0x1UL << _PAGE_PRESENT_SHIFT) > +#define _PAGE_WRITE (0x1UL << _PAGE_WRITE_SHIFT) > +#define _PAGE_DIRTY (0x1UL << _PAGE_DIRTY_SHIFT) > +#define _PAGE_USER (PLV_USER << _PAGE_PLV_SHIFT) > +#define __READABLE (_PAGE_VALID) > +#define __WRITEABLE (_PAGE_DIRTY | _PAGE_WRITE) > +#define _CACHE_CC (0x1UL << _CACHE_SHIFT) /* Coherent Cached */ > + > +/* general registers */ > +#define zero $r0 > +#define ra $r1 > +#define tp $r2 > +#define sp $r3 > +#define a0 $r4 > +#define a1 $r5 > +#define a2 $r6 > +#define a3 $r7 > +#define a4 $r8 > +#define a5 $r9 > +#define a6 $r10 > +#define a7 $r11 > +#define t0 $r12 > +#define t1 $r13 > +#define t2 $r14 > +#define t3 $r15 > +#define t4 $r16 > +#define t5 $r17 > +#define t6 $r18 > +#define t7 $r19 > +#define t8 $r20 > +#define u0 $r21 > +#define fp $r22 > +#define s0 $r23 > +#define s1 $r24 > +#define s2 $r25 > +#define s3 $r26 > +#define s4 $r27 > +#define s5 $r28 > +#define s6 $r29 > +#define s7 $r30 > +#define s8 $r31 > + > +#define PS_4K 0x0000000c > +#define PS_8K 0x0000000d > +#define PS_16K 0x0000000e > +#define PS_DEFAULT_SIZE PS_16K > + > +/* Basic CSR registers */ > +#define LOONGARCH_CSR_CRMD 0x0 /* Current mode info */ > +#define CSR_CRMD_PG_SHIFT 4 > +#define CSR_CRMD_PG (0x1UL << CSR_CRMD_PG_SHIFT) > +#define CSR_CRMD_IE_SHIFT 2 > +#define CSR_CRMD_IE (0x1UL << CSR_CRMD_IE_SHIFT) > +#define CSR_CRMD_PLV_SHIFT 0 > +#define CSR_CRMD_PLV_WIDTH 2 > +#define CSR_CRMD_PLV (0x3UL << CSR_CRMD_PLV_SHIFT) > +#define PLV_MASK 0x3 > + > +#define LOONGARCH_CSR_PRMD 0x1 > +#define LOONGARCH_CSR_EUEN 0x2 > +#define LOONGARCH_CSR_ECFG 0x4 > +#define LOONGARCH_CSR_ESTAT 0x5 /* Exception status */ > +#define LOONGARCH_CSR_ERA 0x6 /* ERA */ > +#define LOONGARCH_CSR_BADV 0x7 /* Bad virtual address */ > +#define LOONGARCH_CSR_EENTRY 0xc > +#define LOONGARCH_CSR_TLBIDX 0x10 /* TLB Index, EHINV, PageSize, NP */ > +#define CSR_TLBIDX_PS_SHIFT 24 > +#define CSR_TLBIDX_PS_WIDTH 6 > +#define CSR_TLBIDX_PS (0x3fUL << CSR_TLBIDX_PS_SHIFT) > +#define CSR_TLBIDX_SIZEM 0x3f000000 > +#define CSR_TLBIDX_SIZE CSR_TLBIDX_PS_SHIFT > + > +#define LOONGARCH_CSR_ASID 0x18 /* ASID */ > +/* Page table base address when VA[VALEN-1] = 0 */ > +#define LOONGARCH_CSR_PGDL 0x19 > +/* Page table base address when VA[VALEN-1] = 1 */ > +#define LOONGARCH_CSR_PGDH 0x1a > +/* Page table base */ > +#define LOONGARCH_CSR_PGD 0x1b > +#define LOONGARCH_CSR_PWCTL0 0x1c > +#define LOONGARCH_CSR_PWCTL1 0x1d > +#define LOONGARCH_CSR_STLBPGSIZE 0x1e > +#define LOONGARCH_CSR_CPUID 0x20 > +#define LOONGARCH_CSR_KS0 0x30 > +#define LOONGARCH_CSR_KS1 0x31 > +#define LOONGARCH_CSR_TMID 0x40 > +#define LOONGARCH_CSR_TCFG 0x41 > +#define LOONGARCH_CSR_TLBRENTRY 0x88 /* TLB refill exception entry */ > +/* KSave for TLB refill exception */ > +#define LOONGARCH_CSR_TLBRSAVE 0x8b > +#define LOONGARCH_CSR_TLBREHI 0x8e > +#define CSR_TLBREHI_PS_SHIFT 0 > +#define CSR_TLBREHI_PS (0x3fUL << CSR_TLBREHI_PS_SHIFT) > + > +#define DEFAULT_LOONARCH64_STACK_MIN 0x4000 > +#define DEFAULT_LOONARCH64_PAGE_TABLE_MIN 0x4000 > +#define EXREGS_GPRS (32) > + > +#ifndef __ASSEMBLER__ > +struct ex_regs { > + unsigned long regs[EXREGS_GPRS]; > + unsigned long pc; > + unsigned long estat; > + unsigned long badv; > +}; > + > +extern void handle_tlb_refill(void); > +extern void handle_exception(void); > +#endif > + > +#define PC_OFFSET_EXREGS ((EXREGS_GPRS + 0) * 8) > +#define ESTAT_OFFSET_EXREGS ((EXREGS_GPRS + 1) * 8) > +#define BADV_OFFSET_EXREGS ((EXREGS_GPRS + 2) * 8) > +#define EXREGS_SIZE ((EXREGS_GPRS + 3) * 8) > + > +#endif /* SELFTEST_KVM_PROCESSOR_H */ > diff --git a/tools/testing/selftests/kvm/include/memstress.h b/tools/testing/selftests/kvm/include/memstress.h > index ce4e603050e..5bcdaf2efab 100644 > --- a/tools/testing/selftests/kvm/include/memstress.h > +++ b/tools/testing/selftests/kvm/include/memstress.h > @@ -13,7 +13,9 @@ > #include "kvm_util.h" > > /* Default guest test virtual memory offset */ > +#ifndef DEFAULT_GUEST_TEST_MEM > #define DEFAULT_GUEST_TEST_MEM 0xc0000000 > +#endif > > #define DEFAULT_PER_VCPU_MEM_SIZE (1 << 30) /* 1G */ >