Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5720066rdb; Wed, 13 Dec 2023 18:21:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGDlgnEIW37DIMSg2upQtqMfMil9itEwmlRZmeaO0x7QD72upVCP9SHm74eOInWbpxYbrKn X-Received: by 2002:a05:6e02:16cf:b0:35d:59a2:332e with SMTP id 15-20020a056e0216cf00b0035d59a2332emr14313486ilx.50.1702520491262; Wed, 13 Dec 2023 18:21:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702520491; cv=none; d=google.com; s=arc-20160816; b=aOLHTwv4MSV+cOi6tiYH4DcemwGrCYgLLwfSKbZ6oNHa/lqzkzwBYoqArTaM1dhn2q 6IsjjmXVaUe1l3i4gUi2r/zcjaNeCjFPeq0mD6Gv2jxzH+ye6UzxRUBTGFrxTmIQcvGc nUByUEr+Lip81GXA079uV9iM9VZv/DLKZmRkuMAo4O/KpA71x2UVsixDdvbh2mVN1mx3 KXvIJuL0IcNJ8eyrZjhiXiyhb4ZgRb9YPDXw90FkwkT4mvDnqYkI/TeCi6rFe+O7h5A0 S7dqhvAkp94xEaqW1y8dM4XLPMpx1L3+LWKMR2iuV+ljZJSqzZSW4G8sPOoNkTLVre/g AceQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=kN/hc8qLP6JtXdImDihhSP2oFr7YXPfbmOfbtEc0pR4=; fh=tZ0ML6QeYVwHAoa30r0iEBweDWD0u+4v9JQen3S7ODM=; b=NgmxQGtC8s9ljDUtQk2RjKtt7b++ZyKj4WbmddafELRivuJAQ2qg0A80BIQCe+ZUql /ujdjVFXvFM94LgqhywKk1iflgH15oMB5gzdsXS4ZEVbM7b7D65fbtkyDD/Tx1aWVMrP 0WX81/9nVpvvSgGJ0SrzW+b1+JqxiV39Ky5NfO3ynG886h/FViP+3HVB8mrqC0FzVAkG 2CeqpiArfQSp6kR3CAS0BTT33LB3UqFfcwO9AqO/HeNkj68Nbmayy0j71ZV8igN/mAz7 AO5ui9m9y1/te8iL9Qo6BY0zJd9JjhHUszM4uR4fIHL7Y3vn6S3mwod7eLl0M4n4Yans O7ow== 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:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id l12-20020a170902d34c00b001c566ea86eesi10339625plk.177.2023.12.13.18.21.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 18:21:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 9C4C08029850; Wed, 13 Dec 2023 18:21:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234093AbjLNCVN (ORCPT + 99 others); Wed, 13 Dec 2023 21:21:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230096AbjLNCVM (ORCPT ); Wed, 13 Dec 2023 21:21:12 -0500 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0D21AE3; Wed, 13 Dec 2023 18:21:16 -0800 (PST) Received: from loongson.cn (unknown [10.20.42.173]) by gateway (Coremail) with SMTP id _____8DxBOubZnpls+QAAA--.1172S3; Thu, 14 Dec 2023 10:21:15 +0800 (CST) Received: from [10.20.42.173] (unknown [10.20.42.173]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxrnOUZnpl5XkDAA--.18609S3; Thu, 14 Dec 2023 10:21:10 +0800 (CST) Subject: Re: [PATCH v5 1/4] KVM: selftests: Add KVM selftests header files for LoongArch To: Sean Christopherson Cc: zhaotianrui , 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 , huangpei@loongson.cn References: <20231130111804.2227570-1-zhaotianrui@loongson.cn> <20231130111804.2227570-2-zhaotianrui@loongson.cn> <023b6f8f-301b-a6d0-448b-09a602ba1141@loongson.cn> <06076290-4efb-5d71-74eb-396d325447e0@loongson.cn> From: maobibo Message-ID: <4b05a834-9584-0a06-c6c8-ab191eddd5f8@loongson.cn> Date: Thu, 14 Dec 2023 10:20:57 +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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8CxrnOUZnpl5XkDAA--.18609S3 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxJw1rAw1xAF45tFyfKw13KFX_yoWrtFyfpF W0kF45Kw4kGrsFyws2qw18WF1aga93Z3WUurn8GryDCan0qr1xZr1jkw1Y9a9aqr48AayF qF4IqwnrKw15Z3gCm3ZEXasCq-sJn29KB7ZKAUJUUUU7529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0V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E autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 13 Dec 2023 18:21:28 -0800 (PST) On 2023/12/14 上午7:56, Sean Christopherson wrote: > On Wed, Dec 13, 2023, maobibo wrote: >> >> On 2023/12/13 下午3:15, zhaotianrui wrote: >>> >>> 在 2023/12/13 上午1:18, Sean Christopherson 写道: >>>> On Tue, Dec 12, 2023, zhaotianrui wrote: >>>>> 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. >>>> >>>> Why?  E.g. is 0xc0000000 unconditionally reserved, not guaranteed to >>>> be valid, >>>> something else? >>>> >>>>> So, do you have any suggesstion? >>>> >>>> Hmm, I think ideally kvm_util_base.h would define a range of memory that >>>> can be used by tests for arbitrary data.  Multiple tests use 0xc0000000, >>>> which is not entirely arbitrary, i.e. it doesn't _need_ to be 0xc0000000, >>>> but 0xc0000000 is convenient because it's 32-bit addressable and doesn't >>>> overlap reserved areas in other architectures. >> In general text entry address of user application on x86/arm64 Linux >> is 0x200000, however on LoongArch system text entry address is strange, its >> value 0x120000000. >> >> When DEFAULT_GUEST_TEST_MEM is defined as 0xc0000000, there is limitation >> for guest memory size, it cannot exceed 0x120000000 - 0xc000000 = 1.5G >> bytes, else there will be conflict. However there is no such issue on >> x86/arm64, since 0xc0000000 is above text entry address 0x200000. > > Ugh, I spent a good 30 minutes trying to figure out how any of this works on x86 > before I realized DEFAULT_GUEST_TEST_MEM is used for the guest _virtual_ address > space. > > I was thinking we were talking about guest _physical_ address, hence my comments > about it being 32-bit addressable and not overlappin reserved areas. E.g. on x86, > anything remotely resembling a real system has regular memory, a.k.a. DRAM, split > between low memory (below the 32-bit boundary, i.e. below 4GiB) and high memory > (from 4GiB to the max legal physical address). Addresses above "top of lower > usable DRAM" (TOLUD) are reserved (again, in a "real" system) for things like > PCI, local APIC, I/O APIC, and the _architecturally_ defined RESET vector. > > I couldn't figure out how x86 worked, because KVM creates an KVM-internal memslot > at address 0xfee00000. And then I realized the test creates memslots at completely > different GPAs, and DEFAULT_GUEST_TEST_MEM is used only as super arbitrary > guest virtual address. The framework and idea of kvm selftest is very good and intrinsic, and it is very easy to write unit test case for kvm -:) > > *sigh* > > Anyways... > >> The LoongArch link scripts actually is strange, it brings out some >> compatible issues such dpdk/kvm selftest when user applications >> want fixed virtual address space. > > Can you elaborate on compatiblity issues? I don't see the connection between > DPDK and KVM selftests. No, there is no the connection between DPDK and KVM selftests. I mean that some applications which use fixed VA address have the same issue, however this kind of usage is OK on X86/ARM. DPDK also uses fixed IOVA address(0xC0000000) when it is combined with IOMMU, there is the similar conflict issue on LoongArch machines. > >> So here DEFAULT_GUEST_TEST_MEM is defined as 0x130000000 separately, maybe >> 0x140000000 is better since it is 1G super-page aligned for 4K page size. > > I would strongly prefer we carve out a virtual address range that *all* tests > can safely use for test-specific code and data. E.g. if/when we add userspace > support to selftests, I like the idea of having dedicated address spaces for > kernel vs. user[*]. > > Maybe we can march in that generally direction and define test's virtual address > range to be in kernel space, i.e. the high half. I assume/hope that would play > nice with all architectures' entry points? yeap, it will solve the issue, virtual address range in kernel space can be used. Also both unprivileged and privileged instruction can be tested with ZengGuang's patch. And is this patchset eligible to merge if common file selftests/kvm/include/memstress.h is kept unchanged? Since it is pending for a period of time, also LoongArch kvm selftest can pass with guest memory size below 1.5G . We can add kernel/user mode support if ZengGuang's patch is merged. Regards Bibo Mao > > [*] https://lore.kernel.org/all/20231102155111.28821-1-guang.zeng@intel.com >