[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <54225ff0-b90a-6c1f-f474-2338df21befa@redhat.com>
Date: Fri, 26 Nov 2021 13:32:34 +0100
From: Paolo Bonzini <pbonzini@...hat.com>
To: Sean Christopherson <seanjc@...gle.com>,
Vitaly Kuznetsov <vkuznets@...hat.com>
Cc: kvm@...r.kernel.org, Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] KVM: selftests: Make sure kvm_create_max_vcpus test
won't hit RLIMIT_NOFILE
On 11/24/21 19:50, Sean Christopherson wrote:
>> + if (rl.rlim_cur < nr_fds_wanted) {
>> + rl.rlim_cur = nr_fds_wanted;
>> +
>> + if (rl.rlim_max < nr_fds_wanted)
>> + rl.rlim_max = nr_fds_wanted;
> Nit, this could use max().
If the hard limit is too low, the right thing to do is to skip the test:
--- a/tools/testing/selftests/kvm/kvm_create_max_vcpus.c
+++ b/tools/testing/selftests/kvm/kvm_create_max_vcpus.c
@@ -59,11 +59,19 @@ int main(int argc, char *argv[])
if (rl.rlim_cur < nr_fds_wanted) {
rl.rlim_cur = nr_fds_wanted;
-
- if (rl.rlim_max < nr_fds_wanted)
+ if (rl.rlim_max < nr_fds_wanted) {
+ int old_rlim_max = rl.rlim_max;
rl.rlim_max = nr_fds_wanted;
- TEST_ASSERT(!setrlimit(RLIMIT_NOFILE, &rl), "setrlimit() failed!");
+ int r = setrlimit(RLIMIT_NOFILE, &rl);
+ if (r < 0) {
+ printf("RLIMIT_NOFILE hard limit is too low (%d, wanted %d)\n",
+ old_rlim_max, nr_fds_wanted);
+ exit(KSFT_SKIP);
+ }
+ } else {
+ TEST_ASSERT(!setrlimit(RLIMIT_NOFILE, &rl), "setrlimit() failed!");
+ }
}
/*
Nevertheless, thanks for the fix and the review! (I might have missed it
if it wasn't for your remark).
Paolo
> Reviewed-and-tested-by: Sean Christopherson<seanjc@...gle.com>
>
Powered by blists - more mailing lists