Thread (3 messages) 3 messages, 3 authors, 2021-11-26

Re: [PATCH v2] KVM: selftests: Make sure kvm_create_max_vcpus test won't hit RLIMIT_NOFILE

From: Paolo Bonzini <pbonzini@redhat.com>
Date: 2021-11-26 12:34:44
Also in: lkml

On 11/24/21 19:50, Sean Christopherson wrote:
quoted
+	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[off-list ref] 
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help