Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2566044imn; Tue, 2 Aug 2022 07:50:17 -0700 (PDT) X-Google-Smtp-Source: AA6agR4klOFULzbsLy48kMob4YZ1Amcpnh5/zoDjmXVYFZvNtCTUXWzvUGZvDuVP0cvm06KKsgwd X-Received: by 2002:a17:907:7d8c:b0:730:8be3:9615 with SMTP id oz12-20020a1709077d8c00b007308be39615mr6907728ejc.547.1659451817059; Tue, 02 Aug 2022 07:50:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659451817; cv=none; d=google.com; s=arc-20160816; b=Vf6JrpfB5s1ojvGjWC6aT4plo7dQ+jF1x4qCYZAfD8KOIxRjoRYiO5bJcbB/5dLHar YHmbjjtbgXryAtZXL7HO5fmM+MuQ5o8dGPO0Y27HDUwOGuvSGQuI0TPfE5wsU5Pl6Yds SAb6liWwxAC2a5WytORWRcvExgnrqcSNHqM8hoZf+srm+oUep90p9Q8srX3soy8jVGWA fs4xMubX+TkfV9Zjgmv2MotdO1JAEYEhnktsLnxbA4G5hPK8i1qcFS/BemRLrvGmDmoo WJLTlXCqJcprpQnfeiMp99Mg2YK8BHd9yNu0vRjWA6zYuQyXO9EisSluWn6uFi+nf9UN hyCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=27yyJkav5DwGufg9wksZxg7D5aoI0Py4PHOZi8o/OYQ=; b=JdSklWJJQvvk4kgQlogjF5B1yeX9UIWZNex4ViS7lo5zZvpsNq1Fy+k6ZWswq1dX8g 6jEPpZSfsDnAOkbIF0Jk7ZMVBbL/DBX2uN97m3q4jXxe11HPrfw1MkevNY8TqKEN/t0G 73FJrYmrJOcZL5rSQy5twwb/BCQq+hFXIhxusqAl4WcoKzgtXHvWd9iSuqLPebaBK5wj /aFx2BXcI+tDQjPYWDA37Uye/2D35yHX0z8Nf7JYxsIikzv92tVbWJZkW0b95pgTAIwX ZhElV79o96So47vMBffZfadCldpx7TPV4vNuoMyikuvwBO5iHQP2WP/yh09EF+fDu6gW EGCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="VpaP0g/d"; 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 cs19-20020a170906dc9300b00730729458d5si5971298ejc.687.2022.08.02.07.49.51; Tue, 02 Aug 2022 07:50:17 -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=20210112 header.b="VpaP0g/d"; 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 S236505AbiHBOpv (ORCPT + 99 others); Tue, 2 Aug 2022 10:45:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237028AbiHBOps (ORCPT ); Tue, 2 Aug 2022 10:45:48 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEC1B1EEC9 for ; Tue, 2 Aug 2022 07:45:46 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id e15so12240927lfs.0 for ; Tue, 02 Aug 2022 07:45:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=27yyJkav5DwGufg9wksZxg7D5aoI0Py4PHOZi8o/OYQ=; b=VpaP0g/dgKXcMOJg5Bd6Z1DzY2BOZrbupQuRtpOEUfBHWJL1JG58UeGx8WK70aD77N a7KN11WgzSchknrohYsphJFl9cPGx6kfSWW1+3wfuFJcO4qOu6LAveQSsjYh2wwG8JDr S4GNNU4P7wri7cTrH+1hUI5nwb+XLlF0sXZm9aoCFlg9GnpvZSekytPP3ecljJ0tcxvH gpvj78bCm3LqBkqmGu3DSGMHX6PqTQSEyFdgO7bgZ8eVf0iU2dKp5w4pEqxdbPpWzC9C hxpY/qUt4ck9ds1POdUC3no8v1XjpFabJ5ZtqBiw13nB5qj1n1j3NeO6lgjjdW3LRtzN 8T8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=27yyJkav5DwGufg9wksZxg7D5aoI0Py4PHOZi8o/OYQ=; b=ATyOnz7lT/cuCysGrPZnujgCIW/AET9Vc9EVjg1DNqOwbulGiGxsRrOtC30IApZC/S biT1ZTRB6+wm3zA2uwut1pxqfNN0jeHS+MKaHgDm72QJo/XFFvaZesOenSQgPdnYDdeJ tq6LIIQkaKVGd5xaHjXWbXnkpAk3490n6s+2MZQ1K8U9/HuMIBt/AZD1r5EvuDKkAHHU 36gmETBTbHt/XyUX6UFqDFXEyGXzPs5yE5ZBDOczpCFe1ThlnHovHanM+AEm+WA9R/mE OXsHxk+g14ATxHdkrv5q+Ga2YLseLVCDZwfeuS/O38vALJoei80dsyIX8gXXrtaQTgj1 W2aQ== X-Gm-Message-State: AJIora/2rQoxknxi51XvHAEtXlqXKpMe2XT63U0X/276BwrZVlgw38kK gviDoLZiOCJOfeJD2S/vPNevdNfljhAyTxPn5eu3/Q== X-Received: by 2002:a05:6512:12d6:b0:48a:acd8:7183 with SMTP id p22-20020a05651212d600b0048aacd87183mr7524996lfg.114.1659451544902; Tue, 02 Aug 2022 07:45:44 -0700 (PDT) MIME-Version: 1.0 References: <20220801201109.825284-1-pgonda@google.com> <20220801201109.825284-7-pgonda@google.com> <20220802100911.5kyfhxdavqtpddma@kamzik> In-Reply-To: <20220802100911.5kyfhxdavqtpddma@kamzik> From: Peter Gonda Date: Tue, 2 Aug 2022 08:45:33 -0600 Message-ID: Subject: Re: [V2 06/11] KVM: selftests: Consolidate common code for popuplating To: Andrew Jones Cc: kvm list , LKML , Marc Orr , Sean Christopherson , Michael Roth , "Lendacky, Thomas" , Joerg Roedel , Mingwei Zhang , Paolo Bonzini , Colton Lewis , Andrew Jones Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 2, 2022 at 4:09 AM Andrew Jones wrote: > > On Mon, Aug 01, 2022 at 01:11:04PM -0700, Peter Gonda wrote: > > From: 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. > > But there is... Yea my mistake. Looking at 9e2f6498efbbc it appears this optimization could happen on all the other archs given the same reasoning in the description "perhaps due to no immediate readers". What do you think about dropping the "No functional change intended" from this patch and moving the WRITE_ONCE() for the ops in the common ucall() code? > > > > > Cc: Colton Lewis > > Cc: Andrew Jones > > Signed-off-by: Sean Christopherson > > Signed-off-by: Peter Gonda > > --- > > tools/testing/selftests/kvm/Makefile | 1 + > > .../selftests/kvm/include/ucall_common.h | 23 ++++++++++++++++--- > > .../testing/selftests/kvm/lib/aarch64/ucall.c | 20 ++++------------ > > 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, 60 insertions(+), 73 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 690b499c3471..39fc5e8e5594 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 ee79d180e07e..5a85f5318bbe 100644 > > --- a/tools/testing/selftests/kvm/include/ucall_common.h > > +++ b/tools/testing/selftests/kvm/include/ucall_common.h > > @@ -24,10 +24,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 ed237b744690..1c81a6a5c1f2 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,30 +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 = {}; > > - va_list va; > > - int i; > > - > > - WRITE_ONCE(uc.cmd, cmd); > > - nargs = min(nargs, UCALL_MAX_ARGS); > > - > > - va_start(va, nargs); > > - for (i = 0; i < nargs; ++i) > > - WRITE_ONCE(uc.args[i], va_arg(va, uint64_t)); > > - va_end(va); > > - > > There are WRITE_ONCE's being used here... > > > WRITE_ONCE(*ucall_exit_mmio_addr, (vm_vaddr_t)&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); > > ...but not here. At least AArch64 needs them, see commit 9e2f6498efbb > ("selftests: KVM: Handle compiler optimizations in ucall") > > > + > > + 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 = {}; > > -- > > 2.37.1.455.g008518b4e5-goog > > > > Thanks, > drew