From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9889DC433EF for ; Mon, 20 Jun 2022 07:40:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239453AbiFTHkR (ORCPT ); Mon, 20 Jun 2022 03:40:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237615AbiFTHkP (ORCPT ); Mon, 20 Jun 2022 03:40:15 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FDAFF5AC; Mon, 20 Jun 2022 00:40:13 -0700 (PDT) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25K4lEg7017264; Mon, 20 Jun 2022 07:39:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=7cqLTU9P1Ro0Wdde+r9wJ+UtamNnbvbI+jmvk75qn34=; b=mjkUx6YN1YPZsmrPM/nAmw0GbmTV0oB/xGVwbdIuWE9YvF7d8Lk+u+IyJHKDT5CiHd2v cy2pNOJbqMb/QoCVcny28OvN8BxYUKp70l6vTeiwW8ZTnv4aoLL7qf/0KHz8OrBYqfCS Z16eWM6z4xkugZNOGg4vQcZ6gQrnc4EN1Tyw7ATMD64gdaZpvxIvVWkEcFHgrfp9JNIC jP4Cw/llGNSIHyxRUzbvim7oDNvR41Skd18CAzTc/rcOzvvBntsvEjSWsklAjapMope5 sWLCY1tgyCg2/KZAVaVVMGixTfAcFIgzBEmWFErI/hQo0dTYaQTKzlhu4qOKEqVvz6zw 1w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gsr0u9vhy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jun 2022 07:39:58 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 25K7JH3B018024; Mon, 20 Jun 2022 07:39:57 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gsr0u9vh1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jun 2022 07:39:57 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 25K7bFew009561; Mon, 20 Jun 2022 07:39:54 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma06ams.nl.ibm.com with ESMTP id 3gs5yhj44t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jun 2022 07:39:54 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 25K7dpqf18481508 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Jun 2022 07:39:51 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 764BC4203F; Mon, 20 Jun 2022 07:39:51 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7625842041; Mon, 20 Jun 2022 07:39:50 +0000 (GMT) Received: from [9.171.78.67] (unknown [9.171.78.67]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 20 Jun 2022 07:39:50 +0000 (GMT) Message-ID: <6518c2f2-476c-9f12-5a07-974af95a0b42@linux.ibm.com> Date: Mon, 20 Jun 2022 09:39:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH 1/3] KVM: selftests: Consolidate common code for popuplating ucall struct Content-Language: en-US To: Sean Christopherson , Paolo Bonzini , Marc Zyngier , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Janosch Frank , Claudio Imbrenda Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Colton Lewis , Andrew Jones References: <20220618001618.1840806-1-seanjc@google.com> <20220618001618.1840806-2-seanjc@google.com> From: Christian Borntraeger In-Reply-To: <20220618001618.1840806-2-seanjc@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 3kMnldFGR4mx2uIIfYJ39jhAL3unWFq8 X-Proofpoint-ORIG-GUID: t79n4gkBCrUV_et_g7vpEmhdtxJM0A7F X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-20_05,2022-06-17_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 adultscore=0 priorityscore=1501 clxscore=1011 spamscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206200035 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 18.06.22 um 02:16 schrieb Sean Christopherson: > Make ucall() a common helper that populates struct ucall, and only calls > into arch code to make the actually call out to userspace. > > Rename all arch-specific helpers to make it clear they're arch-specific, > and to avoid collisions with common helpers (one more on its way...) > > No functional change intended. > > Cc: Colton Lewis > Cc: Andrew Jones > Signed-off-by: Sean Christopherson seems to work on s390. Tested-by: Christian Borntraeger > --- > tools/testing/selftests/kvm/Makefile | 1 + > .../selftests/kvm/include/ucall_common.h | 23 ++++++++++++++++--- > .../testing/selftests/kvm/lib/aarch64/ucall.c | 23 ++++--------------- > tools/testing/selftests/kvm/lib/riscv/ucall.c | 23 ++++--------------- > tools/testing/selftests/kvm/lib/s390x/ucall.c | 23 ++++--------------- > .../testing/selftests/kvm/lib/ucall_common.c | 20 ++++++++++++++++ > .../testing/selftests/kvm/lib/x86_64/ucall.c | 23 ++++--------------- > 7 files changed, 61 insertions(+), 75 deletions(-) > create mode 100644 tools/testing/selftests/kvm/lib/ucall_common.c > > diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile > index b52c130f7b2f..bc2aee2af66c 100644 > --- a/tools/testing/selftests/kvm/Makefile > +++ b/tools/testing/selftests/kvm/Makefile > @@ -46,6 +46,7 @@ LIBKVM += lib/perf_test_util.c > LIBKVM += lib/rbtree.c > LIBKVM += lib/sparsebit.c > LIBKVM += lib/test_util.c > +LIBKVM += lib/ucall_common.c > > LIBKVM_x86_64 += lib/x86_64/apic.c > LIBKVM_x86_64 += lib/x86_64/handlers.S > diff --git a/tools/testing/selftests/kvm/include/ucall_common.h b/tools/testing/selftests/kvm/include/ucall_common.h > index 98562f685151..c6a4fd7fe443 100644 > --- a/tools/testing/selftests/kvm/include/ucall_common.h > +++ b/tools/testing/selftests/kvm/include/ucall_common.h > @@ -23,10 +23,27 @@ struct ucall { > uint64_t args[UCALL_MAX_ARGS]; > }; > > -void ucall_init(struct kvm_vm *vm, void *arg); > -void ucall_uninit(struct kvm_vm *vm); > +void ucall_arch_init(struct kvm_vm *vm, void *arg); > +void ucall_arch_uninit(struct kvm_vm *vm); > +void ucall_arch_do_ucall(vm_vaddr_t uc); > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc); > + > void ucall(uint64_t cmd, int nargs, ...); > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc); > + > +static inline void ucall_init(struct kvm_vm *vm, void *arg) > +{ > + ucall_arch_init(vm, arg); > +} > + > +static inline void ucall_uninit(struct kvm_vm *vm) > +{ > + ucall_arch_uninit(vm); > +} > + > +static inline uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +{ > + return ucall_arch_get_ucall(vcpu, uc); > +} > > #define GUEST_SYNC_ARGS(stage, arg1, arg2, arg3, arg4) \ > ucall(UCALL_SYNC, 6, "hello", stage, arg1, arg2, arg3, arg4) > diff --git a/tools/testing/selftests/kvm/lib/aarch64/ucall.c b/tools/testing/selftests/kvm/lib/aarch64/ucall.c > index 0b949ee06b5e..2de9fdd34159 100644 > --- a/tools/testing/selftests/kvm/lib/aarch64/ucall.c > +++ b/tools/testing/selftests/kvm/lib/aarch64/ucall.c > @@ -21,7 +21,7 @@ static bool ucall_mmio_init(struct kvm_vm *vm, vm_paddr_t gpa) > return true; > } > > -void ucall_init(struct kvm_vm *vm, void *arg) > +void ucall_arch_init(struct kvm_vm *vm, void *arg) > { > vm_paddr_t gpa, start, end, step, offset; > unsigned int bits; > @@ -64,31 +64,18 @@ void ucall_init(struct kvm_vm *vm, void *arg) > TEST_FAIL("Can't find a ucall mmio address"); > } > > -void ucall_uninit(struct kvm_vm *vm) > +void ucall_arch_uninit(struct kvm_vm *vm) > { > ucall_exit_mmio_addr = 0; > sync_global_to_guest(vm, ucall_exit_mmio_addr); > } > > -void ucall(uint64_t cmd, int nargs, ...) > +void ucall_arch_do_ucall(vm_vaddr_t uc) > { > - struct ucall uc = { > - .cmd = cmd, > - }; > - va_list va; > - int i; > - > - nargs = min(nargs, UCALL_MAX_ARGS); > - > - va_start(va, nargs); > - for (i = 0; i < nargs; ++i) > - uc.args[i] = va_arg(va, uint64_t); > - va_end(va); > - > - *ucall_exit_mmio_addr = (vm_vaddr_t)&uc; > + *ucall_exit_mmio_addr = uc; > } > > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > { > struct kvm_run *run = vcpu->run; > struct ucall ucall = {}; > diff --git a/tools/testing/selftests/kvm/lib/riscv/ucall.c b/tools/testing/selftests/kvm/lib/riscv/ucall.c > index 087b9740bc8f..b1598f418c1f 100644 > --- a/tools/testing/selftests/kvm/lib/riscv/ucall.c > +++ b/tools/testing/selftests/kvm/lib/riscv/ucall.c > @@ -10,11 +10,11 @@ > #include "kvm_util.h" > #include "processor.h" > > -void ucall_init(struct kvm_vm *vm, void *arg) > +void ucall_arch_init(struct kvm_vm *vm, void *arg) > { > } > > -void ucall_uninit(struct kvm_vm *vm) > +void ucall_arch_uninit(struct kvm_vm *vm) > { > } > > @@ -44,27 +44,14 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, > return ret; > } > > -void ucall(uint64_t cmd, int nargs, ...) > +void ucall_arch_do_ucall(vm_vaddr_t uc) > { > - struct ucall uc = { > - .cmd = cmd, > - }; > - va_list va; > - int i; > - > - nargs = min(nargs, UCALL_MAX_ARGS); > - > - va_start(va, nargs); > - for (i = 0; i < nargs; ++i) > - uc.args[i] = va_arg(va, uint64_t); > - va_end(va); > - > sbi_ecall(KVM_RISCV_SELFTESTS_SBI_EXT, > KVM_RISCV_SELFTESTS_SBI_UCALL, > - (vm_vaddr_t)&uc, 0, 0, 0, 0, 0); > + uc, 0, 0, 0, 0, 0); > } > > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > { > struct kvm_run *run = vcpu->run; > struct ucall ucall = {}; > diff --git a/tools/testing/selftests/kvm/lib/s390x/ucall.c b/tools/testing/selftests/kvm/lib/s390x/ucall.c > index 73dc4e21190f..114cb4af295f 100644 > --- a/tools/testing/selftests/kvm/lib/s390x/ucall.c > +++ b/tools/testing/selftests/kvm/lib/s390x/ucall.c > @@ -6,34 +6,21 @@ > */ > #include "kvm_util.h" > > -void ucall_init(struct kvm_vm *vm, void *arg) > +void ucall_arch_init(struct kvm_vm *vm, void *arg) > { > } > > -void ucall_uninit(struct kvm_vm *vm) > +void ucall_arch_uninit(struct kvm_vm *vm) > { > } > > -void ucall(uint64_t cmd, int nargs, ...) > +void ucall_arch_do_ucall(vm_vaddr_t uc) > { > - struct ucall uc = { > - .cmd = cmd, > - }; > - va_list va; > - int i; > - > - nargs = min(nargs, UCALL_MAX_ARGS); > - > - va_start(va, nargs); > - for (i = 0; i < nargs; ++i) > - uc.args[i] = va_arg(va, uint64_t); > - va_end(va); > - > /* Exit via DIAGNOSE 0x501 (normally used for breakpoints) */ > - asm volatile ("diag 0,%0,0x501" : : "a"(&uc) : "memory"); > + asm volatile ("diag 0,%0,0x501" : : "a"(uc) : "memory"); > } > > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > { > struct kvm_run *run = vcpu->run; > struct ucall ucall = {}; > diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c > new file mode 100644 > index 000000000000..749ffdf23855 > --- /dev/null > +++ b/tools/testing/selftests/kvm/lib/ucall_common.c > @@ -0,0 +1,20 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +#include "kvm_util.h" > + > +void ucall(uint64_t cmd, int nargs, ...) > +{ > + struct ucall uc = { > + .cmd = cmd, > + }; > + va_list va; > + int i; > + > + nargs = min(nargs, UCALL_MAX_ARGS); > + > + va_start(va, nargs); > + for (i = 0; i < nargs; ++i) > + uc.args[i] = va_arg(va, uint64_t); > + va_end(va); > + > + ucall_arch_do_ucall((vm_vaddr_t)&uc); > +} > diff --git a/tools/testing/selftests/kvm/lib/x86_64/ucall.c b/tools/testing/selftests/kvm/lib/x86_64/ucall.c > index e5f0f9e0d3ee..9f532dba1003 100644 > --- a/tools/testing/selftests/kvm/lib/x86_64/ucall.c > +++ b/tools/testing/selftests/kvm/lib/x86_64/ucall.c > @@ -8,34 +8,21 @@ > > #define UCALL_PIO_PORT ((uint16_t)0x1000) > > -void ucall_init(struct kvm_vm *vm, void *arg) > +void ucall_arch_init(struct kvm_vm *vm, void *arg) > { > } > > -void ucall_uninit(struct kvm_vm *vm) > +void ucall_arch_uninit(struct kvm_vm *vm) > { > } > > -void ucall(uint64_t cmd, int nargs, ...) > +void ucall_arch_do_ucall(vm_vaddr_t uc) > { > - struct ucall uc = { > - .cmd = cmd, > - }; > - va_list va; > - int i; > - > - nargs = min(nargs, UCALL_MAX_ARGS); > - > - va_start(va, nargs); > - for (i = 0; i < nargs; ++i) > - uc.args[i] = va_arg(va, uint64_t); > - va_end(va); > - > asm volatile("in %[port], %%al" > - : : [port] "d" (UCALL_PIO_PORT), "D" (&uc) : "rax", "memory"); > + : : [port] "d" (UCALL_PIO_PORT), "D" (uc) : "rax", "memory"); > } > > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > { > struct kvm_run *run = vcpu->run; > struct ucall ucall = {}; From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 007C6C43334 for ; Mon, 20 Jun 2022 07:40:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fMgDDdcpWQlpEJOUAU3WpZDq07KhK2wyt/RlEuzVOy8=; b=0ktu+O7zcmunng dojCY5kN2MdvrsZJap91krpGVw62jHSBStrUXmE/GHyXbaHZwVEeRA2XriaUDV6V4V0hfxM8dRb01 tAOovePg1o9nAvMpkWyDWsGIOcaJft5aMEaR6CuhdUPwbH7wmNH0vIzNY5yIE9zQOlMXR8NUNjeND Yng6YJp9jYWEWAglv9lH5AR7Y6UjhSohoFDrAQU5MnMQHZidd9rD0MFNloUS7hwhmN8dokysU+QgE vufKjwecos914fXNNZYgCthUpv8LNVS8tzMeeh9dCicIDgRI3+wdsDe0tdC1zrWT7nXAMGhEGvRI9 XIDzBwBIt8Z4mHgotJdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o3C1H-00Ghbv-70; Mon, 20 Jun 2022 07:40:23 +0000 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o3C14-00GhVW-Mf; Mon, 20 Jun 2022 07:40:12 +0000 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25K4lEg7017264; Mon, 20 Jun 2022 07:39:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=7cqLTU9P1Ro0Wdde+r9wJ+UtamNnbvbI+jmvk75qn34=; b=mjkUx6YN1YPZsmrPM/nAmw0GbmTV0oB/xGVwbdIuWE9YvF7d8Lk+u+IyJHKDT5CiHd2v cy2pNOJbqMb/QoCVcny28OvN8BxYUKp70l6vTeiwW8ZTnv4aoLL7qf/0KHz8OrBYqfCS Z16eWM6z4xkugZNOGg4vQcZ6gQrnc4EN1Tyw7ATMD64gdaZpvxIvVWkEcFHgrfp9JNIC jP4Cw/llGNSIHyxRUzbvim7oDNvR41Skd18CAzTc/rcOzvvBntsvEjSWsklAjapMope5 sWLCY1tgyCg2/KZAVaVVMGixTfAcFIgzBEmWFErI/hQo0dTYaQTKzlhu4qOKEqVvz6zw 1w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gsr0u9vhy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jun 2022 07:39:58 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 25K7JH3B018024; Mon, 20 Jun 2022 07:39:57 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gsr0u9vh1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jun 2022 07:39:57 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 25K7bFew009561; Mon, 20 Jun 2022 07:39:54 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma06ams.nl.ibm.com with ESMTP id 3gs5yhj44t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jun 2022 07:39:54 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 25K7dpqf18481508 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Jun 2022 07:39:51 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 764BC4203F; Mon, 20 Jun 2022 07:39:51 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7625842041; Mon, 20 Jun 2022 07:39:50 +0000 (GMT) Received: from [9.171.78.67] (unknown [9.171.78.67]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 20 Jun 2022 07:39:50 +0000 (GMT) Message-ID: <6518c2f2-476c-9f12-5a07-974af95a0b42@linux.ibm.com> Date: Mon, 20 Jun 2022 09:39:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH 1/3] KVM: selftests: Consolidate common code for popuplating ucall struct Content-Language: en-US To: Sean Christopherson , Paolo Bonzini , Marc Zyngier , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Janosch Frank , Claudio Imbrenda Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Colton Lewis , Andrew Jones References: <20220618001618.1840806-1-seanjc@google.com> <20220618001618.1840806-2-seanjc@google.com> From: Christian Borntraeger In-Reply-To: <20220618001618.1840806-2-seanjc@google.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 3kMnldFGR4mx2uIIfYJ39jhAL3unWFq8 X-Proofpoint-ORIG-GUID: t79n4gkBCrUV_et_g7vpEmhdtxJM0A7F X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-20_05,2022-06-17_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 adultscore=0 priorityscore=1501 clxscore=1011 spamscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206200035 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220620_004011_032662_3605240B X-CRM114-Status: GOOD ( 28.75 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Am 18.06.22 um 02:16 schrieb Sean Christopherson: > Make ucall() a common helper that populates struct ucall, and only calls > into arch code to make the actually call out to userspace. > > Rename all arch-specific helpers to make it clear they're arch-specific, > and to avoid collisions with common helpers (one more on its way...) > > No functional change intended. > > Cc: Colton Lewis > Cc: Andrew Jones > Signed-off-by: Sean Christopherson seems to work on s390. Tested-by: Christian Borntraeger > --- > tools/testing/selftests/kvm/Makefile | 1 + > .../selftests/kvm/include/ucall_common.h | 23 ++++++++++++++++--- > .../testing/selftests/kvm/lib/aarch64/ucall.c | 23 ++++--------------- > tools/testing/selftests/kvm/lib/riscv/ucall.c | 23 ++++--------------- > tools/testing/selftests/kvm/lib/s390x/ucall.c | 23 ++++--------------- > .../testing/selftests/kvm/lib/ucall_common.c | 20 ++++++++++++++++ > .../testing/selftests/kvm/lib/x86_64/ucall.c | 23 ++++--------------- > 7 files changed, 61 insertions(+), 75 deletions(-) > create mode 100644 tools/testing/selftests/kvm/lib/ucall_common.c > > diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile > index b52c130f7b2f..bc2aee2af66c 100644 > --- a/tools/testing/selftests/kvm/Makefile > +++ b/tools/testing/selftests/kvm/Makefile > @@ -46,6 +46,7 @@ LIBKVM += lib/perf_test_util.c > LIBKVM += lib/rbtree.c > LIBKVM += lib/sparsebit.c > LIBKVM += lib/test_util.c > +LIBKVM += lib/ucall_common.c > > LIBKVM_x86_64 += lib/x86_64/apic.c > LIBKVM_x86_64 += lib/x86_64/handlers.S > diff --git a/tools/testing/selftests/kvm/include/ucall_common.h b/tools/testing/selftests/kvm/include/ucall_common.h > index 98562f685151..c6a4fd7fe443 100644 > --- a/tools/testing/selftests/kvm/include/ucall_common.h > +++ b/tools/testing/selftests/kvm/include/ucall_common.h > @@ -23,10 +23,27 @@ struct ucall { > uint64_t args[UCALL_MAX_ARGS]; > }; > > -void ucall_init(struct kvm_vm *vm, void *arg); > -void ucall_uninit(struct kvm_vm *vm); > +void ucall_arch_init(struct kvm_vm *vm, void *arg); > +void ucall_arch_uninit(struct kvm_vm *vm); > +void ucall_arch_do_ucall(vm_vaddr_t uc); > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc); > + > void ucall(uint64_t cmd, int nargs, ...); > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc); > + > +static inline void ucall_init(struct kvm_vm *vm, void *arg) > +{ > + ucall_arch_init(vm, arg); > +} > + > +static inline void ucall_uninit(struct kvm_vm *vm) > +{ > + ucall_arch_uninit(vm); > +} > + > +static inline uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +{ > + return ucall_arch_get_ucall(vcpu, uc); > +} > > #define GUEST_SYNC_ARGS(stage, arg1, arg2, arg3, arg4) \ > ucall(UCALL_SYNC, 6, "hello", stage, arg1, arg2, arg3, arg4) > diff --git a/tools/testing/selftests/kvm/lib/aarch64/ucall.c b/tools/testing/selftests/kvm/lib/aarch64/ucall.c > index 0b949ee06b5e..2de9fdd34159 100644 > --- a/tools/testing/selftests/kvm/lib/aarch64/ucall.c > +++ b/tools/testing/selftests/kvm/lib/aarch64/ucall.c > @@ -21,7 +21,7 @@ static bool ucall_mmio_init(struct kvm_vm *vm, vm_paddr_t gpa) > return true; > } > > -void ucall_init(struct kvm_vm *vm, void *arg) > +void ucall_arch_init(struct kvm_vm *vm, void *arg) > { > vm_paddr_t gpa, start, end, step, offset; > unsigned int bits; > @@ -64,31 +64,18 @@ void ucall_init(struct kvm_vm *vm, void *arg) > TEST_FAIL("Can't find a ucall mmio address"); > } > > -void ucall_uninit(struct kvm_vm *vm) > +void ucall_arch_uninit(struct kvm_vm *vm) > { > ucall_exit_mmio_addr = 0; > sync_global_to_guest(vm, ucall_exit_mmio_addr); > } > > -void ucall(uint64_t cmd, int nargs, ...) > +void ucall_arch_do_ucall(vm_vaddr_t uc) > { > - struct ucall uc = { > - .cmd = cmd, > - }; > - va_list va; > - int i; > - > - nargs = min(nargs, UCALL_MAX_ARGS); > - > - va_start(va, nargs); > - for (i = 0; i < nargs; ++i) > - uc.args[i] = va_arg(va, uint64_t); > - va_end(va); > - > - *ucall_exit_mmio_addr = (vm_vaddr_t)&uc; > + *ucall_exit_mmio_addr = uc; > } > > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > { > struct kvm_run *run = vcpu->run; > struct ucall ucall = {}; > diff --git a/tools/testing/selftests/kvm/lib/riscv/ucall.c b/tools/testing/selftests/kvm/lib/riscv/ucall.c > index 087b9740bc8f..b1598f418c1f 100644 > --- a/tools/testing/selftests/kvm/lib/riscv/ucall.c > +++ b/tools/testing/selftests/kvm/lib/riscv/ucall.c > @@ -10,11 +10,11 @@ > #include "kvm_util.h" > #include "processor.h" > > -void ucall_init(struct kvm_vm *vm, void *arg) > +void ucall_arch_init(struct kvm_vm *vm, void *arg) > { > } > > -void ucall_uninit(struct kvm_vm *vm) > +void ucall_arch_uninit(struct kvm_vm *vm) > { > } > > @@ -44,27 +44,14 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, > return ret; > } > > -void ucall(uint64_t cmd, int nargs, ...) > +void ucall_arch_do_ucall(vm_vaddr_t uc) > { > - struct ucall uc = { > - .cmd = cmd, > - }; > - va_list va; > - int i; > - > - nargs = min(nargs, UCALL_MAX_ARGS); > - > - va_start(va, nargs); > - for (i = 0; i < nargs; ++i) > - uc.args[i] = va_arg(va, uint64_t); > - va_end(va); > - > sbi_ecall(KVM_RISCV_SELFTESTS_SBI_EXT, > KVM_RISCV_SELFTESTS_SBI_UCALL, > - (vm_vaddr_t)&uc, 0, 0, 0, 0, 0); > + uc, 0, 0, 0, 0, 0); > } > > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > { > struct kvm_run *run = vcpu->run; > struct ucall ucall = {}; > diff --git a/tools/testing/selftests/kvm/lib/s390x/ucall.c b/tools/testing/selftests/kvm/lib/s390x/ucall.c > index 73dc4e21190f..114cb4af295f 100644 > --- a/tools/testing/selftests/kvm/lib/s390x/ucall.c > +++ b/tools/testing/selftests/kvm/lib/s390x/ucall.c > @@ -6,34 +6,21 @@ > */ > #include "kvm_util.h" > > -void ucall_init(struct kvm_vm *vm, void *arg) > +void ucall_arch_init(struct kvm_vm *vm, void *arg) > { > } > > -void ucall_uninit(struct kvm_vm *vm) > +void ucall_arch_uninit(struct kvm_vm *vm) > { > } > > -void ucall(uint64_t cmd, int nargs, ...) > +void ucall_arch_do_ucall(vm_vaddr_t uc) > { > - struct ucall uc = { > - .cmd = cmd, > - }; > - va_list va; > - int i; > - > - nargs = min(nargs, UCALL_MAX_ARGS); > - > - va_start(va, nargs); > - for (i = 0; i < nargs; ++i) > - uc.args[i] = va_arg(va, uint64_t); > - va_end(va); > - > /* Exit via DIAGNOSE 0x501 (normally used for breakpoints) */ > - asm volatile ("diag 0,%0,0x501" : : "a"(&uc) : "memory"); > + asm volatile ("diag 0,%0,0x501" : : "a"(uc) : "memory"); > } > > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > { > struct kvm_run *run = vcpu->run; > struct ucall ucall = {}; > diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c > new file mode 100644 > index 000000000000..749ffdf23855 > --- /dev/null > +++ b/tools/testing/selftests/kvm/lib/ucall_common.c > @@ -0,0 +1,20 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +#include "kvm_util.h" > + > +void ucall(uint64_t cmd, int nargs, ...) > +{ > + struct ucall uc = { > + .cmd = cmd, > + }; > + va_list va; > + int i; > + > + nargs = min(nargs, UCALL_MAX_ARGS); > + > + va_start(va, nargs); > + for (i = 0; i < nargs; ++i) > + uc.args[i] = va_arg(va, uint64_t); > + va_end(va); > + > + ucall_arch_do_ucall((vm_vaddr_t)&uc); > +} > diff --git a/tools/testing/selftests/kvm/lib/x86_64/ucall.c b/tools/testing/selftests/kvm/lib/x86_64/ucall.c > index e5f0f9e0d3ee..9f532dba1003 100644 > --- a/tools/testing/selftests/kvm/lib/x86_64/ucall.c > +++ b/tools/testing/selftests/kvm/lib/x86_64/ucall.c > @@ -8,34 +8,21 @@ > > #define UCALL_PIO_PORT ((uint16_t)0x1000) > > -void ucall_init(struct kvm_vm *vm, void *arg) > +void ucall_arch_init(struct kvm_vm *vm, void *arg) > { > } > > -void ucall_uninit(struct kvm_vm *vm) > +void ucall_arch_uninit(struct kvm_vm *vm) > { > } > > -void ucall(uint64_t cmd, int nargs, ...) > +void ucall_arch_do_ucall(vm_vaddr_t uc) > { > - struct ucall uc = { > - .cmd = cmd, > - }; > - va_list va; > - int i; > - > - nargs = min(nargs, UCALL_MAX_ARGS); > - > - va_start(va, nargs); > - for (i = 0; i < nargs; ++i) > - uc.args[i] = va_arg(va, uint64_t); > - va_end(va); > - > asm volatile("in %[port], %%al" > - : : [port] "d" (UCALL_PIO_PORT), "D" (&uc) : "rax", "memory"); > + : : [port] "d" (UCALL_PIO_PORT), "D" (uc) : "rax", "memory"); > } > > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > { > struct kvm_run *run = vcpu->run; > struct ucall ucall = {}; _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6DBAEC433EF for ; Mon, 20 Jun 2022 07:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IaXV+og6NBoXcZGGidgJ84uAx8olA5YunUGgioclKgA=; b=d+63XB5cWtLxSF F3rCSBTeo5He+89yyWVYpJ0Hv1lUASF2PYtpTYFI8sVqvcUTC1IEJgIHWilqwANyFXytKnO/aqRSc /Asf+r67BIgtZjOhycdZ792XmZmz/ki/n1QKYLZF6h4oRbDie+rCcUToWJr5ainTDsMHVnt9xss+Q i59RmhG0SCZswx4N2YgAhXN89KgOfgblFkpnsaTPb7NodWJbNnNiafkspqMMPPiVbG/cKN64j6Y7v HNA0Ui5AzFOSRic0/JuUoSVGkIVLDniG99BHBwULNgmbg87EUlQ3vDFXKUKXqIsxwutiBA9/6T1xC 76sZOMaVSjxLIyxp0QKg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o3C18-00GhWY-C5; Mon, 20 Jun 2022 07:40:14 +0000 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o3C14-00GhVW-Mf; Mon, 20 Jun 2022 07:40:12 +0000 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25K4lEg7017264; Mon, 20 Jun 2022 07:39:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=7cqLTU9P1Ro0Wdde+r9wJ+UtamNnbvbI+jmvk75qn34=; b=mjkUx6YN1YPZsmrPM/nAmw0GbmTV0oB/xGVwbdIuWE9YvF7d8Lk+u+IyJHKDT5CiHd2v cy2pNOJbqMb/QoCVcny28OvN8BxYUKp70l6vTeiwW8ZTnv4aoLL7qf/0KHz8OrBYqfCS Z16eWM6z4xkugZNOGg4vQcZ6gQrnc4EN1Tyw7ATMD64gdaZpvxIvVWkEcFHgrfp9JNIC jP4Cw/llGNSIHyxRUzbvim7oDNvR41Skd18CAzTc/rcOzvvBntsvEjSWsklAjapMope5 sWLCY1tgyCg2/KZAVaVVMGixTfAcFIgzBEmWFErI/hQo0dTYaQTKzlhu4qOKEqVvz6zw 1w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gsr0u9vhy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jun 2022 07:39:58 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 25K7JH3B018024; Mon, 20 Jun 2022 07:39:57 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gsr0u9vh1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jun 2022 07:39:57 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 25K7bFew009561; Mon, 20 Jun 2022 07:39:54 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma06ams.nl.ibm.com with ESMTP id 3gs5yhj44t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jun 2022 07:39:54 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 25K7dpqf18481508 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Jun 2022 07:39:51 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 764BC4203F; Mon, 20 Jun 2022 07:39:51 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7625842041; Mon, 20 Jun 2022 07:39:50 +0000 (GMT) Received: from [9.171.78.67] (unknown [9.171.78.67]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 20 Jun 2022 07:39:50 +0000 (GMT) Message-ID: <6518c2f2-476c-9f12-5a07-974af95a0b42@linux.ibm.com> Date: Mon, 20 Jun 2022 09:39:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH 1/3] KVM: selftests: Consolidate common code for popuplating ucall struct Content-Language: en-US To: Sean Christopherson , Paolo Bonzini , Marc Zyngier , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Janosch Frank , Claudio Imbrenda Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Colton Lewis , Andrew Jones References: <20220618001618.1840806-1-seanjc@google.com> <20220618001618.1840806-2-seanjc@google.com> From: Christian Borntraeger In-Reply-To: <20220618001618.1840806-2-seanjc@google.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 3kMnldFGR4mx2uIIfYJ39jhAL3unWFq8 X-Proofpoint-ORIG-GUID: t79n4gkBCrUV_et_g7vpEmhdtxJM0A7F X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-20_05,2022-06-17_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 adultscore=0 priorityscore=1501 clxscore=1011 spamscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206200035 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220620_004011_032662_3605240B X-CRM114-Status: GOOD ( 28.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Am 18.06.22 um 02:16 schrieb Sean Christopherson: > Make ucall() a common helper that populates struct ucall, and only calls > into arch code to make the actually call out to userspace. > > Rename all arch-specific helpers to make it clear they're arch-specific, > and to avoid collisions with common helpers (one more on its way...) > > No functional change intended. > > Cc: Colton Lewis > Cc: Andrew Jones > Signed-off-by: Sean Christopherson seems to work on s390. Tested-by: Christian Borntraeger > --- > tools/testing/selftests/kvm/Makefile | 1 + > .../selftests/kvm/include/ucall_common.h | 23 ++++++++++++++++--- > .../testing/selftests/kvm/lib/aarch64/ucall.c | 23 ++++--------------- > tools/testing/selftests/kvm/lib/riscv/ucall.c | 23 ++++--------------- > tools/testing/selftests/kvm/lib/s390x/ucall.c | 23 ++++--------------- > .../testing/selftests/kvm/lib/ucall_common.c | 20 ++++++++++++++++ > .../testing/selftests/kvm/lib/x86_64/ucall.c | 23 ++++--------------- > 7 files changed, 61 insertions(+), 75 deletions(-) > create mode 100644 tools/testing/selftests/kvm/lib/ucall_common.c > > diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile > index b52c130f7b2f..bc2aee2af66c 100644 > --- a/tools/testing/selftests/kvm/Makefile > +++ b/tools/testing/selftests/kvm/Makefile > @@ -46,6 +46,7 @@ LIBKVM += lib/perf_test_util.c > LIBKVM += lib/rbtree.c > LIBKVM += lib/sparsebit.c > LIBKVM += lib/test_util.c > +LIBKVM += lib/ucall_common.c > > LIBKVM_x86_64 += lib/x86_64/apic.c > LIBKVM_x86_64 += lib/x86_64/handlers.S > diff --git a/tools/testing/selftests/kvm/include/ucall_common.h b/tools/testing/selftests/kvm/include/ucall_common.h > index 98562f685151..c6a4fd7fe443 100644 > --- a/tools/testing/selftests/kvm/include/ucall_common.h > +++ b/tools/testing/selftests/kvm/include/ucall_common.h > @@ -23,10 +23,27 @@ struct ucall { > uint64_t args[UCALL_MAX_ARGS]; > }; > > -void ucall_init(struct kvm_vm *vm, void *arg); > -void ucall_uninit(struct kvm_vm *vm); > +void ucall_arch_init(struct kvm_vm *vm, void *arg); > +void ucall_arch_uninit(struct kvm_vm *vm); > +void ucall_arch_do_ucall(vm_vaddr_t uc); > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc); > + > void ucall(uint64_t cmd, int nargs, ...); > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc); > + > +static inline void ucall_init(struct kvm_vm *vm, void *arg) > +{ > + ucall_arch_init(vm, arg); > +} > + > +static inline void ucall_uninit(struct kvm_vm *vm) > +{ > + ucall_arch_uninit(vm); > +} > + > +static inline uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +{ > + return ucall_arch_get_ucall(vcpu, uc); > +} > > #define GUEST_SYNC_ARGS(stage, arg1, arg2, arg3, arg4) \ > ucall(UCALL_SYNC, 6, "hello", stage, arg1, arg2, arg3, arg4) > diff --git a/tools/testing/selftests/kvm/lib/aarch64/ucall.c b/tools/testing/selftests/kvm/lib/aarch64/ucall.c > index 0b949ee06b5e..2de9fdd34159 100644 > --- a/tools/testing/selftests/kvm/lib/aarch64/ucall.c > +++ b/tools/testing/selftests/kvm/lib/aarch64/ucall.c > @@ -21,7 +21,7 @@ static bool ucall_mmio_init(struct kvm_vm *vm, vm_paddr_t gpa) > return true; > } > > -void ucall_init(struct kvm_vm *vm, void *arg) > +void ucall_arch_init(struct kvm_vm *vm, void *arg) > { > vm_paddr_t gpa, start, end, step, offset; > unsigned int bits; > @@ -64,31 +64,18 @@ void ucall_init(struct kvm_vm *vm, void *arg) > TEST_FAIL("Can't find a ucall mmio address"); > } > > -void ucall_uninit(struct kvm_vm *vm) > +void ucall_arch_uninit(struct kvm_vm *vm) > { > ucall_exit_mmio_addr = 0; > sync_global_to_guest(vm, ucall_exit_mmio_addr); > } > > -void ucall(uint64_t cmd, int nargs, ...) > +void ucall_arch_do_ucall(vm_vaddr_t uc) > { > - struct ucall uc = { > - .cmd = cmd, > - }; > - va_list va; > - int i; > - > - nargs = min(nargs, UCALL_MAX_ARGS); > - > - va_start(va, nargs); > - for (i = 0; i < nargs; ++i) > - uc.args[i] = va_arg(va, uint64_t); > - va_end(va); > - > - *ucall_exit_mmio_addr = (vm_vaddr_t)&uc; > + *ucall_exit_mmio_addr = uc; > } > > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > { > struct kvm_run *run = vcpu->run; > struct ucall ucall = {}; > diff --git a/tools/testing/selftests/kvm/lib/riscv/ucall.c b/tools/testing/selftests/kvm/lib/riscv/ucall.c > index 087b9740bc8f..b1598f418c1f 100644 > --- a/tools/testing/selftests/kvm/lib/riscv/ucall.c > +++ b/tools/testing/selftests/kvm/lib/riscv/ucall.c > @@ -10,11 +10,11 @@ > #include "kvm_util.h" > #include "processor.h" > > -void ucall_init(struct kvm_vm *vm, void *arg) > +void ucall_arch_init(struct kvm_vm *vm, void *arg) > { > } > > -void ucall_uninit(struct kvm_vm *vm) > +void ucall_arch_uninit(struct kvm_vm *vm) > { > } > > @@ -44,27 +44,14 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, > return ret; > } > > -void ucall(uint64_t cmd, int nargs, ...) > +void ucall_arch_do_ucall(vm_vaddr_t uc) > { > - struct ucall uc = { > - .cmd = cmd, > - }; > - va_list va; > - int i; > - > - nargs = min(nargs, UCALL_MAX_ARGS); > - > - va_start(va, nargs); > - for (i = 0; i < nargs; ++i) > - uc.args[i] = va_arg(va, uint64_t); > - va_end(va); > - > sbi_ecall(KVM_RISCV_SELFTESTS_SBI_EXT, > KVM_RISCV_SELFTESTS_SBI_UCALL, > - (vm_vaddr_t)&uc, 0, 0, 0, 0, 0); > + uc, 0, 0, 0, 0, 0); > } > > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > { > struct kvm_run *run = vcpu->run; > struct ucall ucall = {}; > diff --git a/tools/testing/selftests/kvm/lib/s390x/ucall.c b/tools/testing/selftests/kvm/lib/s390x/ucall.c > index 73dc4e21190f..114cb4af295f 100644 > --- a/tools/testing/selftests/kvm/lib/s390x/ucall.c > +++ b/tools/testing/selftests/kvm/lib/s390x/ucall.c > @@ -6,34 +6,21 @@ > */ > #include "kvm_util.h" > > -void ucall_init(struct kvm_vm *vm, void *arg) > +void ucall_arch_init(struct kvm_vm *vm, void *arg) > { > } > > -void ucall_uninit(struct kvm_vm *vm) > +void ucall_arch_uninit(struct kvm_vm *vm) > { > } > > -void ucall(uint64_t cmd, int nargs, ...) > +void ucall_arch_do_ucall(vm_vaddr_t uc) > { > - struct ucall uc = { > - .cmd = cmd, > - }; > - va_list va; > - int i; > - > - nargs = min(nargs, UCALL_MAX_ARGS); > - > - va_start(va, nargs); > - for (i = 0; i < nargs; ++i) > - uc.args[i] = va_arg(va, uint64_t); > - va_end(va); > - > /* Exit via DIAGNOSE 0x501 (normally used for breakpoints) */ > - asm volatile ("diag 0,%0,0x501" : : "a"(&uc) : "memory"); > + asm volatile ("diag 0,%0,0x501" : : "a"(uc) : "memory"); > } > > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > { > struct kvm_run *run = vcpu->run; > struct ucall ucall = {}; > diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c > new file mode 100644 > index 000000000000..749ffdf23855 > --- /dev/null > +++ b/tools/testing/selftests/kvm/lib/ucall_common.c > @@ -0,0 +1,20 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +#include "kvm_util.h" > + > +void ucall(uint64_t cmd, int nargs, ...) > +{ > + struct ucall uc = { > + .cmd = cmd, > + }; > + va_list va; > + int i; > + > + nargs = min(nargs, UCALL_MAX_ARGS); > + > + va_start(va, nargs); > + for (i = 0; i < nargs; ++i) > + uc.args[i] = va_arg(va, uint64_t); > + va_end(va); > + > + ucall_arch_do_ucall((vm_vaddr_t)&uc); > +} > diff --git a/tools/testing/selftests/kvm/lib/x86_64/ucall.c b/tools/testing/selftests/kvm/lib/x86_64/ucall.c > index e5f0f9e0d3ee..9f532dba1003 100644 > --- a/tools/testing/selftests/kvm/lib/x86_64/ucall.c > +++ b/tools/testing/selftests/kvm/lib/x86_64/ucall.c > @@ -8,34 +8,21 @@ > > #define UCALL_PIO_PORT ((uint16_t)0x1000) > > -void ucall_init(struct kvm_vm *vm, void *arg) > +void ucall_arch_init(struct kvm_vm *vm, void *arg) > { > } > > -void ucall_uninit(struct kvm_vm *vm) > +void ucall_arch_uninit(struct kvm_vm *vm) > { > } > > -void ucall(uint64_t cmd, int nargs, ...) > +void ucall_arch_do_ucall(vm_vaddr_t uc) > { > - struct ucall uc = { > - .cmd = cmd, > - }; > - va_list va; > - int i; > - > - nargs = min(nargs, UCALL_MAX_ARGS); > - > - va_start(va, nargs); > - for (i = 0; i < nargs; ++i) > - uc.args[i] = va_arg(va, uint64_t); > - va_end(va); > - > asm volatile("in %[port], %%al" > - : : [port] "d" (UCALL_PIO_PORT), "D" (&uc) : "rax", "memory"); > + : : [port] "d" (UCALL_PIO_PORT), "D" (uc) : "rax", "memory"); > } > > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > { > struct kvm_run *run = vcpu->run; > struct ucall ucall = {}; _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BC0AC43334 for ; Mon, 20 Jun 2022 08:47:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id CE54C4B3B0; Mon, 20 Jun 2022 04:47:42 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@ibm.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jfzvh1w9jFwt; Mon, 20 Jun 2022 04:47:41 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 3F9CD4B374; Mon, 20 Jun 2022 04:47:41 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id A93B34B38B for ; Mon, 20 Jun 2022 03:40:09 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZQkNGaRh+7d7 for ; Mon, 20 Jun 2022 03:40:08 -0400 (EDT) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id DBAA04B281 for ; Mon, 20 Jun 2022 03:40:07 -0400 (EDT) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25K4lEg7017264; Mon, 20 Jun 2022 07:39:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=7cqLTU9P1Ro0Wdde+r9wJ+UtamNnbvbI+jmvk75qn34=; b=mjkUx6YN1YPZsmrPM/nAmw0GbmTV0oB/xGVwbdIuWE9YvF7d8Lk+u+IyJHKDT5CiHd2v cy2pNOJbqMb/QoCVcny28OvN8BxYUKp70l6vTeiwW8ZTnv4aoLL7qf/0KHz8OrBYqfCS Z16eWM6z4xkugZNOGg4vQcZ6gQrnc4EN1Tyw7ATMD64gdaZpvxIvVWkEcFHgrfp9JNIC jP4Cw/llGNSIHyxRUzbvim7oDNvR41Skd18CAzTc/rcOzvvBntsvEjSWsklAjapMope5 sWLCY1tgyCg2/KZAVaVVMGixTfAcFIgzBEmWFErI/hQo0dTYaQTKzlhu4qOKEqVvz6zw 1w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gsr0u9vhy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jun 2022 07:39:58 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 25K7JH3B018024; Mon, 20 Jun 2022 07:39:57 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gsr0u9vh1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jun 2022 07:39:57 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 25K7bFew009561; Mon, 20 Jun 2022 07:39:54 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma06ams.nl.ibm.com with ESMTP id 3gs5yhj44t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jun 2022 07:39:54 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 25K7dpqf18481508 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Jun 2022 07:39:51 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 764BC4203F; Mon, 20 Jun 2022 07:39:51 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7625842041; Mon, 20 Jun 2022 07:39:50 +0000 (GMT) Received: from [9.171.78.67] (unknown [9.171.78.67]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 20 Jun 2022 07:39:50 +0000 (GMT) Message-ID: <6518c2f2-476c-9f12-5a07-974af95a0b42@linux.ibm.com> Date: Mon, 20 Jun 2022 09:39:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH 1/3] KVM: selftests: Consolidate common code for popuplating ucall struct Content-Language: en-US To: Sean Christopherson , Paolo Bonzini , Marc Zyngier , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Janosch Frank , Claudio Imbrenda References: <20220618001618.1840806-1-seanjc@google.com> <20220618001618.1840806-2-seanjc@google.com> From: Christian Borntraeger In-Reply-To: <20220618001618.1840806-2-seanjc@google.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 3kMnldFGR4mx2uIIfYJ39jhAL3unWFq8 X-Proofpoint-ORIG-GUID: t79n4gkBCrUV_et_g7vpEmhdtxJM0A7F X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-20_05,2022-06-17_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 adultscore=0 priorityscore=1501 clxscore=1011 spamscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206200035 X-Mailman-Approved-At: Mon, 20 Jun 2022 04:47:39 -0400 Cc: kvm@vger.kernel.org, David Hildenbrand , linux-kernel@vger.kernel.org, Colton Lewis , kvm-riscv@lists.infradead.org, Atish Patra , linux-riscv@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu Am 18.06.22 um 02:16 schrieb Sean Christopherson: > Make ucall() a common helper that populates struct ucall, and only calls > into arch code to make the actually call out to userspace. > > Rename all arch-specific helpers to make it clear they're arch-specific, > and to avoid collisions with common helpers (one more on its way...) > > No functional change intended. > > Cc: Colton Lewis > Cc: Andrew Jones > Signed-off-by: Sean Christopherson seems to work on s390. Tested-by: Christian Borntraeger > --- > tools/testing/selftests/kvm/Makefile | 1 + > .../selftests/kvm/include/ucall_common.h | 23 ++++++++++++++++--- > .../testing/selftests/kvm/lib/aarch64/ucall.c | 23 ++++--------------- > tools/testing/selftests/kvm/lib/riscv/ucall.c | 23 ++++--------------- > tools/testing/selftests/kvm/lib/s390x/ucall.c | 23 ++++--------------- > .../testing/selftests/kvm/lib/ucall_common.c | 20 ++++++++++++++++ > .../testing/selftests/kvm/lib/x86_64/ucall.c | 23 ++++--------------- > 7 files changed, 61 insertions(+), 75 deletions(-) > create mode 100644 tools/testing/selftests/kvm/lib/ucall_common.c > > diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile > index b52c130f7b2f..bc2aee2af66c 100644 > --- a/tools/testing/selftests/kvm/Makefile > +++ b/tools/testing/selftests/kvm/Makefile > @@ -46,6 +46,7 @@ LIBKVM += lib/perf_test_util.c > LIBKVM += lib/rbtree.c > LIBKVM += lib/sparsebit.c > LIBKVM += lib/test_util.c > +LIBKVM += lib/ucall_common.c > > LIBKVM_x86_64 += lib/x86_64/apic.c > LIBKVM_x86_64 += lib/x86_64/handlers.S > diff --git a/tools/testing/selftests/kvm/include/ucall_common.h b/tools/testing/selftests/kvm/include/ucall_common.h > index 98562f685151..c6a4fd7fe443 100644 > --- a/tools/testing/selftests/kvm/include/ucall_common.h > +++ b/tools/testing/selftests/kvm/include/ucall_common.h > @@ -23,10 +23,27 @@ struct ucall { > uint64_t args[UCALL_MAX_ARGS]; > }; > > -void ucall_init(struct kvm_vm *vm, void *arg); > -void ucall_uninit(struct kvm_vm *vm); > +void ucall_arch_init(struct kvm_vm *vm, void *arg); > +void ucall_arch_uninit(struct kvm_vm *vm); > +void ucall_arch_do_ucall(vm_vaddr_t uc); > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc); > + > void ucall(uint64_t cmd, int nargs, ...); > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc); > + > +static inline void ucall_init(struct kvm_vm *vm, void *arg) > +{ > + ucall_arch_init(vm, arg); > +} > + > +static inline void ucall_uninit(struct kvm_vm *vm) > +{ > + ucall_arch_uninit(vm); > +} > + > +static inline uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +{ > + return ucall_arch_get_ucall(vcpu, uc); > +} > > #define GUEST_SYNC_ARGS(stage, arg1, arg2, arg3, arg4) \ > ucall(UCALL_SYNC, 6, "hello", stage, arg1, arg2, arg3, arg4) > diff --git a/tools/testing/selftests/kvm/lib/aarch64/ucall.c b/tools/testing/selftests/kvm/lib/aarch64/ucall.c > index 0b949ee06b5e..2de9fdd34159 100644 > --- a/tools/testing/selftests/kvm/lib/aarch64/ucall.c > +++ b/tools/testing/selftests/kvm/lib/aarch64/ucall.c > @@ -21,7 +21,7 @@ static bool ucall_mmio_init(struct kvm_vm *vm, vm_paddr_t gpa) > return true; > } > > -void ucall_init(struct kvm_vm *vm, void *arg) > +void ucall_arch_init(struct kvm_vm *vm, void *arg) > { > vm_paddr_t gpa, start, end, step, offset; > unsigned int bits; > @@ -64,31 +64,18 @@ void ucall_init(struct kvm_vm *vm, void *arg) > TEST_FAIL("Can't find a ucall mmio address"); > } > > -void ucall_uninit(struct kvm_vm *vm) > +void ucall_arch_uninit(struct kvm_vm *vm) > { > ucall_exit_mmio_addr = 0; > sync_global_to_guest(vm, ucall_exit_mmio_addr); > } > > -void ucall(uint64_t cmd, int nargs, ...) > +void ucall_arch_do_ucall(vm_vaddr_t uc) > { > - struct ucall uc = { > - .cmd = cmd, > - }; > - va_list va; > - int i; > - > - nargs = min(nargs, UCALL_MAX_ARGS); > - > - va_start(va, nargs); > - for (i = 0; i < nargs; ++i) > - uc.args[i] = va_arg(va, uint64_t); > - va_end(va); > - > - *ucall_exit_mmio_addr = (vm_vaddr_t)&uc; > + *ucall_exit_mmio_addr = uc; > } > > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > { > struct kvm_run *run = vcpu->run; > struct ucall ucall = {}; > diff --git a/tools/testing/selftests/kvm/lib/riscv/ucall.c b/tools/testing/selftests/kvm/lib/riscv/ucall.c > index 087b9740bc8f..b1598f418c1f 100644 > --- a/tools/testing/selftests/kvm/lib/riscv/ucall.c > +++ b/tools/testing/selftests/kvm/lib/riscv/ucall.c > @@ -10,11 +10,11 @@ > #include "kvm_util.h" > #include "processor.h" > > -void ucall_init(struct kvm_vm *vm, void *arg) > +void ucall_arch_init(struct kvm_vm *vm, void *arg) > { > } > > -void ucall_uninit(struct kvm_vm *vm) > +void ucall_arch_uninit(struct kvm_vm *vm) > { > } > > @@ -44,27 +44,14 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, > return ret; > } > > -void ucall(uint64_t cmd, int nargs, ...) > +void ucall_arch_do_ucall(vm_vaddr_t uc) > { > - struct ucall uc = { > - .cmd = cmd, > - }; > - va_list va; > - int i; > - > - nargs = min(nargs, UCALL_MAX_ARGS); > - > - va_start(va, nargs); > - for (i = 0; i < nargs; ++i) > - uc.args[i] = va_arg(va, uint64_t); > - va_end(va); > - > sbi_ecall(KVM_RISCV_SELFTESTS_SBI_EXT, > KVM_RISCV_SELFTESTS_SBI_UCALL, > - (vm_vaddr_t)&uc, 0, 0, 0, 0, 0); > + uc, 0, 0, 0, 0, 0); > } > > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > { > struct kvm_run *run = vcpu->run; > struct ucall ucall = {}; > diff --git a/tools/testing/selftests/kvm/lib/s390x/ucall.c b/tools/testing/selftests/kvm/lib/s390x/ucall.c > index 73dc4e21190f..114cb4af295f 100644 > --- a/tools/testing/selftests/kvm/lib/s390x/ucall.c > +++ b/tools/testing/selftests/kvm/lib/s390x/ucall.c > @@ -6,34 +6,21 @@ > */ > #include "kvm_util.h" > > -void ucall_init(struct kvm_vm *vm, void *arg) > +void ucall_arch_init(struct kvm_vm *vm, void *arg) > { > } > > -void ucall_uninit(struct kvm_vm *vm) > +void ucall_arch_uninit(struct kvm_vm *vm) > { > } > > -void ucall(uint64_t cmd, int nargs, ...) > +void ucall_arch_do_ucall(vm_vaddr_t uc) > { > - struct ucall uc = { > - .cmd = cmd, > - }; > - va_list va; > - int i; > - > - nargs = min(nargs, UCALL_MAX_ARGS); > - > - va_start(va, nargs); > - for (i = 0; i < nargs; ++i) > - uc.args[i] = va_arg(va, uint64_t); > - va_end(va); > - > /* Exit via DIAGNOSE 0x501 (normally used for breakpoints) */ > - asm volatile ("diag 0,%0,0x501" : : "a"(&uc) : "memory"); > + asm volatile ("diag 0,%0,0x501" : : "a"(uc) : "memory"); > } > > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > { > struct kvm_run *run = vcpu->run; > struct ucall ucall = {}; > diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c > new file mode 100644 > index 000000000000..749ffdf23855 > --- /dev/null > +++ b/tools/testing/selftests/kvm/lib/ucall_common.c > @@ -0,0 +1,20 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +#include "kvm_util.h" > + > +void ucall(uint64_t cmd, int nargs, ...) > +{ > + struct ucall uc = { > + .cmd = cmd, > + }; > + va_list va; > + int i; > + > + nargs = min(nargs, UCALL_MAX_ARGS); > + > + va_start(va, nargs); > + for (i = 0; i < nargs; ++i) > + uc.args[i] = va_arg(va, uint64_t); > + va_end(va); > + > + ucall_arch_do_ucall((vm_vaddr_t)&uc); > +} > diff --git a/tools/testing/selftests/kvm/lib/x86_64/ucall.c b/tools/testing/selftests/kvm/lib/x86_64/ucall.c > index e5f0f9e0d3ee..9f532dba1003 100644 > --- a/tools/testing/selftests/kvm/lib/x86_64/ucall.c > +++ b/tools/testing/selftests/kvm/lib/x86_64/ucall.c > @@ -8,34 +8,21 @@ > > #define UCALL_PIO_PORT ((uint16_t)0x1000) > > -void ucall_init(struct kvm_vm *vm, void *arg) > +void ucall_arch_init(struct kvm_vm *vm, void *arg) > { > } > > -void ucall_uninit(struct kvm_vm *vm) > +void ucall_arch_uninit(struct kvm_vm *vm) > { > } > > -void ucall(uint64_t cmd, int nargs, ...) > +void ucall_arch_do_ucall(vm_vaddr_t uc) > { > - struct ucall uc = { > - .cmd = cmd, > - }; > - va_list va; > - int i; > - > - nargs = min(nargs, UCALL_MAX_ARGS); > - > - va_start(va, nargs); > - for (i = 0; i < nargs; ++i) > - uc.args[i] = va_arg(va, uint64_t); > - va_end(va); > - > asm volatile("in %[port], %%al" > - : : [port] "d" (UCALL_PIO_PORT), "D" (&uc) : "rax", "memory"); > + : : [port] "d" (UCALL_PIO_PORT), "D" (uc) : "rax", "memory"); > } > > -uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > +uint64_t ucall_arch_get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > { > struct kvm_run *run = vcpu->run; > struct ucall ucall = {}; _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm