From patchwork Fri Feb 2 04:10:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: maobibo X-Patchwork-Id: 195561 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp198711dyc; Thu, 1 Feb 2024 20:13:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHHU6WkBGvXnI9YEMQ60uciiZ+hDMPBSLbIamh2bPw6at7P/eyuIr8oEE0gJlVbpNqOueWD X-Received: by 2002:aa7:8b81:0:b0:6df:f525:d8db with SMTP id r1-20020aa78b81000000b006dff525d8dbmr1028328pfd.8.1706847215628; Thu, 01 Feb 2024 20:13:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706847215; cv=pass; d=google.com; s=arc-20160816; b=TbzyzubSFp35vz84Hc9LDd5yUVJYGZq3d3fmBoa/H+1hi3U14vHDIIUDhMDrFZzHMK ECdRs0M+79m2D1/n/84UnPTITTC7JtTomR0c4EPj4eoI5q7+ejOvRT9xWl3xaYSYnVJM Digj3D3L6LnDfJHlfBZrhC/WPeGhD85noNj7DFTDnAfSByB5DMCgsfX4bX2yQvklv6gW 6dZX3RjBV9OXlyBZO7sWutzjzZn0m4mz6qjt5rM2eIc8y79m3YJn1lnUFEbeUJ4JckUx GeyrhxjkNC3F3VGO8LLAOYmge1jrr69Qzca7x7E2rUt/TiHJasE0vyDeT79btUVinhdh E54A== 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=WG7w+jHycS6PU858Ske4yElI24RQ2HEk0qaKH8I1GzY=; b=YOiI519R59v5BhgDoRDFLm37qgDw/S7yKdllHTflw7/+U3/iK+SeGJG/Yse/VuGSBq wOZBuxF3D0nP2hVHlXswy5rtse7xTjrHbd+SjOFqAw29tAMAJ3nYebPB+qhhbgRI9fMi s5uUO+DDIJ6kvVG4gQ44VbrRVdJj6nDeCF3YUD5/eSAn5Vv5qgGtg5H8iOofdTjv50X8 lNPU3lJvwzHmZjYeek3+twVekglQZ8zYyCffMD0iG4CtWgUOHmra4mcKf46aBSYEwkUf maxN2Sq6DlT4r9hh79OcaH48BbDLvA4xZ2l/5l2BMg/i+t82Hyfz9kA5VgVqyv0hGIAs kUzw==; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49179-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXW8OlIf/5/EDaFq1VS9J1J5CU3mjI8TJSyVk4yGHidmmQJ17XKyMBszqpcsDKZAk3wMa06tLCrdr9r7K+B3SJTPGmM2Q== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h10-20020a056a00230a00b006dbdbf8943esi876369pfh.182.2024.02.01.20.13.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 20:13:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49179-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49179-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 157992883C9 for ; Fri, 2 Feb 2024 04:12:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 788BD17564; Fri, 2 Feb 2024 04:11:01 +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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789759026289074094 X-GMAIL-MSGID: 1789759026289074094 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; +}