Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1483059rdb; Wed, 24 Jan 2024 17:55:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHohrSo0+GGuMfKvwmhBIZGz1rS/L1A2edb4taWkmPSMxOyf2aNcnGXFFtedogndNnrknsf X-Received: by 2002:a05:600c:1da5:b0:40d:9240:7bc4 with SMTP id p37-20020a05600c1da500b0040d92407bc4mr53550wms.2.1706147715935; Wed, 24 Jan 2024 17:55:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706147715; cv=pass; d=google.com; s=arc-20160816; b=k+3ZWnEYhKGnTa2dcd97cSJtjuiZ9Gd0P5Tv/FO8r0eRBR0Yhu6krnxGvTSQIwLb1N ujs43GB4YjIftFHXyVIzA7VN3eFOrnM9P+89Kyhb1Va+S/ju1YJgvvoHgPVgVZPQhgv4 v7D0GJlcx4kwevHxzHOrMDEqTLKzFmQHloU1PLbI3I1tx2E9jdJpoqvnOKlWs5pHTRO2 9KroLjT8e9XKhT/np0ojmuveXuO4rm9/wnsykx7H5eZsVn8RPHmQUucOoeG7XdJVCTJ2 y+/lFHnVey1Xtgo7zxCyeZ7L03l5EIo6ykHkmd2s8nkFgp2mBWt46aLF2xXWw16A1eLA s3Ng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=tyxnJKVhZ0msTXWBRyL3dOK5j63JShj6auTu2Y5XaUQ=; fh=wle3M6nZSpyM2bErweAAS2C2D0e+rFxFslIQG1wEa/g=; b=ik5UYEapMIQXJUkxuNX0WYBqbcTb8tbto6vst3rNLyRjT5tnrOAYbhPRJczaryEmaK DLuQLVj44COBWu3DDrR5Nw24ARBRHoFG36UmKVa7wyUnAb3SI7p7Mr3vo3Fk5URxEWdp krGnyEyQUnzXFV3kffoQYJptyfXU/lNLYU4sf5q0ac1jHWjj4RGFE0l8i1a+ut0vGz/7 ojllhOMA6ST+CvlegRdJ2OiXrR0ImosbLB2U2sy2z4dTvwlDfdkhURkUdc6zqhzwlyPS BvJKi1Vx9nDRJJNG8NP0KLTZMlJOJ3roxJNn2Oy/B/aKVRGNqGntLdYImwmARj9g7xGr 32KA== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-37875-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37875-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 10-20020a0564021f4a00b0055cc3b6314dsi1281074edz.86.2024.01.24.17.55.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 17:55:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37875-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-37875-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37875-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id ADCF41F23A7C for ; Thu, 25 Jan 2024 01:55:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F02579CF; Thu, 25 Jan 2024 01:54:35 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 233FF6FCA; Thu, 25 Jan 2024 01:54:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706147674; cv=none; b=fvQ0Ih3UGMrc1Bzc73Myq3NUAcpum4Fj2NlE00/xg7v0vF5n4+paU6Yp2Pr1/WAHxYhSwq5iMGXHYhHmhZ3lARHmOKgycFudj1j4wsey9a2xRNIJhQlxuuD+qXcDt7JbrP5PSTDGSbaLaYgsxDB5LI6txYblh7fd2dkrnzz97O8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706147674; c=relaxed/simple; bh=iI63PJ2NYgUftm5Hp3yxrWxlYFweWO2E06psH6Sm0o8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BG/gWqUSY4NeaZeFxg1RvMexjerDHarQFWlV14GnUwI362QiVm05fGyEDdryYLdiVCi2TU2ffmMod3E7fOYhczISldMeshuXiWghuIRksuHzNqM9YYkyQvvE5nKWs5ETNudrWedrEREv4vAj8O4NUhZuenBU0rlBfKZNYrrrqjY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8BxyuhWv7FltT0FAA--.686S3; Thu, 25 Jan 2024 09:54:30 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxVMxMv7FlojkYAA--.45641S5; Thu, 25 Jan 2024 09:54:30 +0800 (CST) From: Bibo Mao To: Paolo Bonzini , Shuah Khan , Sean Christopherson Cc: Tianrui Zhao , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v6 3/4] KVM: selftests: Add ucall test support for LoongArch Date: Thu, 25 Jan 2024 09:54:19 +0800 Message-Id: <20240125015420.1960090-4-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240125015420.1960090-1-maobibo@loongson.cn> References: <20240125015420.1960090-1-maobibo@loongson.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:AQAAf8BxVMxMv7FlojkYAA--.45641S5 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxCFyDtF18GF45Cw48AF1UArc_yoW5WF4rpa 4fCw18Kr4xKF17A3sxJwnFq3Wftrs2kF1fXFyavrWF9w42y3WxAr1xKFyqyFy2vFZYgrs5 ZFn2g3WUuF1UtwbCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU90b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1q6r4UM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4j6r4UJwAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0c Ia020Ex4CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jw0_ WrylYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwI xGrwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWU XVWUAwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67 kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY 6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVj vjDU0xZFpf9x07UCoGQUUUUU= From: Tianrui Zhao Add ucall test support for LoongArch, ucall method on LoongArch uses undefined mmio area. It will cause causes vcpu exits to hypervisor so that hypervisor can communicate with vcpu. Signed-off-by: Tianrui Zhao Signed-off-by: Bibo Mao --- .../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 000000000000..4b68f37efd36 --- /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 000000000000..fc6cbb50573f --- /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.3