Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp608204rdb; Thu, 1 Feb 2024 20:12:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IF2FdYj9M1XePcZDg9JHC6JWlX8OIPBwAtBPA0KNrEoeexVCSurcSAT0dKLdgcHxiy0Bqtv X-Received: by 2002:a17:903:2312:b0:1d8:f39b:8a5f with SMTP id d18-20020a170903231200b001d8f39b8a5fmr1431270plh.62.1706847119974; Thu, 01 Feb 2024 20:11:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706847119; cv=pass; d=google.com; s=arc-20160816; b=z1Ubo3vB2LUqCurvIbNHThfEoP7p9mVB9iOq2bTZa4RayrLoeeyHhmj5FJfWC9HhHt eevMPG7zfMh/YzWa5/G1FSTi9ghKRv76voFcgL6qHWlZyYVkynzA85h2gDI4ks/nUPiV FqgSCBAE6WV/st8aXA1O7sgIh8II3ZuoRULt4OXS5hxRuPlqRp5QFn1pJ5kuNuZSFBob dEosuMybk9St9CnFMtrUU9yNPMuTsHlmM2vKZCpA9DgOAq+TT+s3Zgfr+BzBq0WSPW/p MRdXojmVo46Ymkkkram2XSP29c36299pDmPWs9TInKXwTj00MBCzIw4CXek1x9JUC/0z UIow== 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=UmcbMp+8q4i+Eivpg/P0YBqHlqiYP5y2GrMtTBO/czs=; b=xSnU100wv/OZ+YjjEqer44Dn+aER2h5Vr7zwSEib0InFRTsl3So3+Keic76ZZ5evC3 aVh+z6UZKj4Us6w45mo/sUQpWkGHurIYu7Y3WrRmSLiJFGzuMRQFckGaH2ZLKGt4dlVS EpxQA9lAdWtSPUgAxpDoVTx6WdyO5exPNLETM+WCB416DdpGiJKiG11U7A57I9Ijee8B zxquQ3c2kf3sugOB6J1hJUu5jeD7dAdnpib4b5L1KgM59wvc2/hUS8wq09AKnGy1IKU7 z6h2pmP7e7xhILT0NbHeyjPfOvAXp+f4lknJvw7sZhUgOx5KxeZfjETv3EX1Bty5pmJy L9eg==; dara=google.com 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-49179-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49179-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWGnNTM0yr3/ZPCpF7Khk65+22vypQdNrqWqY8jsH6jV4hebMzOykGoKU+hPaUcVFuZ3vD+OzeQLnkQiuf1Jr2XaV3MtQD9TbqW0tBy0Q== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id j8-20020a170903024800b001d8da5e2681si1018603plh.402.2024.02.01.20.11.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 20:11:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49179-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-49179-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49179-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id E2303B212CE for ; Fri, 2 Feb 2024 04:11:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 22F0C168A4; Fri, 2 Feb 2024 04:11:00 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D3764F504; Fri, 2 Feb 2024 04:10:56 +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=1706847059; cv=none; b=frgP1LTTV1ppT4dvdMj7QiCi1lyqQUBtJEDPYkheHU960et57s4BzAJD7kW4TK+/5NmhLvMoLBq+DceN7XxkOyL9AE+xOU8EqRA275exxJEHaaGMKQpdClf2gO38dODkxxj5WXBDZYsjvKyGj2hqo4UeToPwd5RizV8PeGbFOSM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706847059; c=relaxed/simple; bh=iI63PJ2NYgUftm5Hp3yxrWxlYFweWO2E06psH6Sm0o8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pBJueh2WpzQ3NOrflauvGHrOugvx9io7f26M1PfpGSVSTxvnMK8FMKADk5Y15iIqDeqMNJWehsD3RyPAcd2hssq0Kpda6+WU7PvZXDW1aX30jRJNDAe3bEdv7BLUxrRSk7HODHigyj9dgYY+bzJobRN7k9+ZDwro6W7m5K1jw58= 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 _____8AxqvBJa7xlbf4JAA--.29120S3; Fri, 02 Feb 2024 12:10:49 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxvhNGa7xlhd0sAA--.51008S5; Fri, 02 Feb 2024 12:10:49 +0800 (CST) From: Bibo Mao To: Paolo Bonzini , Sean Christopherson Cc: Tianrui Zhao , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v7 3/4] KVM: selftests: Add ucall test support for LoongArch Date: Fri, 2 Feb 2024 12:10:45 +0800 Message-Id: <20240202041046.3405779-4-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240202041046.3405779-1-maobibo@loongson.cn> References: <20240202041046.3405779-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:AQAAf8DxvhNGa7xlhd0sAA--.51008S5 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxCFyDtF18GF45Cw48AF1UArc_yoW5WF4rpa 4fCw18Kr4xKF17A3sxJwnFq3Wftrs2kF1fXFyavrWF9w42y3WxAr1xKFyqyFy2vFZYgrs5 ZFn2g3WUuF1UtwbCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUk2b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r126r13M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5McIj6I8E87Iv 67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUco7KUUUUU 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