Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4241266pxb; Mon, 8 Feb 2021 11:13:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxSWPdgvwRy7LSiC37hRgjSNSeO0arMOBgDxA1laV0kLyy/LRie3QXERy4v+qxu65wlS232 X-Received: by 2002:a17:906:d935:: with SMTP id rn21mr18516767ejb.443.1612811596941; Mon, 08 Feb 2021 11:13:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612811596; cv=none; d=google.com; s=arc-20160816; b=i2nVgPsOmD/52YJS6maL90micBsnq9YbRLFuR0T2c2a8kBVMMSu5yX/9BfoL+RzSgh b8pVTfqoDF4rp5tV5AW/T9pfhB9/OMmtZZRBNju5zoVci2lUqs99MRIa6D2b0wtGqA5W yTUCcOeDFZZouAEDmhv78pfoULy7rppkUrSox961AJd7g7mSQK+MMmx70VAFwNUaPUHq HyucPKOp9e/88TgR6jF21G9qrC8TZIEBN6KOyIlkesYFtahFNgCX9oRiTgLBsPE2ykwh FobJHoYe18fmWQUJyc7L3coFkNTuhS+ON11MLcI7lXHI3uwsh+u/tcMyVCZ4tgV/wgs/ gVXQ== 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=RxLUe7o0XBsEMnyZ2ayM5Zt5mnJyMnV0qymbKsVL5xI=; b=d1a+aO6Ueq03V9lHbVF/BDDxX0/2FkJZJ6lz5EmX2gyfQ8SHyhzdz6IBHnrn6Ya4f6 4MjbJIi9/SX8+sb/rNpwCINCGApGnv1tM3Tn2U/eFAUNffmMRg35pwFw4tCs40c4ffMJ Q7GDuiHm6/LXpm0SUhRmcLdw0cweqZ6hTNF5HwCa+N1OmvD5XU/aWhrG7CTirXp0dcPO NvTJDT4XhitoO0x6nlkFhkWUlyEGixeRPqk4Zwu0UUIIIdya2gRPPDGL1G3bKYD1JycD LNtXCk2DeALqylrXPdTHnPfzDWAUSIayfpHIEHWMfuM4F3fxnvW6QdNIRZA2GHs0GOZQ MJRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Fl/ILLaQ"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f8si12825371edw.351.2021.02.08.11.12.52; Mon, 08 Feb 2021 11:13:16 -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=@google.com header.s=20161025 header.b="Fl/ILLaQ"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235904AbhBHTMT (ORCPT + 99 others); Mon, 8 Feb 2021 14:12:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233420AbhBHRvz (ORCPT ); Mon, 8 Feb 2021 12:51:55 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A30FC061788 for ; Mon, 8 Feb 2021 09:43:36 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id u143so3952690pfc.7 for ; Mon, 08 Feb 2021 09:43:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=RxLUe7o0XBsEMnyZ2ayM5Zt5mnJyMnV0qymbKsVL5xI=; b=Fl/ILLaQ27dYD+8sqFnFsVrXGNE10dTiegetvaiJTd8Yx6XriE47wKym0jVJrTwrHf BmXGbYYJjosrvsmaLpdY3H9q8eF58k8PP1WFfWPi2qffZgrb0bNsvXa+VX5kf/QlqCkg zW4C1Pgh1YcHlMdx2FTREafj2nwr2qb8xCxF5CC0JuF7pQad93EkK6uHwL4TQ0IkiiDw FJr4HH2jpQqHubAZoiIhJicivZ4xX7kULKs7IFpO3L7Vq8FbOv9flC917FeP7y19cUoB 3oGKpOxnPKNDCLpYb9Q629nRD1dx2AcBjTiqkhi/qvw1ElSP4jICnl2jLeWyNUPnju0P Zh+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=RxLUe7o0XBsEMnyZ2ayM5Zt5mnJyMnV0qymbKsVL5xI=; b=d9dP3OPB+oqSvoQ9C7IRqeHeBUmjsbRgmIpHkJx3yZTbO8KMD/Pt1f71P/uB2lqyJF TtA+uKJdQPbXwQkS4mEoZ+urqsErGSpyeoURYZCz7F1w5K7iBxHAC42lCDGXDZG4hPXh 5zVX/nIEG7fL3kQxMxaisfolay+CVDQwTumGBGjyDYvSIbjX5tTRhMTbsEg6LwspQtlc 1rLaSFiqQ1R3wYZly5ibacCwsI3wRAB2u0VhfRJVcH5XRHsLu/v59tzgk7DVJT2pgTMA vNCnX5JsaxIiQxLGlEFGudu2ovKreX6hgyyvyFysf2eCIUptpD+HUmusiBFCOw8UTt4n z3jQ== X-Gm-Message-State: AOAM532KqDs0Q9sdJxZxogKkVx87qw2V3vm1iNmFwaOKr3vr4/zWJC1A vna9inCJNqnpMkBthbkCAFbV5A== X-Received: by 2002:a62:8cd7:0:b029:1d9:447c:e21a with SMTP id m206-20020a628cd70000b02901d9447ce21amr14414194pfd.2.1612806215874; Mon, 08 Feb 2021 09:43:35 -0800 (PST) Received: from google.com ([2620:15c:f:10:e4db:abc1:a5c0:9dbc]) by smtp.gmail.com with ESMTPSA id c18sm9730201pfo.171.2021.02.08.09.43.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 09:43:35 -0800 (PST) Date: Mon, 8 Feb 2021 09:43:28 -0800 From: Sean Christopherson To: Yanan Wang Cc: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Shuah Khan , Andrew Jones , Marc Zyngier , Ben Gardon , Peter Xu , Aaron Lewis , Vitaly Kuznetsov , wanghaibin.wang@huawei.com, yuzenghui@huawei.com Subject: Re: [RFC PATCH 1/2] KVM: selftests: Add a macro to get string of vm_mem_backing_src_type Message-ID: References: <20210208090841.333724-1-wangyanan55@huawei.com> <20210208090841.333724-2-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210208090841.333724-2-wangyanan55@huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 08, 2021, Yanan Wang wrote: > Add a macro to get string of the backing source memory type, so that > application can add choices for source types in the help() function, > and users can specify which type to use for testing. > > Signed-off-by: Yanan Wang > --- > tools/testing/selftests/kvm/include/kvm_util.h | 3 +++ > tools/testing/selftests/kvm/lib/kvm_util.c | 8 ++++++++ > 2 files changed, 11 insertions(+) > > diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h > index 5cbb861525ed..f5fc29dc9ee6 100644 > --- a/tools/testing/selftests/kvm/include/kvm_util.h > +++ b/tools/testing/selftests/kvm/include/kvm_util.h > @@ -69,7 +69,9 @@ enum vm_guest_mode { > #define PTES_PER_MIN_PAGE ptes_per_page(MIN_PAGE_SIZE) > > #define vm_guest_mode_string(m) vm_guest_mode_string[m] > +#define vm_mem_backing_src_type_string(s) vm_mem_backing_src_type_string[s] Oof, I see this is just following vm_guest_mode_string. IMO, defining the string to look like a function is unnecessary and rather mean. > extern const char * const vm_guest_mode_string[]; > +extern const char * const vm_mem_backing_src_type_string[]; > > struct vm_guest_mode_params { > unsigned int pa_bits; > @@ -83,6 +85,7 @@ enum vm_mem_backing_src_type { > VM_MEM_SRC_ANONYMOUS, > VM_MEM_SRC_ANONYMOUS_THP, > VM_MEM_SRC_ANONYMOUS_HUGETLB, > + NUM_VM_BACKING_SRC_TYPES, > }; > > int kvm_check_cap(long cap); > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c > index fa5a90e6c6f0..a9b651c7f866 100644 > --- a/tools/testing/selftests/kvm/lib/kvm_util.c > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c > @@ -165,6 +165,14 @@ const struct vm_guest_mode_params vm_guest_mode_params[] = { > _Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) == NUM_VM_MODES, > "Missing new mode params?"); > > +const char * const vm_mem_backing_src_type_string[] = { A shorter name would be nice, though I don't have a good suggestion. > + "VM_MEM_SRC_ANONYMOUS ", > + "VM_MEM_SRC_ANONYMOUS_THP ", > + "VM_MEM_SRC_ANONYMOUS_HUGETLB", It'd be more robust to explicitly assign indices, that way tweaks to vm_mem_backing_src_type won't cause silent breakage. Ditto for the existing vm_guest_mode_string. E.g. I think something like this would work (completely untested) const char *vm_guest_mode_string(int 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); return strings[i]; } > +}; > +_Static_assert(sizeof(vm_mem_backing_src_type_string)/sizeof(char *) == NUM_VM_BACKING_SRC_TYPES, > + "Missing new source type strings?"); > + > /* > * VM Create > * > -- > 2.23.0 >