From nobody Mon Feb 9 06:24:37 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 3CF4315539D for ; Sat, 11 Jan 2025 00:51:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736556665; cv=none; b=ZWDY3O97uTsAdhk6dNgwTTVDYmr84rkDDMJY+koW84NmkULBzGYMb5EZ/l4Lt8YXM1FLdKfVeksegKtlirttNSZWWdcF9cyilgDog6y2MoKvLCAdSZZazlkqRvKLDKYxAkeOhAKsISTNiyHVip+zqdTsYI/3X5cQb/wFcdOHZOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736556665; c=relaxed/simple; bh=P1tpMNzbS5Njgz1DwTNPeyi/z6xYk/XJDEeQ78FSaJY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JBFo6kbPsJZbGl6cZlsji1x/r7quyscaYeEMZLMIlXl8ahFHB+vVwqlB3aHGJE78Q61mFKIFhBfOaS8gvJFCUfLvlZb8uU0Nw/TQTZpX6JsF2vdH/FyScyAvgFJtk3Eyv6g7eKJAS3JXtUrG1/TYOEavNxh0mQFJJbASpfJIhVQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=B8H4vmx5; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="B8H4vmx5" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ee86953aeaso4615110a91.2 for ; Fri, 10 Jan 2025 16:51:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736556663; x=1737161463; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=wbJUIEbFpcT4LmqIjAYiV2s86GObQLOrAwx+1Pf2g7A=; b=B8H4vmx5U5R2RNRHEr+LTZQ00c6LwpNWanyQ11c3mRiFGK7Nx4S0FnbWAdMVq/g1I6 QtFiaCkKbWcfpOZeNBb+qVMp2yDZTQQu/oUq3AD2Jvj7Wz/9buxOYgybffw30aNGWf0f EBzcZY7u8oAyASjsypleFdL11d+JKr75RdkagQeYxIoeNDmqLYRmZ7VSMoP8Zo+8IjLB z9PI66uCznYT4ffv8tde5hbk6HFCHEQY2l8muJd6C2dHzjYEEf6Q0SInMBb4hZdm58uL 6Gsb4Y5Vbyd6sXIOqGF90uKfHaqtD0XHLjy4OoVJ+YiWM6yG3H06RvhFfIzay0rxulHM CYpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736556663; x=1737161463; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wbJUIEbFpcT4LmqIjAYiV2s86GObQLOrAwx+1Pf2g7A=; b=BVqoonwhSMiaxFlCwUVUzrFdTuJZI/Bwoc8ShGGmQz4j1OEM9wpnDk+0L4UeeERsx4 0FS7OnkqDkl8uRivPZbGaPBmAxO+Y4czT5l8m956ECjG2nkopZ5qXGQhsIfViUfW/GE1 a3tMUJwiBiz/vVDPd2U4HAbuMYOWdICjD1WAj0Xbr2K62C9cKufO4nfT16lhjCLpUjF8 x3wFEMpQ3JD+5wByN2V5c4y0jmH/485ap8TMc1Fc8g2UdRKfHAdTBaX4qw1G61CRS9k7 Gbeo11tpSsacl34zgkKHanylG16Q1DHiTSk4SCoY6Z42soEKwBnZStIk9T6EhF4JpW9S P6hg== X-Forwarded-Encrypted: i=1; AJvYcCWJ5IrOgXr/xpEHBkviEBmJQ9/wi/MqC2zqB1KHXy0jeEm1Y20U5JJhN2UTk57Wj7J1M/j2EFkK5HNzxpg=@vger.kernel.org X-Gm-Message-State: AOJu0Yww/SOTuychiUmxp/tRc5+vxVPjNcjHEcs/BbdKMEXNVpffkdbj GdwdeTCH4M781vNafG+Pa9hSSmddcf1EdGOI0K+f+N1wOHbmh5aVU21iinQ3OZeD1GNhgOUlkN+ 92A== X-Google-Smtp-Source: AGHT+IGH6342S92kOvdYD94+ymoteQzN/cfHIZ0hJZS0WFG0jyjicN3k4eAbOT3Lbu+t8kUVV+/QXmvVvSI= X-Received: from pjboi12.prod.google.com ([2002:a17:90b:3a0c:b0:2eb:12c1:bf8f]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:270c:b0:2ee:6e22:bfd0 with SMTP id 98e67ed59e1d1-2f548ee48demr16948021a91.21.1736556663692; Fri, 10 Jan 2025 16:51:03 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 10 Jan 2025 16:50:47 -0800 In-Reply-To: <20250111005049.1247555-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250111005049.1247555-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250111005049.1247555-8-seanjc@google.com> Subject: [PATCH v2 7/9] KVM: selftests: Adjust number of files rlimit for all "standard" VMs From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the max vCPUs test's RLIMIT_NOFILE adjustments to common code, and use the new helper to adjust the resource limit for non-barebones VMs by default. x86's recalc_apic_map_test creates 512 vCPUs, and a future change will open the binary stats fd for all vCPUs, which will put the recalc APIC test above some distros' default limit of 1024. Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/include/kvm_util.h | 2 ++ .../selftests/kvm/kvm_create_max_vcpus.c | 28 +-------------- tools/testing/selftests/kvm/lib/kvm_util.c | 34 +++++++++++++++++++ 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing= /selftests/kvm/include/kvm_util.h index 9a64bab42f89..d4670b5962ab 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -966,6 +966,8 @@ static inline struct kvm_vm *vm_create_shape_with_one_v= cpu(struct vm_shape shape =20 struct kvm_vcpu *vm_recreate_with_one_vcpu(struct kvm_vm *vm); =20 +void kvm_set_files_rlimit(uint32_t nr_vcpus); + void kvm_pin_this_task_to_pcpu(uint32_t pcpu); void kvm_print_vcpu_pinning_help(void); void kvm_parse_vcpu_pinning(const char *pcpus_string, uint32_t vcpu_to_pcp= u[], diff --git a/tools/testing/selftests/kvm/kvm_create_max_vcpus.c b/tools/tes= ting/selftests/kvm/kvm_create_max_vcpus.c index c78f34699f73..c5310736ed06 100644 --- a/tools/testing/selftests/kvm/kvm_create_max_vcpus.c +++ b/tools/testing/selftests/kvm/kvm_create_max_vcpus.c @@ -10,7 +10,6 @@ #include #include #include -#include =20 #include "test_util.h" =20 @@ -39,36 +38,11 @@ int main(int argc, char *argv[]) { int kvm_max_vcpu_id =3D kvm_check_cap(KVM_CAP_MAX_VCPU_ID); int kvm_max_vcpus =3D kvm_check_cap(KVM_CAP_MAX_VCPUS); - /* - * Number of file descriptors reqired, KVM_CAP_MAX_VCPUS for vCPU fds + - * an arbitrary number for everything else. - */ - int nr_fds_wanted =3D kvm_max_vcpus + 100; - struct rlimit rl; =20 pr_info("KVM_CAP_MAX_VCPU_ID: %d\n", kvm_max_vcpu_id); pr_info("KVM_CAP_MAX_VCPUS: %d\n", kvm_max_vcpus); =20 - /* - * Check that we're allowed to open nr_fds_wanted file descriptors and - * try raising the limits if needed. - */ - TEST_ASSERT(!getrlimit(RLIMIT_NOFILE, &rl), "getrlimit() failed!"); - - if (rl.rlim_cur < nr_fds_wanted) { - rl.rlim_cur =3D nr_fds_wanted; - if (rl.rlim_max < nr_fds_wanted) { - int old_rlim_max =3D rl.rlim_max; - rl.rlim_max =3D nr_fds_wanted; - - int r =3D setrlimit(RLIMIT_NOFILE, &rl); - __TEST_REQUIRE(r >=3D 0, - "RLIMIT_NOFILE hard limit is too low (%d, wanted %d)", - old_rlim_max, nr_fds_wanted); - } else { - TEST_ASSERT(!setrlimit(RLIMIT_NOFILE, &rl), "setrlimit() failed!"); - } - } + kvm_set_files_rlimit(kvm_max_vcpus); =20 /* * Upstream KVM prior to 4.8 does not support KVM_CAP_MAX_VCPU_ID. diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/sel= ftests/kvm/lib/kvm_util.c index 16ee03e76d66..f49bb504fa72 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -411,6 +412,37 @@ static uint64_t vm_nr_pages_required(enum vm_guest_mod= e mode, return vm_adjust_num_guest_pages(mode, nr_pages); } =20 +void kvm_set_files_rlimit(uint32_t nr_vcpus) +{ + /* + * Number of file descriptors required, nr_vpucs vCPU fds + an arbitrary + * number for everything else. + */ + int nr_fds_wanted =3D nr_vcpus + 100; + struct rlimit rl; + + /* + * Check that we're allowed to open nr_fds_wanted file descriptors and + * try raising the limits if needed. + */ + TEST_ASSERT(!getrlimit(RLIMIT_NOFILE, &rl), "getrlimit() failed!"); + + if (rl.rlim_cur < nr_fds_wanted) { + rl.rlim_cur =3D nr_fds_wanted; + if (rl.rlim_max < nr_fds_wanted) { + int old_rlim_max =3D rl.rlim_max; + + rl.rlim_max =3D nr_fds_wanted; + __TEST_REQUIRE(setrlimit(RLIMIT_NOFILE, &rl) >=3D 0, + "RLIMIT_NOFILE hard limit is too low (%d, wanted %d)", + old_rlim_max, nr_fds_wanted); + } else { + TEST_ASSERT(!setrlimit(RLIMIT_NOFILE, &rl), "setrlimit() failed!"); + } + } + +} + struct kvm_vm *__vm_create(struct vm_shape shape, uint32_t nr_runnable_vcp= us, uint64_t nr_extra_pages) { @@ -420,6 +452,8 @@ struct kvm_vm *__vm_create(struct vm_shape shape, uint3= 2_t nr_runnable_vcpus, struct kvm_vm *vm; int i; =20 + kvm_set_files_rlimit(nr_runnable_vcpus); + pr_debug("%s: mode=3D'%s' type=3D'%d', pages=3D'%ld'\n", __func__, vm_guest_mode_string(shape.mode), shape.type, nr_pages); =20 --=20 2.47.1.613.gc27f4b7a9f-goog