Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp635284pxb; Thu, 25 Feb 2021 11:00:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzA21ysY6YXIFCZdZwS0cP0akXyPF6t/L9xyhtAqLH9gc0749bZ5mZJHU6yj0t9OmFT/2Nl X-Received: by 2002:a05:6402:1750:: with SMTP id v16mr4690464edx.54.1614279657283; Thu, 25 Feb 2021 11:00:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614279657; cv=none; d=google.com; s=arc-20160816; b=FCm1eeUHlqOAh8AohKiwgZWuoCy3I83003cCWfgTfLWwoIQXy54O/IaF/g6qMUaR4T nDVdwyXtzVh0ITLa4Ble/80b1VUz3Zu4Oz0WYJ/GQpEg1po8+S0sjFE18TXwSmkzfxRK uBVlctkEZCUGfWRzXPTgqBGOSeH9oJJD3/Tswg7bRBrRsmvucqaOWIhzs7Dx4IjGwmfA 9W/FdvjGgxSqJMzDZYXX0s9GA5zmHGDnmbxSwwjR3isLcbpZsY0l7VxWZimW5pR76uP4 GXmi68m7F/0RjiGX9NxJsFXJVlxs3bds9xsIcK2YdNXFjvZA40NOfAsU2JUYsGYWX2YV /tcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=V2KuMziu842JMfiM/AqGMgt14XmhOnxGCT/IAIzioz4=; b=WvmTYTtmGGhGg1erRfoSPvzJ0IBeGW6XxsNszBWFWlR5QZ9uVA0uOAZccE1Z/3a+Wd NmlaN2Jpgx6Jg0e2rm6THXEaxKk51nDu909aToTV/YgJeosXSuFaGk0JZy/GmFcleg75 ED6r11NWjThw6yjYzRZjRARt3FFDL4ZqZM6/hYyy5/CJt9AJJ+FbMrGDRVr3V2QBr8wh sMnhoRNXmidB2ZAQ/qgUTwdkDphyiyu1rzdNrxk8hiXbgyszDwtcKtGz21deTWvCLZq1 gJfFQeJFo7lvbOYwqmeI0c89B268XiNXkzzvaHYJScqjRYE1WolnS0883cykrofV5UIK 6VYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gU2Bqgbn; spf=pass (google.com: 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q18si3797606ejm.178.2021.02.25.11.00.32; Thu, 25 Feb 2021 11:00:57 -0800 (PST) Received-SPF: pass (google.com: 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gU2Bqgbn; spf=pass (google.com: 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233121AbhBYS5S (ORCPT + 99 others); Thu, 25 Feb 2021 13:57:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46670 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbhBYS4w (ORCPT ); Thu, 25 Feb 2021 13:56:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614279325; 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=V2KuMziu842JMfiM/AqGMgt14XmhOnxGCT/IAIzioz4=; b=gU2BqgbntiNhgBncilt+huDXgjrG7on6rRMauWP2o1vwM5Dc9KHU3JCQvmhDJWfOxub5WW 4SzML5WMQMzGKWi2iZqc5t9GHQs52VcEtAV24VmgNsTcvjNDYTKNkV7KoNQtP6J3N4S1wr hXwQP5p/YmhgiawVtknxu54MOfkb63Q= 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-94-lUrrAByYOcuxgzJK52RQTg-1; Thu, 25 Feb 2021 13:55:23 -0500 X-MC-Unique: lUrrAByYOcuxgzJK52RQTg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7CFC01083E8F; Thu, 25 Feb 2021 18:55:21 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.194.200]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 729D860C16; Thu, 25 Feb 2021 18:55:09 +0000 (UTC) Date: Thu, 25 Feb 2021 19:55:06 +0100 From: Andrew Jones To: Yanan Wang Cc: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Ben Gardon , Sean Christopherson , Vitaly Kuznetsov , Arnaldo Carvalho de Melo , Ingo Molnar , Peter Xu , Marc Zyngier , wanghaibin.wang@huawei.com, yuzenghui@huawei.com Subject: Re: [RFC PATCH v2 3/7] KVM: selftests: Make a generic helper to get vm guest mode strings Message-ID: <20210225185506.r54k2z6e6xual7ag@kamzik.brq.redhat.com> References: <20210225055940.18748-1-wangyanan55@huawei.com> <20210225055940.18748-4-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210225055940.18748-4-wangyanan55@huawei.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 25, 2021 at 01:59:36PM +0800, Yanan Wang wrote: > For generality and conciseness, make an API which can be used in all > kvm libs and selftests to get vm guest mode strings. And the index i > is checked in the API in case of possiable faults. > > Signed-off-by: Yanan Wang > --- > .../testing/selftests/kvm/include/kvm_util.h | 4 +-- > tools/testing/selftests/kvm/lib/kvm_util.c | 29 ++++++++++++------- > 2 files changed, 19 insertions(+), 14 deletions(-) > > diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h > index 2d7eb6989e83..f52a7492f47f 100644 > --- a/tools/testing/selftests/kvm/include/kvm_util.h > +++ b/tools/testing/selftests/kvm/include/kvm_util.h > @@ -68,9 +68,6 @@ enum vm_guest_mode { > #define MIN_PAGE_SIZE (1U << MIN_PAGE_SHIFT) > #define PTES_PER_MIN_PAGE ptes_per_page(MIN_PAGE_SIZE) > > -#define vm_guest_mode_string(m) vm_guest_mode_string[m] > -extern const char * const vm_guest_mode_string[]; > - > struct vm_guest_mode_params { > unsigned int pa_bits; > unsigned int va_bits; > @@ -84,6 +81,7 @@ int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap); > int vcpu_enable_cap(struct kvm_vm *vm, uint32_t vcpu_id, > struct kvm_enable_cap *cap); > void vm_enable_dirty_ring(struct kvm_vm *vm, uint32_t ring_size); > +const char *vm_guest_mode_string(uint32_t i); > > struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm); > void kvm_vm_free(struct kvm_vm *vmp); > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c > index d787cb802b4a..cc22c4ab7d67 100644 > --- a/tools/testing/selftests/kvm/lib/kvm_util.c > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c > @@ -141,17 +141,24 @@ static void vm_open(struct kvm_vm *vm, int perm) > "rc: %i errno: %i", vm->fd, errno); > } > > -const char * const vm_guest_mode_string[] = { > - "PA-bits:52, VA-bits:48, 4K pages", > - "PA-bits:52, VA-bits:48, 64K pages", > - "PA-bits:48, VA-bits:48, 4K pages", > - "PA-bits:48, VA-bits:48, 64K pages", > - "PA-bits:40, VA-bits:48, 4K pages", > - "PA-bits:40, VA-bits:48, 64K pages", > - "PA-bits:ANY, VA-bits:48, 4K pages", > -}; > -_Static_assert(sizeof(vm_guest_mode_string)/sizeof(char *) == NUM_VM_MODES, > - "Missing new mode strings?"); > +const char *vm_guest_mode_string(uint32_t i) > +{ > + static const char * const strings[] = { > + [VM_MODE_P52V48_4K] = "PA-bits:52, VA-bits:48, 4K pages", > + [VM_MODE_P52V48_64K] = "PA-bits:52, VA-bits:48, 64K pages", > + [VM_MODE_P48V48_4K] = "PA-bits:48, VA-bits:48, 4K pages", > + [VM_MODE_P48V48_64K] = "PA-bits:48, VA-bits:48, 64K pages", > + [VM_MODE_P40V48_4K] = "PA-bits:40, VA-bits:48, 4K pages", > + [VM_MODE_P40V48_64K] = "PA-bits:40, VA-bits:48, 64K pages", > + [VM_MODE_PXXV48_4K] = "PA-bits:ANY, VA-bits:48, 4K pages", > + }; > + _Static_assert(sizeof(strings)/sizeof(char *) == NUM_VM_MODES, > + "Missing new mode strings?"); > + > + TEST_ASSERT(i < NUM_VM_MODES, "Guest mode ID %d too big", i); > + > + return strings[i]; > +} > > const struct vm_guest_mode_params vm_guest_mode_params[] = { > { 52, 48, 0x1000, 12 }, > -- > 2.19.1 > Reviewed-by: Andrew Jones