Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2447260rdb; Sun, 3 Dec 2023 18:06:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IGr305h54N5ee/jB+XQaYj2wSoRGXaTe4a7dO2HwMNK5l0UIoGtqJT9LAQwj6NY77upQBgK X-Received: by 2002:a17:902:bd01:b0:1d0:b1f0:fdb with SMTP id p1-20020a170902bd0100b001d0b1f00fdbmr92412pls.46.1701655592606; Sun, 03 Dec 2023 18:06:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701655592; cv=none; d=google.com; s=arc-20160816; b=LyOxzWn97xXKn9HtSRL4yPeMcdPiJuh6jH0nmAIlTDViM7RPaLOa7PJX1wp7wHe0rd sdIwoBh2V9n9rDx3/HWBLI73cWL6JkuwhoiA5sx7jrGdhULokNiA3UsbDL6DK5gyaOm0 slxlpbbQ7wt6JgiiAYQqIiKGh3ETmYKnlXuL8+MrK5DzY/o0RTIWdoMhhlmWkECOYqQP oOkRyLdILRIRa3EB34gYkxBq5qn6BnHqs4OhhfBd4bNNK1PZgPkmG9FGIrnL2Y7r++W/ Bm5/6BnyCXNHdlx+KEIXY2pctRvGebe3C8t/Vtufxt7BDq0nib5ebBVlExmMyZNGCX/t XMJA== 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=WJlcp8rdg8bcaqc8Pkr7P9bTkEdeTpMKVambwqiLv3Y=; fh=c/TFKcqWybZIdh7j8vRV/vOfC7gwk6VtKb8tnRXtAJI=; b=egUDM4SjmTE+ZxmNWeYU0MgpyUgOaoo6Z0d4/muPrlWOCrHdlND4/PH+r15SdH9HGh J1naHoibQHBJxxfQz0xxDtwzsIX28P5HFn+ve2yYHk39ogLGzHFyhDifmlAJ92PUnW7a 6ClkXJdU8JXKUjAIjKWvx4fUVfZjJVQsq4GPxZ2mVrZl0x35pUy9Tl4ZSWp93BTKR4ak BUW3Cgut2134TkZQ0Ffy8jHMDUntZyAsf4fOKKZLy9MAg3Yq/0e/C0u0j6Y0BgMjTh2G tN7bHH+pfhHHkRAHqtRfYO9gvGJP8jtVfrREIVvyH0urnlEqxELU3DGecOWL6KvTw8Tm 0FYg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id b2-20020a170903228200b001d09711b7a6si1185958plh.149.2023.12.03.18.06.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 18:06:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 55DFA807C85B; Sun, 3 Dec 2023 18:06:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234260AbjLDCFw (ORCPT + 99 others); Sun, 3 Dec 2023 21:05:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229869AbjLDCFv (ORCPT ); Sun, 3 Dec 2023 21:05:51 -0500 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 584F0A6; Sun, 3 Dec 2023 18:05:56 -0800 (PST) Received: from loongson.cn (unknown [10.20.42.173]) by gateway (Coremail) with SMTP id _____8Cxc_D_M21l9aE+AA--.59169S3; Mon, 04 Dec 2023 10:05:52 +0800 (CST) Received: from [10.20.42.173] (unknown [10.20.42.173]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxiuT_M21lashTAA--.55524S3; Mon, 04 Dec 2023 10:05:51 +0800 (CST) Subject: Re: [PATCH v5 3/4] KVM: selftests: Add ucall test support for LoongArch To: Tianrui Zhao , Shuah Khan , Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Sean Christopherson Cc: Vishal Annapurve , Huacai Chen , WANG Xuerui , loongarch@lists.linux.dev, Peter Xu , Vipin Sharma References: <20231130111804.2227570-1-zhaotianrui@loongson.cn> <20231130111804.2227570-4-zhaotianrui@loongson.cn> From: maobibo Message-ID: Date: Mon, 4 Dec 2023 10:05:45 +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-4-zhaotianrui@loongson.cn> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8DxiuT_M21lashTAA--.55524S3 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxAryfKF45Zr4UXF45Jr45CFX_yoW5Cw4Dpa 4rA3WrKr4xKF17A3s3Jw1qq3Z3Grs2kF1xZ342qrWF9w42y3WxJr1xKFyjyFyxtr4ktFs5 ZFn2ganruF1Ut3cCm3ZEXasCq-sJn29KB7ZKAUJUUUU7529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUP2b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4j6r4UJwAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0c Ia020Ex4CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jw0_ WrylYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvEwIxGrw CYjI0SjxkI62AI1cAE67vIY487MxkF7I0En4kS14v26r126r1DMxAIw28IcxkI7VAKI48J MxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y6r17MI8I3I0E5I8CrVAFwI 0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y 0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r4j6ryUMIIF0xvE2Ix0cI8IcVCY1x0267AKxV W8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1l IxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU0epB3UUUU U== X-Spam-Status: No, score=-2.6 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 fry.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 (fry.vger.email [0.0.0.0]); Sun, 03 Dec 2023 18:06:08 -0800 (PST) On 2023/11/30 下午7:18, Tianrui Zhao wrote: > Add ucall test support for LoongArch. A ucall is a "hypercall to > userspace". > > Signed-off-by: Tianrui Zhao > --- > .../selftests/kvm/include/loongarch/ucall.h | 28 ++++++++++++++ > .../selftests/kvm/lib/loongarch/ucall.c | 38 +++++++++++++++++++ > 2 files changed, 66 insertions(+) > create mode 100644 tools/testing/selftests/kvm/include/loongarch/ucall.h > create mode 100644 tools/testing/selftests/kvm/lib/loongarch/ucall.c > > diff --git a/tools/testing/selftests/kvm/include/loongarch/ucall.h b/tools/testing/selftests/kvm/include/loongarch/ucall.h > new file mode 100644 > index 00000000000..e9033ea6fbf > --- /dev/null > +++ b/tools/testing/selftests/kvm/include/loongarch/ucall.h > @@ -0,0 +1,28 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +#ifndef SELFTEST_KVM_UCALL_H > +#define SELFTEST_KVM_UCALL_H > + > +#include "kvm_util_base.h" > + > +#define UCALL_EXIT_REASON KVM_EXIT_MMIO > + > +/* > + * Default base address for application loading is 0x120000000, > + * DEFAULT_GUEST_TEST_MEM should be larger than app loading address, > + * so that PER_VCPU_MEM_SIZE can be large enough, and kvm selftests > + * app size is smaller than 256M in generic > + */ > +#define DEFAULT_GUEST_TEST_MEM 0x130000000 > + > +/* > + * ucall_exit_mmio_addr holds per-VM values (global data is duplicated by each > + * VM), it must not be accessed from host code. > + */ > +extern vm_vaddr_t *ucall_exit_mmio_addr; > + > +static inline void ucall_arch_do_ucall(vm_vaddr_t uc) > +{ > + WRITE_ONCE(*ucall_exit_mmio_addr, uc); > +} > + > +#endif > diff --git a/tools/testing/selftests/kvm/lib/loongarch/ucall.c b/tools/testing/selftests/kvm/lib/loongarch/ucall.c > new file mode 100644 > index 00000000000..fc6cbb50573 > --- /dev/null > +++ b/tools/testing/selftests/kvm/lib/loongarch/ucall.c > @@ -0,0 +1,38 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * ucall support. A ucall is a "hypercall to userspace". > + * > + */ > +#include "kvm_util.h" > + > +/* > + * ucall_exit_mmio_addr holds per-VM values (global data is duplicated by each > + * VM), it must not be accessed from host code. > + */ > +vm_vaddr_t *ucall_exit_mmio_addr; > + > +void ucall_arch_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa) > +{ > + vm_vaddr_t mmio_gva = vm_vaddr_unused_gap(vm, vm->page_size, KVM_UTIL_MIN_VADDR); > + > + virt_map(vm, mmio_gva, mmio_gpa, 1); > + > + vm->ucall_mmio_addr = mmio_gpa; > + > + write_guest_global(vm, ucall_exit_mmio_addr, (vm_vaddr_t *)mmio_gva); > +} > + > +void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu) > +{ > + struct kvm_run *run = vcpu->run; > + > + if (run->exit_reason == KVM_EXIT_MMIO && > + run->mmio.phys_addr == vcpu->vm->ucall_mmio_addr) { > + TEST_ASSERT(run->mmio.is_write && run->mmio.len == sizeof(uint64_t), > + "Unexpected ucall exit mmio address access"); > + > + return (void *)(*((uint64_t *)run->mmio.data)); > + } > + > + return NULL; > +} > Reviewed-by: Bibo Mao