Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp789526pxb; Thu, 25 Feb 2021 15:30:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMLr2NGjU35NhXRxlCa9UWe/1gIXuvbx+w5DiGUOpinjG4otTZySZzFf4LHyMewptNKcay X-Received: by 2002:a17:906:19c9:: with SMTP id h9mr74098ejd.288.1614295815974; Thu, 25 Feb 2021 15:30:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614295815; cv=none; d=google.com; s=arc-20160816; b=eegBfAp88dNWWMxMq35MfSlrTcybJhUU4tq4PdALXNNAMnOgsWbtaOGejyxOZFU8qV UBmuUHI3iUtpkBz6UKNYOTbb/UZv1BQul/yFdJaRRn3mxDaotnF4RToWbxUDjfal2y7R JX2bm7DD1euR1UH4+1B84tQPl3ooGa9sHFEuZOCr096g6ypTdiviAccTyA9Sxy6bpd1x Na4iMDtQPARdhzgKQuRQDaz3sjrWogdB7eP3Jato8hBddJjefrkhCRKaO2E9sDGwLkrt y0xBOZ3q2I5uL6ltl59S+W55kYSfIkL3G+dRXJegLEukEdJb+btYi+IgPiHIh7xt98hF 5oeQ== 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=5BVyJ8VvhMa5lHXCBOiQO5IyxOHW0ykPgLhaVVKuF7o=; b=FSsewYCqUqQljHpZQSlaLQ0Yw6iIk3t1xmVlihnMvRgZ/P87hGbMWQQwi4B4WkhSSI AL/hT0D8hMwtTgeMQWQEovVUbsG7cicHJQ+nzQyJxJOogmvwQ0zn54nSN1yIVPRebhis 8PxWqT6M57etE7V2km8PviPtwDXC2iuJWYePbZW8viIIMfGKkyTEr+TfVY3ZLxY4Shn9 Ko376YUNpNOj109vPqD9EpszEyd0cly7owDxvSNbUyv8tXYlVOF2xbrPts01DShXTiD6 52D9N4sN4hX8YvGfk3zzHiCur/gTuvQt+auck4WauiaCwLnhR1EOR6b2Fnj6M65F2ERT rQ/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=UWBdQmX5; 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 e6si4811250edz.98.2021.02.25.15.29.53; Thu, 25 Feb 2021 15:30:15 -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=UWBdQmX5; 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 S232296AbhBYX2J (ORCPT + 99 others); Thu, 25 Feb 2021 18:28:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231925AbhBYX2C (ORCPT ); Thu, 25 Feb 2021 18:28:02 -0500 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B327C06178A for ; Thu, 25 Feb 2021 15:27:13 -0800 (PST) Received: by mail-io1-xd2b.google.com with SMTP id p16so7805437ioj.4 for ; Thu, 25 Feb 2021 15:27:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5BVyJ8VvhMa5lHXCBOiQO5IyxOHW0ykPgLhaVVKuF7o=; b=UWBdQmX5mxAijUdurfYOQi6c43opvi1a/wi/+4KyyiHnJJSuhXhjNw9bYkLjqtkxAs vGiJ8MhFQKJ9R0mZ0SxqK1g6dO98KHuEjnrvyhhYaZPQT4+aEocJAmoL4I2Xk8Gohcjc qVh2FHH2skEnlBFGnTtXAiStbuFid709J4jHNahXQxocrUXTLcwNI5rjUZEBY8Pswxq5 LEta9r9H5PHla4jnN4W7I2fatYYsf5emIp+5DRJt63xeOdoGGTrkIt6uFhtLbmM44TiB ixQap30K4R0vg3a19ZXZBjIXE2cflvXK/dCudrVp159dl07OXVp8tM2YaqM6PbVX4otY 4lmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5BVyJ8VvhMa5lHXCBOiQO5IyxOHW0ykPgLhaVVKuF7o=; b=b0SgBLz7oOERoK2jNBY2JodcFZf79WX+z8+61cK1L3kq7Ir33Zj1uk2zR+E/AlxZux RszoRJBNLEOvzzeQJxnj1lQ/aIa9HdpsHPtuC00J+fQnVUOv4FdPw4VdsK53rFagZ3Ms CAo42oBlOE3JPm2LiIPb5aGF9IIIb9X5HWl+vUwPrCj2s8P1OmvsYupxEuTjzHiGOWnJ n0qcIkb9UbNsX5JTVwfClXVppsdbcFGUrMQb+5Zb/4W2kySGwuXgsxJRleeKh8/NOwe8 zl0TfTSyEUZL3XPFwItZwIjnWr+w1C3NRBLhz+vpRjoxuuMEPkbkvSGPeRuJoufGYGQJ 2/Cw== X-Gm-Message-State: AOAM532128iycrHX4CwIGOYUIkAuAOuGa12v586Sx1zCtz+zfhyR9+mb d+DjkQiTBEGek3yiEi9bFIp4ygAndzIRENdlaJgXpg== X-Received: by 2002:a02:30cb:: with SMTP id q194mr159018jaq.57.1614295632018; Thu, 25 Feb 2021 15:27:12 -0800 (PST) MIME-Version: 1.0 References: <20210225055940.18748-1-wangyanan55@huawei.com> <20210225055940.18748-5-wangyanan55@huawei.com> In-Reply-To: <20210225055940.18748-5-wangyanan55@huawei.com> From: Ben Gardon Date: Thu, 25 Feb 2021 15:27:00 -0800 Message-ID: Subject: Re: [RFC PATCH v2 4/7] KVM: selftests: Add a helper to get system configured THP page size To: Yanan Wang Cc: kvm , linux-kselftest@vger.kernel.org, LKML , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Arnaldo Carvalho de Melo , Ingo Molnar , Andrew Jones , Peter Xu , Marc Zyngier , wanghaibin.wang@huawei.com, yuzenghui@huawei.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 24, 2021 at 10:00 PM Yanan Wang wrote: > > If we want to have some tests about transparent hugepages, the system > configured THP hugepage size should better be known by the tests, which > can be used for kinds of alignment or guest memory accessing of vcpus... > So it makes sense to add a helper to get the transparent hugepage size. > > With VM_MEM_SRC_ANONYMOUS_THP specified in vm_userspace_mem_region_add(), > we now stat /sys/kernel/mm/transparent_hugepage to check whether THP is > configured in the host kernel before madvise(). Based on this, we can also > read file /sys/kernel/mm/transparent_hugepage/hpage_pmd_size to get THP > hugepage size. > > Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon > --- > .../testing/selftests/kvm/include/test_util.h | 2 ++ > tools/testing/selftests/kvm/lib/test_util.c | 36 +++++++++++++++++++ > 2 files changed, 38 insertions(+) > > diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h > index b7f41399f22c..ef24c76ba89a 100644 > --- a/tools/testing/selftests/kvm/include/test_util.h > +++ b/tools/testing/selftests/kvm/include/test_util.h > @@ -78,6 +78,8 @@ struct vm_mem_backing_src_alias { > enum vm_mem_backing_src_type type; > }; > > +bool thp_configured(void); > +size_t get_trans_hugepagesz(void); > void backing_src_help(void); > enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name); > > diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c > index c7c0627c6842..f2d133f76c67 100644 > --- a/tools/testing/selftests/kvm/lib/test_util.c > +++ b/tools/testing/selftests/kvm/lib/test_util.c > @@ -10,6 +10,7 @@ > #include > #include > #include > +#include > #include "linux/kernel.h" > > #include "test_util.h" > @@ -117,6 +118,41 @@ const struct vm_mem_backing_src_alias backing_src_aliases[] = { > {"anonymous_hugetlb", VM_MEM_SRC_ANONYMOUS_HUGETLB,}, > }; > > +bool thp_configured(void) > +{ > + int ret; > + struct stat statbuf; > + > + ret = stat("/sys/kernel/mm/transparent_hugepage", &statbuf); > + TEST_ASSERT(ret == 0 || (ret == -1 && errno == ENOENT), > + "Error in stating /sys/kernel/mm/transparent_hugepage: %d", > + errno); > + > + return ret == 0; > +} > + > +size_t get_trans_hugepagesz(void) > +{ > + size_t size; > + char buf[16]; > + FILE *f; > + > + TEST_ASSERT(thp_configured(), "THP is not configured in host kernel"); > + > + f = fopen("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size", "r"); > + TEST_ASSERT(f != NULL, > + "Error in opening transparent_hugepage/hpage_pmd_size: %d", > + errno); > + > + if (fread(buf, sizeof(char), sizeof(buf), f) == 0) { > + fclose(f); > + TEST_FAIL("Unable to read transparent_hugepage/hpage_pmd_size"); > + } > + > + size = strtoull(buf, NULL, 10); > + return size; > +} > + > void backing_src_help(void) > { > int i; > -- > 2.19.1 >