Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp30531ybb; Tue, 14 Apr 2020 18:12:06 -0700 (PDT) X-Google-Smtp-Source: APiQypKClASuwnpy9cGfbd8xXOE2MTXvaw+0Yxq2rCwfDdQTsDsh7aJ9IMTOJZnIcp6JAiF272gT X-Received: by 2002:a50:a68a:: with SMTP id e10mr23476062edc.317.1586913126052; Tue, 14 Apr 2020 18:12:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586913126; cv=none; d=google.com; s=arc-20160816; b=R2h/Jhc0WbOSo3s1XFkuHv08dX6NWA3+LutJz3m/549gdq/srFekZ8G/7b2ToFAQr7 VgUjEx2g3qxc4KsQj1uf8os+ajqGxGdlqecyWhzjsrd8Eu3VS7xXenldJLiuSYhidV5I svKFtlzT7SCwC+tbdzlJGxCAfz89TfHbVZ0C52TeE0EzEfz2LmiNfyZRFpr71uYvVdPl cl4HndzjBarXjSN163P8nC1IpWH5VCX6nPr0c1ThMvplPp+tNvJk29oPDvjBKj1r3yvR 7IdSU7hRoAtgYMSNom4TjQIg+Ir4pycoL9cNNW/32HTNIsBdJ9/A7ttjP4XOgLp0GqCr eBnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=1OaVhKjpCz+9f+2NYjDTwK0uXCqgFR8DKieuYPxNgo0=; b=Dwq3L8YQfhH/44wtVJLgkbDdBdXm1T1NEQ7gmSE4oWm/n2iUs9JmYvrFSoqMB5hmFe Sm7QnUtQcgBGHFCCkzAOkagfuZmbrC59HGuZxzcb1BD6eSPx/S2eUMb7cSwaiaQKbzFW TZkkiBj2fCCt3QmfVHL12dphp4m9WVFNyyUhPbusDEEuNex//a2bkzfaGtWkp7hesRSl +moFIYRd7sIfUjvagIlGx7GZGnobvXToQwHpY9wt26/83hKern81HsuOnKvjcKwT5z5x TqCvBP/jiYhFp7gTQEi2HPC/PJ79zoPn5iQ+3jZrmAmDSMilFhucOx31dJgVW8KyM7XX ZNkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cm28si4410341edb.404.2020.04.14.18.11.43; Tue, 14 Apr 2020 18:12:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389035AbgDMV1B (ORCPT + 99 others); Mon, 13 Apr 2020 17:27:01 -0400 Received: from mga14.intel.com ([192.55.52.115]:40070 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388994AbgDMV1A (ORCPT ); Mon, 13 Apr 2020 17:27:00 -0400 IronPort-SDR: tNOI4xhA1VF6iW4XLnh7bEQzYvq2Mf4FsSLDogheVyL7e2n6hp3rvF9X5ug+fDRGY78bqWOdLJ Uo9SD8WkDXnQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2020 14:26:59 -0700 IronPort-SDR: zUxMGEWh0rWRWpxXiFP85EcDCZiCPVAcwHH4tIFkxEFM8GWog7ANF4QPqUo2JM/MxjxZe8TOlG CqrkQ6O+ot4Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,380,1580803200"; d="scan'208";a="252999630" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.202]) by orsmga003.jf.intel.com with ESMTP; 13 Apr 2020 14:26:59 -0700 Date: Mon, 13 Apr 2020 14:26:59 -0700 From: Sean Christopherson To: Wainer dos Santos Moschetta Cc: Paolo Bonzini , Christian Borntraeger , Janosch Frank , David Hildenbrand , Cornelia Huck , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Andrew Jones Subject: Re: [PATCH 01/10] KVM: selftests: Take vcpu pointer instead of id in vm_vcpu_rm() Message-ID: <20200413212659.GB21204@linux.intel.com> References: <20200410231707.7128-1-sean.j.christopherson@intel.com> <20200410231707.7128-2-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 13, 2020 at 03:26:55PM -0300, Wainer dos Santos Moschetta wrote: > > On 4/10/20 8:16 PM, Sean Christopherson wrote: > >The sole caller of vm_vcpu_rm() already has the vcpu pointer, take it > >directly instead of doing an extra lookup. > > > Most of (if not all) vcpu related functions in kvm_util.c receives an id, so > this change creates an inconsistency. Ya, but taking the id is done out of "necessity", as everything is public and for whatever reason the design of the selftest framework is to not expose 'struct vcpu' outside of the utils. vm_vcpu_rm() is internal only, IMO pulling the id out of the vcpu just to lookup the same vcpu is a waste of time. FWIW, I think the whole vcpuid thing is a bad interface, almost all the tests end up defining an arbitrary number for the sole VCPU_ID, i.e. the vcpuid interface just adds a pointless layer of obfuscation. I haven't looked through all the tests, but returning the vcpu and making the struct opaque, same as kvm_vm, seems like it would yield more readable code with less overhead. While I'm on a soapbox, hiding 'struct vcpu' and 'struct kvm_vm' also seems rather silly, but at least that doesn't directly lead to funky code. > Disregarding the above comment, the changes look good to me. So: > > Reviewed-by: Wainer dos Santos Moschetta > > > > > >Signed-off-by: Sean Christopherson > >--- > > tools/testing/selftests/kvm/lib/kvm_util.c | 7 +++---- > > 1 file changed, 3 insertions(+), 4 deletions(-) > > > >diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c > >index 8a3523d4434f..9a783c20dd26 100644 > >--- a/tools/testing/selftests/kvm/lib/kvm_util.c > >+++ b/tools/testing/selftests/kvm/lib/kvm_util.c > >@@ -393,7 +393,7 @@ struct vcpu *vcpu_find(struct kvm_vm *vm, uint32_t vcpuid) > > * > > * Input Args: > > * vm - Virtual Machine > >- * vcpuid - VCPU ID > >+ * vcpu - VCPU to remove > > * > > * Output Args: None > > * > >@@ -401,9 +401,8 @@ struct vcpu *vcpu_find(struct kvm_vm *vm, uint32_t vcpuid) > > * > > * Within the VM specified by vm, removes the VCPU given by vcpuid. > > */ > >-static void vm_vcpu_rm(struct kvm_vm *vm, uint32_t vcpuid) > >+static void vm_vcpu_rm(struct kvm_vm *vm, struct vcpu *vcpu) > > { > >- struct vcpu *vcpu = vcpu_find(vm, vcpuid); > > int ret; > > ret = munmap(vcpu->state, sizeof(*vcpu->state)); > >@@ -427,7 +426,7 @@ void kvm_vm_release(struct kvm_vm *vmp) > > int ret; > > while (vmp->vcpu_head) > >- vm_vcpu_rm(vmp, vmp->vcpu_head->id); > >+ vm_vcpu_rm(vmp, vmp->vcpu_head); > > ret = close(vmp->fd); > > TEST_ASSERT(ret == 0, "Close of vm fd failed,\n" >