Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1313214rwo; Wed, 2 Aug 2023 11:58:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlH4QJhRJ1yygj2DGfu53Z9Qig4Kajj/kCASAzyaRreW9c1/L6e6jg4zQTcL9Tp1Wy22zjGJ X-Received: by 2002:a17:907:1ca7:b0:978:2b56:d76e with SMTP id nb39-20020a1709071ca700b009782b56d76emr8383618ejc.12.1691002700042; Wed, 02 Aug 2023 11:58:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691002700; cv=none; d=google.com; s=arc-20160816; b=RnjxhQcN6EzZze4xBRYrKfbcbWLuyUEI1h8Hd0pS5o3RBpn/Nkn6/eEdCWL8b/JuYN IYfK9ay6/Pn0JqMa0lYdguZPTVVJ8AtL6LnC86XHVh3kZD9KlCnq4rNXkchWcgj0+HNy 4rFf9b+kofqoRjdnQEp7/HJ2ToBOKx7tlkOaCBEVmpfjdoJNQSPMuoxhOUOQ/43n/JAY w/73sm2t4x5e2Fa4vpvFCdHusnLJYop4q7JSR73UwHnolQamQ+ZgseksE1Eli67tHgcw iUZUMzlQ3KRcoOVoKsatltO76NFE5P87spQQke2YS5P8DXsAYnguNXTZTojJ5tO5RBOc 8zSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=RoApKlnA3BOMzrINClENLRSkWlEARK57ybrSJylcOSk=; fh=zucpp8MTujBKF102SNBmrZrEcggo7osgWjpgKV7+jnE=; b=g3z7fJEx8R2p/vyqCVtzN/bq+UqEcx0PlcYe8oYL4BlnLjDQF4LfbNTFu6hJZ4uiyU hTlByIS4S7n97/btcbG10/3tzSczBY4b4Bv2aHxmuJJVGVViG+9Z+ILoywNYpx9bBWSx /6HKeFGmGVsf2xiT0Owrk0BCJyJfCEK9LQ6Mx/UHpqK2ACbZ6jA6zWWV0zRAli9+mOJZ y3T21k7V1JgOZBqn5ihye8085tf04haCwb8Zd58BIokhlfxzj3kRThgB28Q1g6Lee6kO unrZjAAb91FPjJQ5Jo71ELEez16tAqA5GqXCS7DHGrlS6d++zVB9Bvrp5DvBkHz/b96j zsBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=mj8VbGef; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v5-20020aa7d9c5000000b0051e3371a8bbsi11083203eds.2.2023.08.02.11.57.54; Wed, 02 Aug 2023 11:58:20 -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; dkim=pass header.i=@google.com header.s=20221208 header.b=mj8VbGef; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232289AbjHBSI7 (ORCPT + 99 others); Wed, 2 Aug 2023 14:08:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233638AbjHBSIv (ORCPT ); Wed, 2 Aug 2023 14:08:51 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5845219BE for ; Wed, 2 Aug 2023 11:08:45 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1bb982d2572so1202125ad.0 for ; Wed, 02 Aug 2023 11:08:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690999725; x=1691604525; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=RoApKlnA3BOMzrINClENLRSkWlEARK57ybrSJylcOSk=; b=mj8VbGefF2duwlheVOgxf6z54EG8zmMmwTerkgYKRlKthiOTNJifWNjqGPpmd4UZ+U jjcOJOa08SbKJsGvXjtH9ppHkQYcI5kWP9kAzRpXklc+WxAV4dGSR9oFYXt04TzNoPIz IUQigpkiYepYDIpfvkkuk8E2MptKkOHgh4xjhGnNHqYRhj6SfsgdRH7Hto6bXzz5ErOv OMqP/Q2jm6rY5LXXUeKeOFb/e1cztAh+2HFBnvBi1IFIs/YsWXNMY2SE/bz7t/l04EXv uK6l60t/yG7NWonZPOCCnfaL51hwuUDMw1osNl0M+Bnv5Ea/cbFAhozDp05c++rkQODw WIOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690999725; x=1691604525; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RoApKlnA3BOMzrINClENLRSkWlEARK57ybrSJylcOSk=; b=PpgYuxV9ybDTGoIPFxamYL33iruOte4znt3PG2Ml8qpK9THQgw2BrFFMkowKY+XzcY y0VlLzQurq56GYFUe7pmoe+AIEkaDddDyA+JCiKP6pfliCJxM07dVRV6C8Phgi+Rfgy0 iPEQhD7m/jITeypGIdbQ1lfCZATOafK9kvXqxzWbKJxXV36j9ERetrtXSp7GEJzJTjCX dHcBq1ETeGS/q+KmZVoM+PmpjxhsZU5c2WI/e7Go1zuO5PcvE2kwyyEBkA4Fbrrbotew aUZX86AKjmUsGB8pHM/cdwWprxku2jVH5Q6qtGCepu/QHBo7I17N/BiB8Np6yR3F1J3P mGJg== X-Gm-Message-State: ABy/qLbyJQLVWDcjjFvrlY9xp9FkjNNbB6nyVjXJXDaBvywnC0WhhJLk fn3igRwiLH+bc4+UKiQDMXYwsGEGOyI= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:e5c1:b0:1b7:edcd:8dcf with SMTP id u1-20020a170902e5c100b001b7edcd8dcfmr98398plf.4.1690999724892; Wed, 02 Aug 2023 11:08:44 -0700 (PDT) Date: Wed, 2 Aug 2023 11:08:43 -0700 In-Reply-To: <20230801020206.1957986-4-zhaotianrui@loongson.cn> Mime-Version: 1.0 References: <20230801020206.1957986-1-zhaotianrui@loongson.cn> <20230801020206.1957986-4-zhaotianrui@loongson.cn> Message-ID: Subject: Re: [PATCH v1 3/4] selftests: kvm: Add ucall tests for LoongArch KVM From: Sean Christopherson To: Tianrui Zhao 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 Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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 On Tue, Aug 01, 2023, Tianrui Zhao wrote: > Add ucall tests for LoongArch KVM, it means that VM use hypercall s/tests/support > 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. > + 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 >