Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1841121rwo; Wed, 2 Aug 2023 23:59:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlF3KrwmtqaQP34N9Vrw4nwrGYdqhqdYXExb0gcJNuIoqgfIKOOeevQ46NeEtl+5jxbv8hMt X-Received: by 2002:a17:907:7751:b0:993:f2c2:7512 with SMTP id kx17-20020a170907775100b00993f2c27512mr8045009ejc.33.1691045966030; Wed, 02 Aug 2023 23:59:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691045966; cv=none; d=google.com; s=arc-20160816; b=gWZH+sC5uvWbv7ioXqFvzkrJRMkKTfBuITcVJGgAxU6s96reJ40Wk5HCMO5dmbz9lC 1J4wil7PgkkJxNocz3zFLMKx2wAM2Hl4waoG+YUXUMdIGeTTUJR2u7n6BckRFLF8eFHq sWnBHKuzJ8eB7q2lpacTnJF9u/zBfiPXrMzbXw21nhOAqqE/68/3B3aPuzua8C9rB4Lp t3uqjtBWzzoNI2bttUT2I8LdqgDKSodw1O3LSIkTeftTqno58WkhXlcWgbGHYIvH9lJ+ niYVPjkHfzcOsbuZR3mVJ/gvhFuETlvZCIPPA244uWz86pD1i/CKHZoNySHpfLIpd7Yc mqjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=CSgrj6I9oSsG1MS6ykaxA3lHapu/t28FdZxX0KklB9c=; fh=41RNoEzjB3KLxaASySr3tAtaq+s0fVrN0eYWAX1QMt4=; b=UJ4JBVmvIvkvNp1CnsbkAKVVX81WaMZJEqVM553fQ48rBDao9NR/pOFggNXMg1yL7+ YVxgTrrwY05wB25R1oqTOx9fbMwQzGFVTtc6bslgXF4KRRkoAugifoL1i1cVMq7oeaga w6SUHKAbvVSEKgrmQqxxqlmNDat0Ytc6hL87JYezH/c7GQPcJxor/xvOJ3XQU2yIXDGf KirWihE1Ov7x/RRV3Fsw+Gcuy1s9r8jIfFw881tFksPl6a1Kb7wiP6ud2W66UQ5Z/0Br PZE3ZRaecW8f7tXRgjKaOFQgvGaJx3SuNq6elJI7tB45t9EpHmqQLYdNPQk+abZsfpAA i+xg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f5-20020a1709064dc500b00993150e5327si6571930ejw.341.2023.08.02.23.59.00; Wed, 02 Aug 2023 23:59:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232170AbjHCGmc (ORCPT + 99 others); Thu, 3 Aug 2023 02:42:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230422AbjHCGmb (ORCPT ); Thu, 3 Aug 2023 02:42:31 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8C76DCC; Wed, 2 Aug 2023 23:42:28 -0700 (PDT) Received: from loongson.cn (unknown [10.40.46.158]) by gateway (Coremail) with SMTP id _____8DxRvFSTMtkf4YPAA--.36154S3; Thu, 03 Aug 2023 14:42:26 +0800 (CST) Received: from [192.168.124.126] (unknown [10.40.46.158]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cx_c5QTMtkr8dGAA--.51824S3; Thu, 03 Aug 2023 14:42:26 +0800 (CST) Subject: Re: [PATCH v1 3/4] selftests: kvm: Add ucall tests for LoongArch KVM To: Sean Christopherson Cc: Shuah Khan , Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Vishal Annapurve , Huacai Chen , WANG Xuerui , loongarch@lists.linux.dev, Peter Xu , Vipin Sharma , maobibo@loongson.cn References: <20230801020206.1957986-1-zhaotianrui@loongson.cn> <20230801020206.1957986-4-zhaotianrui@loongson.cn> From: zhaotianrui Message-ID: Date: Thu, 3 Aug 2023 14:42:24 +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: Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID: AQAAf8Cx_c5QTMtkr8dGAA--.51824S3 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBj93XoW7AF13KFy7Cr4rCryrJry7Arc_yoW8tw15pa s5Ca1UKF4Sgw17AwnxXr1jq3Wftr93tF1UZFyaq3yS9wsIvF1fJr1fKFy29FyavF1Ygr4r ZFn2gFnxCF1Yk3cCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUvIb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5McIj6I8E87Iv 67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lc7I2V7IY0VAS07 AlzVAYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02 F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GF ylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r 4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07jO db8UUUUU= X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ?? 2023/8/3 ????2:08, Sean Christopherson ะด??: > On Tue, Aug 01, 2023, Tianrui Zhao wrote: >> Add ucall tests for LoongArch KVM, it means that VM use hypercall > s/tests/support Thanks, I will fix this comment. > >> to return to userspace and handle the mmio exception. >> >> Based-on: <20230720062813.4126751-1-zhaotianrui@loongson.cn> >> Signed-off-by: Tianrui Zhao >> --- >> .../selftests/kvm/lib/loongarch/ucall.c | 44 +++++++++++++++++++ >> 1 file changed, 44 insertions(+) >> create mode 100644 tools/testing/selftests/kvm/lib/loongarch/ucall.c >> >> 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..b32f7c7f6548 >> --- /dev/null >> +++ b/tools/testing/selftests/kvm/lib/loongarch/ucall.c >> @@ -0,0 +1,44 @@ >> +// 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. >> + */ >> +static 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_do_ucall(vm_vaddr_t uc) >> +{ >> + > Extra newline. Thanks, I will remove this line. Thanks Tianrui Zhao > >> + WRITE_ONCE(*ucall_exit_mmio_addr, uc); >> +} >> + >> +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 >>