Message ID | 20230807065137.3408970-4-zhaotianrui@loongson.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1274583vqr; Mon, 7 Aug 2023 00:14:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFHj+MUrCm4FwV6JMj2pYrmFhRxO4i6iDkIyeZNRP7wcP4NkgOIdFNqRX3Mwz7m73aconUs X-Received: by 2002:a17:90b:3a8f:b0:262:f798:b60d with SMTP id om15-20020a17090b3a8f00b00262f798b60dmr6274923pjb.6.1691392453801; Mon, 07 Aug 2023 00:14:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691392453; cv=none; d=google.com; s=arc-20160816; b=zKeIqqQ8sCc3mxr6xd8sEhjiQUFQ4g0XhJvo8KlSJnWnCO9qec/PM2IPdx/GeC0+ka Pji/DBuaCob9H7dOnN4mTxZ29HrREGaunbRF7FVouhcPxK4vDRsCHXfQYQKYEr6mmctl /0+FMQ0N9uvqlDMNRJCLRh6hDEwO5Zg4HoF9xjPdAewYkxZomxJjNeKW9U/wg8JkuCJc NjalqdJpXh/yYTR9WStwimIIcvAFxvW6EAu2H+blQ8xNOK5dqr/digkeM5Nglbq8EwBl My33jazkvb4xarfxhn6V0u35/mQtrhTgQjFji5hJzeegzY0LXL0QUbWWBN1jajpDxM73 crVw== 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=vdR8KVto+ZVhAXAaFq0Y4FBz/3rDyrUBsszrws7YbEs=; fh=gsUmtxbMqK36mL5NFoC4xZ5sX9WhDudI+8elbmlEVgg=; b=HeJBSaalDr7lThrEloDj/lvfe1gIajgp9Oy2SM/QdzrnKKkiz8FGx+uvVsj6t5cABo 7sdOiPLpgcmsC6PofdNbzGz1Lib9ABVix+yb4tpy7Imfhx8P2gmokFdDkPlIAXW4vXti xxdVOVbVAMRrmbYP/MMaozxJoOCQTNjPFPt9b7W8SVaEsQIpXtpibxxreRVhS0fY5uRr qg3Oe9zuoJr6JHtD5TQsnvTaz8mDJSvkS21LUPWglnTr79V3EG07kGK06kMI59yWberG HBGJ8pVLBz53NZBr3twckEr5+XcADbM5DCNDQrQnjpsaEGRwhlQjzBSeTPsy0xl5J8dw CDew== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mh5-20020a17090b4ac500b00263fc986e28si9052525pjb.24.2023.08.07.00.13.59; Mon, 07 Aug 2023 00:14:13 -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 S229998AbjHGGwD (ORCPT <rfc822;aaronkmseo@gmail.com> + 99 others); Mon, 7 Aug 2023 02:52:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231328AbjHGGvs (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 7 Aug 2023 02:51:48 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8138F198D; Sun, 6 Aug 2023 23:51:42 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxCPJ8lNBk9dwRAA--.40000S3; Mon, 07 Aug 2023 14:51:40 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxJ8x5lNBkwspMAA--.23544S5; Mon, 07 Aug 2023 14:51:39 +0800 (CST) From: Tianrui Zhao <zhaotianrui@loongson.cn> To: Shuah Khan <shuah@kernel.org>, Paolo Bonzini <pbonzini@redhat.com>, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Sean Christopherson <seanjc@google.com> Cc: Vishal Annapurve <vannapurve@google.com>, Huacai Chen <chenhuacai@kernel.org>, WANG Xuerui <kernel@xen0n.name>, loongarch@lists.linux.dev, Peter Xu <peterx@redhat.com>, Vipin Sharma <vipinsh@google.com>, maobibo@loongson.cn, zhaotianrui@loongson.cn Subject: [PATCH v2 3/4] KVM: selftests: Add ucall test support for LoongArch Date: Mon, 7 Aug 2023 14:51:36 +0800 Message-Id: <20230807065137.3408970-4-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230807065137.3408970-1-zhaotianrui@loongson.cn> References: <20230807065137.3408970-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8DxJ8x5lNBkwspMAA--.23544S5 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773553533986550451 X-GMAIL-MSGID: 1773553533986550451 |
Series |
KVM: selftests: Add LoongArch support
|
|
Commit Message
zhaotianrui
Aug. 7, 2023, 6:51 a.m. UTC
Add ucall test support for LoongArch. A ucall is a "hypercall to
userspace".
Based-on: <20230803022138.2736430-1-zhaotianrui@loongson.cn>
Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
---
.../selftests/kvm/lib/loongarch/ucall.c | 43 +++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 tools/testing/selftests/kvm/lib/loongarch/ucall.c
Comments
On Mon, Aug 07, 2023, Tianrui Zhao wrote: > Add ucall test support for LoongArch. A ucall is a "hypercall to > userspace". Nit, can you explain why LoongArch uses MMIO to trigger ucall, and what alternatives were considred (if any)? The main reason for the ask is because we've tossed around the idea of converting all architectures (except s390) to MMIO-based ucall in order to reduce the number of "flavors" of ucall we have to worry about it. If MMIO is the only reasonable choice for LoongArch, that's another reason to double down on MMIO as the primary choice for ucall. > Based-on: <20230803022138.2736430-1-zhaotianrui@loongson.cn> > Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn> > --- > .../selftests/kvm/lib/loongarch/ucall.c | 43 +++++++++++++++++++ > 1 file changed, 43 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..72868ddec313 > --- /dev/null > +++ b/tools/testing/selftests/kvm/lib/loongarch/ucall.c > @@ -0,0 +1,43 @@ > +// 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) > +{ > + WRITE_ONCE(*ucall_exit_mmio_addr, uc); Another uber nit, you might want to put this in the header as a static inline to avoid function calls. I doubt it'll actually matter, but we've had enough weird, hard-to-debug issues with ucall that minimizing the amount of generated code might save some future pain.
在 2023/9/28 上午4:54, Sean Christopherson 写道: > On Mon, Aug 07, 2023, Tianrui Zhao wrote: >> Add ucall test support for LoongArch. A ucall is a "hypercall to >> userspace". > Nit, can you explain why LoongArch uses MMIO to trigger ucall, and what alternatives > were considred (if any)? The main reason for the ask is because we've tossed > around the idea of converting all architectures (except s390) to MMIO-based ucall > in order to reduce the number of "flavors" of ucall we have to worry about it. > If MMIO is the only reasonable choice for LoongArch, that's another reason to > double down on MMIO as the primary choice for ucall. Thanks for your reminding about ucall, and our guest can also use hypercall instruction to trigger ucall, so this change will not affect us. Thanks Tianrui Zhao > >> Based-on: <20230803022138.2736430-1-zhaotianrui@loongson.cn> >> Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn> >> --- >> .../selftests/kvm/lib/loongarch/ucall.c | 43 +++++++++++++++++++ >> 1 file changed, 43 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..72868ddec313 >> --- /dev/null >> +++ b/tools/testing/selftests/kvm/lib/loongarch/ucall.c >> @@ -0,0 +1,43 @@ >> +// 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) >> +{ >> + WRITE_ONCE(*ucall_exit_mmio_addr, uc); > Another uber nit, you might want to put this in the header as a static inline to > avoid function calls. I doubt it'll actually matter, but we've had enough weird, > hard-to-debug issues with ucall that minimizing the amount of generated code might > save some future pain.
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..72868ddec313 --- /dev/null +++ b/tools/testing/selftests/kvm/lib/loongarch/ucall.c @@ -0,0 +1,43 @@ +// 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) +{ + 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; +}