Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3304381ybl; Mon, 27 Jan 2020 01:12:46 -0800 (PST) X-Google-Smtp-Source: APXvYqxPtfqonwyHzSLSJysErH87OwUH0hymk1LzBKq78EDrP3fsnhHpKOjQHxYqEfH7LajlAFTZ X-Received: by 2002:aca:c494:: with SMTP id u142mr7064353oif.86.1580116366813; Mon, 27 Jan 2020 01:12:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580116366; cv=none; d=google.com; s=arc-20160816; b=aP0qq+UgtByRlwHfDC9P222G+3K83VZsMvaFhRerR7ltvk+fhmzQb+K0vvZUzSreMa lbq9gXW5RWXUJDNJdn9GfR+jCF5YOqeGgUetSB/STnyAtbum4MtQ64dVpu2aBK0pe2vM msDIYubeRJdxE2IzVwvFh7aPsgIUeVXs0AARfRFscghVqglsCTJlIqivXCookfqei7Bs BU0761Jw3dL3uHWfISQ6tOBLyt/sF1XGgrtJX/E2aw8SG2xKDCyQLylnf1bd/KY3kj1m 2U0vGTAtmjzLPMYY3zWtMkyvlm+/9yR/gp2WLh19QWHFvNrTc6Kv9S9DVFN+vwSTXGzX /Csg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=6xHjqcGoKCBGKlL3qdqNz6iPbD1SCDfAlhNTZTWBwQI=; b=dUJBq1QLEZ/O/OkfRrL52Ld6/C3o9WHLNb14jwk7X7TPwBrBTZxoyc7COe7N/bh79d m8jmxLxpA2evdj9FXWcP6OT3hlNFwqdGDMnlW7/AcvNBnZPePQUTyImB9NxgUhRRp6b0 wmFxKWXTyCTR9jyAbM7bNOA7w9kHmMJOcYXJEMG9LRd169aDBppEmc1PoYWH1okuOwfH QNuWIxm8SegrJd5rRUKIvsLttLlSYs296YARkQz4yUS5FfQIZx8o6vTe8dqNLhZP5dht QhYCa60kQslwudsY2TbHxzX9MBypPYdJBgk7eq39LR6ppQx0GqGBw6o6F9e5fDq5tZTX gz3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="TWYS4cP/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h7si5903473otm.165.2020.01.27.01.12.34; Mon, 27 Jan 2020 01:12:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="TWYS4cP/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729099AbgA0Iiu (ORCPT + 99 others); Mon, 27 Jan 2020 03:38:50 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:21545 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728668AbgA0Iiu (ORCPT ); Mon, 27 Jan 2020 03:38:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580114329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6xHjqcGoKCBGKlL3qdqNz6iPbD1SCDfAlhNTZTWBwQI=; b=TWYS4cP/nS2v41+Adw261lU6Vbh7Q790VDcyYD3Vbpfnw/QrGTCSue+yYXJEBo4OY3BhmN BD4XM00U+KpHLftRthcU1h+eFODahZ90w/5DGNJPq6fYap3P9TElz19gSj2ZVmEgmfTiR7 HnfMona5hDWkiQ1aknpHeQuXXO2ACqM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-16-7JGMZ4wYPHaLPIBsHxr0GA-1; Mon, 27 Jan 2020 03:38:47 -0500 X-MC-Unique: 7JGMZ4wYPHaLPIBsHxr0GA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AFC6D1800D41; Mon, 27 Jan 2020 08:38:45 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.43.2.160]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8CEA4863C5; Mon, 27 Jan 2020 08:38:41 +0000 (UTC) Date: Mon, 27 Jan 2020 09:38:38 +0100 From: Andrew Jones To: Paolo Bonzini Cc: Ben Gardon , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Cannon Matthews , Peter Xu , Peter Shier , Oliver Upton Subject: Re: [PATCH v4 06/10] KVM: selftests: Add support for vcpu_args_set to aarch64 and s390x Message-ID: <20200127083838.u32bylca2n4om6zx@kamzik.brq.redhat.com> References: <20200123180436.99487-1-bgardon@google.com> <20200123180436.99487-7-bgardon@google.com> <6061cd22-59bb-c191-bd98-f14d7cd274ae@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6061cd22-59bb-c191-bd98-f14d7cd274ae@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 25, 2020 at 10:34:16AM +0100, Paolo Bonzini wrote: > On 23/01/20 19:04, Ben Gardon wrote: > > Currently vcpu_args_set is only implemented for x86. This makes writing > > tests with multiple vCPUs difficult as each guest vCPU must either a.) > > do the same thing or b.) derive some kind of unique token from it's > > registers or the architecture. To simplify the process of writing tests > > with multiple vCPUs for s390 and aarch64, add set args functions for > > those architectures. > > > > Signed-off-by: Ben Gardon > > --- > > .../selftests/kvm/lib/aarch64/processor.c | 33 +++++++++++++++++ > > .../selftests/kvm/lib/s390x/processor.c | 35 +++++++++++++++++++ > > 2 files changed, 68 insertions(+) > > > > diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c > > index 86036a59a668e..a2ff90a75f326 100644 > > --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c > > +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c > > @@ -333,3 +333,36 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code) > > { > > aarch64_vcpu_add_default(vm, vcpuid, NULL, guest_code); > > } > > + > > +/* VM VCPU Args Set > > + * > > + * Input Args: > > + * vm - Virtual Machine > > + * vcpuid - VCPU ID > > + * num - number of arguments > > + * ... - arguments, each of type uint64_t > > + * > > + * Output Args: None > > + * > > + * Return: None > > + * > > + * Sets the first num function input arguments to the values > > + * given as variable args. Each of the variable args is expected to > > + * be of type uint64_t. The registers set by this function are r0-r7. > > + */ > > +void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...) > > +{ > > + va_list ap; > > + > > + TEST_ASSERT(num >= 1 && num <= 8, "Unsupported number of args,\n" > > + " num: %u\n", > > + num); > > + > > + va_start(ap, num); > > + > > + for (i = 0; i < num; i++) > > + set_reg(vm, vcpuid, ARM64_CORE_REG(regs.regs[num]), For AArch64 you also need to squash s/num/i/ for this line. (Plus I'm still not that pleased with adding this big header to this file for this function, or the weird line breaks in the assert.) > > + va_arg(ap, uint64_t)); > > + > > + va_end(ap); > > +} > > diff --git a/tools/testing/selftests/kvm/lib/s390x/processor.c b/tools/testing/selftests/kvm/lib/s390x/processor.c > > index 32a02360b1eb0..680f37be9dbc9 100644 > > --- a/tools/testing/selftests/kvm/lib/s390x/processor.c > > +++ b/tools/testing/selftests/kvm/lib/s390x/processor.c > > @@ -269,6 +269,41 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code) > > run->psw_addr = (uintptr_t)guest_code; > > } > > > > +/* VM VCPU Args Set > > + * > > + * Input Args: > > + * vm - Virtual Machine > > + * vcpuid - VCPU ID > > + * num - number of arguments > > + * ... - arguments, each of type uint64_t > > + * > > + * Output Args: None > > + * > > + * Return: None > > + * > > + * Sets the first num function input arguments to the values > > + * given as variable args. Each of the variable args is expected to > > + * be of type uint64_t. The registers set by this function are r2-r6. > > + */ > > +void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...) > > +{ > > + va_list ap; > > + struct kvm_regs regs; > > + > > + TEST_ASSERT(num >= 1 && num <= 5, "Unsupported number of args,\n" > > + " num: %u\n", > > + num); > > + > > + va_start(ap, num); > > + vcpu_regs_get(vm, vcpuid, ®s); > > + > > + for (i = 0; i < num; i++) > > + regs.gprs[i + 2] = va_arg(ap, uint64_t); > > + > > + vcpu_regs_set(vm, vcpuid, ®s); > > + va_end(ap); > > +} > > + > > void vcpu_dump(FILE *stream, struct kvm_vm *vm, uint32_t vcpuid, uint8_t indent) > > { > > struct vcpu *vcpu = vm->vcpu_head; > > > > Squashing this: > > diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c > index a2ff90a75f32..839a76c96f01 100644 > --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c > +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c > @@ -353,6 +353,7 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code) > void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...) > { > va_list ap; > + int i; > > TEST_ASSERT(num >= 1 && num <= 8, "Unsupported number of args,\n" > " num: %u\n", > diff --git a/tools/testing/selftests/kvm/lib/s390x/processor.c b/tools/testing/selftests/kvm/lib/s390x/processor.c > index 680f37be9dbc..a0b84235c848 100644 > --- a/tools/testing/selftests/kvm/lib/s390x/processor.c > +++ b/tools/testing/selftests/kvm/lib/s390x/processor.c > @@ -289,6 +289,7 @@ void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...) > { > va_list ap; > struct kvm_regs regs; > + int i; > > TEST_ASSERT(num >= 1 && num <= 5, "Unsupported number of args,\n" > " num: %u\n", > > Paolo >