From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D3C446D56E for ; Tue, 18 Aug 2026 12:49:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787057366; cv=none; b=hRBD5N3pb/aMw7nKVsN6Bi5bRZ78H8M1nkHjceilACSSfflUV4Q6hmQSZITRMCIjjSx11soKvGvuG7Q0I6y53r/vcP6wgDQBM5gTfbDVOScsHlbRfsC7/OXPAQMgtILd45/ed7YMN4NFMTsmRr1ZwRiOHOalAJHtsQUO5iTkRHs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787057366; c=relaxed/simple; bh=cvR0dWZUF4em4CAcfZS1ifgyPX19BMD2dQHLEiiqibQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=W8kNyVzaFwY6oaP5RyuD4BVNbsA5JdL1KEdwS16WwUGYiX7wci8AhddIj4UuLPVFy4McJFUNNx1X079CwVHCovM0Jz6hr4at5mOV1J06yBTKhs+UtnWBUZEg8XMi+DV0yXSD6FBX+eNL31ZOhD9TVKwg/hlyAAzpSpqw2Sywt7I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Pc8f0zPO; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Pc8f0zPO" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-38dfe7eb825so3531171a91.0 for ; Tue, 18 Aug 2026 05:49:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787057364; x=1787662164; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=g8KO6swaxgVTtcdM/0ToN4cGodRQ27jC6GnsdjaTcjE=; b=Pc8f0zPOJBXasWXc0O1qtpcA1UUmKV3dn3PPze/ztMHdCy0vETenIYgB+wIo5ay6gP gijkZmlzPsvYnFvX5sjqykszHMOh0eFljckkEJBJ0d+niwwfp9KkV5J/xeO4SJaTgAWt UaRfBn27kGPqrh5TDK84aOrx0eomxubW/ssPB9tHsGFWLav7DuHp1ceVWmjKJbg8VFXP p/4Moit0baN7a+onBqvjet53WHAmYTLiTro30+W2XYPE8//BO/cvclvEePZoOFEryuQo jPLHr0CLyJIhTmTx5WxZYuAtaZZ1SxI619vGWQAJY5j7wXPCx27k6HnvhN0KAkoF0YUz HFKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787057364; x=1787662164; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=g8KO6swaxgVTtcdM/0ToN4cGodRQ27jC6GnsdjaTcjE=; b=CM3hniHJrwf4vmH7VrE+CILFy++GA4dnObMDreksLte/rxJYpW7ppuxeW9knTOANUj RnArndVz0fklSvz1cxGU8PjDuvrQlN3fCFXPxk6QV8XrtjReBRt4Xq1JGGOWnCKtYRLt m5PjQSqPMqC1KCwIFemWdyJ2bmGzgkBJjENcmnEhC6WBVOVPWSx+zTj0JTPLmdsbObHO uc6KOU6YlMRuuQQEc4i5Kh0/RLgVszkDwBsJojcrEyb1QBBNqa4J1KNWZEifnJQpvYpe gaaa38WtY9H5eartnzi/+K2Dqt4CDqeQoWvKeq4WyeWthjgMS1kX96Fh6CdjUzCPGvsn LzZw== X-Forwarded-Encrypted: i=1; AHgh+RoGpguTNi22CxT/AX3pFQHV8aSRuihEpWpyg7E/EZHio/qRobnZ50cnMDiHfX8gAZ0UCNw=@vger.kernel.org X-Gm-Message-State: AOJu0YyDKs75NHfEO+QLHgBnx7ThYDdPYumM2L9x5tfX5r5g8iL4iVGh 7o4TIFgZDFmHDt9K0Ies/OBn0ffE6AFj4SFVirjHBHAyhanSq5DWGrK/ X-Gm-Gg: AR+sD11J3ay39LfOxZZh7T8zzuGkBMf3SdN0VHysdIVFAmoYgKxo920ZntYUtnoHx+8 p3RarifEdeyZfg/57WLliFIlT7kf+rs2Il4zPnn2esTJBr7r+w+pzKjiBLnhLLHS5whuHGfZFwC 5xIfiXsfeiAxCHw86G1V5gGmIckw6Jb84G2ONFteYytdUhFboPHaki1XaXGM+y6CB00IPhEe3Ub BUcgQIFQ1VbYC4Po+6BadDCfpELBW5KxTTjtMh6mo+3sJgpH46vJ1SendwTREJMUoVQHqDctdPn 1fx2w2RKE9XCOTY8OKLdOoyMCfOWROExVp6I1Brtuhfvf7FerG4V1H1kQ9qsOjLZIZUkaEjc/Hh VYtKoKy9qfnTyPNy+LKnOUZaaaGiCEpgnZnHEekPCQU49eUXQbTEp6pG7FbbPZn526HLHhDlfDD 4X4SJyYE3K+f9Bb4cb0fsGeahfw3HXbCdPezvNijEeUluNhLd+yQykYtbVE1z9nJF1pTIOCbgMC JQBUzO2EAU9XF2hGZ1zqhabmjg= X-Received: by 2002:a17:90b:264c:b0:38d:ddc2:7ccb with SMTP id 98e67ed59e1d1-3933b714f34mr36446357a91.1.1787057364363; Tue, 18 Aug 2026 05:49:24 -0700 (PDT) Received: from [10.26.143.42] ([43.132.141.24]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39339d00eafsm7174764a91.1.2026.08.18.05.49.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Aug 2026 05:49:24 -0700 (PDT) Message-ID: <4f7023b4-dd7a-47cb-9754-52e6d41d3aa1@gmail.com> Date: Tue, 18 Aug 2026 20:49:21 +0800 Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/3] KVM: selftests: arm64: Skip sea_to_user without 1GB hugepages To: Marc Zyngier Cc: kvmarm@lists.linux.dev, Oliver Upton , kvm@vger.kernel.org, sashiko-reviews@lists.linux.dev References: <20260818112920.26252-1-likexu@tencent.com> <20260818112920.26252-3-likexu@tencent.com> <20260818113615.5CBE01F000E9@smtp.kernel.org> Content-Language: en-US From: Like Xu In-Reply-To: <20260818113615.5CBE01F000E9@smtp.kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 8/18/26 7:36 PM, sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: > - [Medium] get_free_hugepages() overestimates available hugepages by ignoring reserved pages, which allows the test to proceed and crash with ENOMEM on systems with reserved pools. > -- > > --- Patch [2]: [PATCH v2 2/3] KVM: selftests: arm64: Skip sea_to_user without 1GB hugepages --- > commit 5fa5666824342b3dd28a5ef6a04bb5ac183257c8 > Author: Like Xu > > KVM: selftests: arm64: Skip sea_to_user without 1GB hugepages > > This commit adds a check to skip the sea_to_user test if the host does not > have enough 1GB hugepages available, preventing a hard failure on systems > without an empty pool. > > [ ... ] >> diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c >> index bab1bd2b775b6..29f9c1d60b1b7 100644 >> --- a/tools/testing/selftests/kvm/lib/test_util.c >> +++ b/tools/testing/selftests/kvm/lib/test_util.c >> @@ -222,6 +222,21 @@ size_t get_def_hugetlb_pagesz(void) >> TEST_FAIL("Error in reading /proc/meminfo"); >> } >> >> +size_t get_free_hugepages(size_t page_size) >> +{ >> + char path[128]; >> + size_t free; >> + >> + snprintf(path, sizeof(path), >> + "/sys/kernel/mm/hugepages/hugepages-%zukB/free_hugepages", >> + page_size >> 10); >> + if (!test_sysfs_path(path)) >> + return 0; >> + >> + free = get_sysfs_val(path); >> + return free * page_size; > > [Severity: Medium] > Does this calculation overestimate the available hugepages by ignoring the > reserved pool? > > The sysfs free_hugepages value includes pages that are already committed to > other mappings but not yet allocated (which are tracked via resv_hugepages). > > If the test runs on a host where free_hugepages meets the VM_MEM_SIZE > requirement but some or all of those pages are reserved, the test will > incorrectly proceed and still crash with an -ENOMEM abort instead of cleanly > skipping. > > Could we also read and subtract resv_hugepages to determine the actual > allocatable count? For any human to double check: diff --git a/tools/testing/selftests/kvm/arm64/sea_to_user.c b/tools/testing/selftests/kvm/arm64/sea_to_user.c index 1c2a743ca8e23..7cf95da8e594d 100644 --- a/tools/testing/selftests/kvm/arm64/sea_to_user.c +++ b/tools/testing/selftests/kvm/arm64/sea_to_user.c @@ -281,6 +281,12 @@ static struct kvm_vm *vm_create_with_sea_handler(struct kvm_vcpu **vcpu) alignment = max(backing_page_size, guest_page_size); num_guest_pages = VM_MEM_SIZE / guest_page_size; + /* + * The region is backed by 1GB hugepages; skip gracefully rather than + * failing with mmap() -ENOMEM if the host has none reserved. + */ + TEST_REQUIRE(get_free_hugepages(backing_page_size) >= VM_MEM_SIZE); + vm = __vm_create_with_one_vcpu(vcpu, num_guest_pages, guest_code); vm_init_descriptor_tables(vm); vcpu_init_descriptor_tables(*vcpu); diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h index a56271c237ae9..0624922c2735d 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -168,6 +168,7 @@ struct vm_mem_backing_src_alias { bool thp_configured(void); size_t get_trans_hugepagesz(void); size_t get_def_hugetlb_pagesz(void); +size_t get_free_hugepages(size_t page_size); const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(u32 i); size_t get_backing_src_pagesz(u32 i); bool is_backing_src_hugetlb(u32 i); diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c index bab1bd2b775b6..3bff9d825e8af 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -222,6 +222,32 @@ size_t get_def_hugetlb_pagesz(void) TEST_FAIL("Error in reading /proc/meminfo"); } +size_t get_free_hugepages(size_t page_size) +{ + char path[128]; + size_t free, resv; + + snprintf(path, sizeof(path), + "/sys/kernel/mm/hugepages/hugepages-%zukB/free_hugepages", + page_size >> 10); + if (!test_sysfs_path(path)) + return 0; + free = get_sysfs_val(path); + + /* + * free_hugepages still counts pages that are reserved by existing + * mappings but not yet faulted in, so only free minus resv can back a + * new reservation (see available_huge_pages() in mm/hugetlb.c). Ignore + * surplus/overcommit: it does not apply to gigantic pages at runtime. + */ + snprintf(path, sizeof(path), + "/sys/kernel/mm/hugepages/hugepages-%zukB/resv_hugepages", + page_size >> 10); + resv = test_sysfs_path(path) ? get_sysfs_val(path) : 0; + + return free > resv ? (free - resv) * page_size : 0; +} + #define ANON_FLAGS (MAP_PRIVATE | MAP_ANONYMOUS) #define ANON_HUGE_FLAGS (ANON_FLAGS | MAP_HUGETLB) > >> +} >> + >> #define ANON_FLAGS (MAP_PRIVATE | MAP_ANONYMOUS) >> #define ANON_HUGE_FLAGS (ANON_FLAGS | MAP_HUGETLB) >> >