Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1657400rdb; Sun, 8 Oct 2023 19:55:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEGzT+bKYC/sGbZDHpgqdCRI0X9zseXpviPRW8TMwkSkGdJRf0BeXbX74O+p6ICxVzeOGBL X-Received: by 2002:a05:6a00:2d23:b0:690:c5cf:91f4 with SMTP id fa35-20020a056a002d2300b00690c5cf91f4mr16536593pfb.12.1696820143109; Sun, 08 Oct 2023 19:55:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696820143; cv=none; d=google.com; s=arc-20160816; b=iUGwHXskfoTjz+AwsXL7Fw5I4x4SQDfaoifYVsNMsgz+FrVA6TuoaZ8mnW3GtXOICi I5V38N8Snl12LT+GIZ98d803g+ClO+yATbPkpkAwy4mmk/mcydTFfFEImh0xyReMEewZ PBBbD8cqvsILtuYNsovKybzdlzWkDkCWtrS3cfxl8/2FSZp77THjDnSPfZcJn3pIVTVL bl1SVc5ekNWvbgUi8WNKarMIS45nDtadPJCm5QqA8IyfyYHkPVfgjFeD3LA3Hmt2D7GM 1gUVKpl4K+7Vvqd905J1CwKfsv/lMTIbLvYqthHazrkXRnHRJIBq4mMbhU6vpbDh2x1l H6pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=mgkw/HaivZtQiffGnWyJI9DT03FoCxlJZTa9j06fglI=; fh=Qi8O4GPf+E9kHNNUfjv2vNMHhM7kTwYQ+uMwpaT6JZQ=; b=pMUdK5xRdnAqhnOD55G6keNQfXDtzI3zUxj+Jsh7fv69aW1pmLtZR+IBCEatYk72kZ eG3WKDWSL5wQtwRCEWeeIUyvS5xA9vESRtT3Y6+r5UpNv1x2UbJtmmumPyIKWSIJ2XKI ATGQG3JlsdAK4CRJWCoFQKjQS87P5a1TuSehdUBrr8TVpnRRmrKc/DUFiXusKPKbnrrk 4+uO8v0ECdFK6tneXG/UXoLuFcsPdMwxBgSqLECidRVzLesdWg/xxwYIuN4GmvqTNiv4 ELQ9d4nv5hKOZWbQ6Cp1KB8GVGOVyh8XeuU7Pu8xWDyoyeEuPBnIdnSloIswcSbdPks+ 1oNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id by12-20020a056a00400c00b00691016ba9bcsi6356332pfb.14.2023.10.08.19.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 19:55:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 63101809B752; Sun, 8 Oct 2023 19:55:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344977AbjJICzQ (ORCPT + 99 others); Sun, 8 Oct 2023 22:55:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232250AbjJICzP (ORCPT ); Sun, 8 Oct 2023 22:55:15 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CB623AB; Sun, 8 Oct 2023 19:55:12 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8DxPOuOayNlEC4wAA--.21567S3; Mon, 09 Oct 2023 10:55:11 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cx7y+NayNlRvEbAA--.58139S5; Mon, 09 Oct 2023 10:55:10 +0800 (CST) From: Tianrui Zhao To: 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 , maobibo@loongson.cn, zhaotianrui@loongson.cn Subject: [PATCH v3 3/4] KVM: selftests: Add ucall test support for LoongArch Date: Mon, 9 Oct 2023 10:55:09 +0800 Message-Id: <20231009025510.342681-4-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20231009025510.342681-1-zhaotianrui@loongson.cn> References: <20231009025510.342681-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Cx7y+NayNlRvEbAA--.58139S5 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Sun, 08 Oct 2023 19:55:34 -0700 (PDT) X-Spam-Level: ** Add ucall test support for LoongArch. A ucall is a "hypercall to userspace". Based-on: <20230927030959.3629941-1-zhaotianrui@loongson.cn> Signed-off-by: Tianrui Zhao --- .../selftests/kvm/include/loongarch/ucall.h | 20 ++++++++++ .../selftests/kvm/lib/loongarch/ucall.c | 38 +++++++++++++++++++ 2 files changed, 58 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 0000000000..4b68f37efd --- /dev/null +++ b/tools/testing/selftests/kvm/include/loongarch/ucall.h @@ -0,0 +1,20 @@ +/* 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 + +/* + * 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 0000000000..fc6cbb5057 --- /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; +} -- 2.39.1