From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 A28E63CA497 for ; Fri, 26 Jun 2026 21:35:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782509766; cv=none; b=uSAO12EJd42NmPxu0jXiA5H1VkJ/zFayJwV7pysuwEswRHPEpv/G7jRPXUSTxJe87vIC4gNGJMW7dCYA7CAdG3xTng8e+52ti9wh1Wezd1zKkN+6mFVcN85zeFpyu14nWSVzF4PoMZMYR6Jt5bDm3xarmNF1gb0BF7t6Se02SPE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782509766; c=relaxed/simple; bh=C8Pm8bDjAvONP3npZngQGRIsMoOy/jsuoXoApS2hZsE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dxlY9E8UM1vfwpCyk+CsxVxyo+x4bcDRD5rxSn014TrxJITffOh3z6pmBpIaFGrDrXCnYvBcE5ti++I8jporMPf8Vo5JV5iixztkmk5XyQDIb8YBxCocW/OgrWe37ud26OhpxWs6cAPjKwcIss3aNlYbXlYq4SFdb4Tv1T90t1w= 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=DtWkxR70; arc=none smtp.client-ip=209.85.214.201 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="DtWkxR70" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2c80f89b64bso18559135ad.2 for ; Fri, 26 Jun 2026 14:35:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782509755; x=1783114555; 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=MGnCIDvL4VuiQREjmSstYz3dctCxQA8TSy/TAbZS7yY=; b=DtWkxR70uBK/LL43hbB9e5YC3Ui9eLy3ri4s9W/9amlcKMLCUIcrkaMbL2u6OYiAXM R6NeBqnDSLOU2o1zCWPg1mP2CR9PkGjjvyXSfXaoYeR0jdDdTts7V4y6OQX4SIbqflfM XWnPaVOaAdyd9V+raZbBr1zwUW+T30ycUt2YhPrcPgC6lRw8ZBhlOKmva2564+8ZHR6E i/s5lkiNC3iPrvtg4WLi+CmNTqpkienSsmhO88ErkabE9EMszXOriHShhogeWNBVQzfP T7IColn6eIIPqI8FmX4f86ZSv7I0LKGIwiKENZ8sxkmrQ9zS2MtUiHOmuPvBwpgQ4Nol 5HyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782509755; x=1783114555; 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=MGnCIDvL4VuiQREjmSstYz3dctCxQA8TSy/TAbZS7yY=; b=pT8MVq/3Btup8Ru7aGyzgX6Cwd6egW5FaDi3X4oG6A6QBLH+IwgpMn6uZmqDjYMsce FyTrySxe46irF4Cqm5pce4fHmyMsE7hgIRTHob021ub39C+a4vDGBaxBWQKSn3TZWDgl c3uvSkg09jszsKvAzv929zMHVdQQZSPJIIoW/Im64qzuJzLei30V2wXpmpLip75lsXnO /tMDT8fDhXDLajXP75ojAZeMmDstztUX7liAidoTy8pDiDDbyWZKi/x3Eu2zjdwMMF4V VxPZZ01r3tmUJmLO2oFlujl7jHXN884K35FCsL4dipARAE9yovwGDGl9cGKBRdcxAAWs gBdg== X-Forwarded-Encrypted: i=1; AHgh+RobR1IYK4aHiDSJ4Q1ZL4dWioqz07x5oVd55iZeG9NG1ZqMOQ7QCmT+XjaL6l2XVn6rNKDRJEl51UtB/SI=@vger.kernel.org X-Gm-Message-State: AOJu0Ywn/+x0M0CNYRwA09ARWE5L7V1UR2ZkZHSJz1olEGPVHS3T3WG0 WbXza30B76nTHA/ngHkKDAXBN+ODOrftMb0tpe3HQQggVkJ+ImFCMtMngo9lWaAmF57Rg7ty4Cb 8Vd/HyQ== X-Received: from plau11.prod.google.com ([2002:a17:903:304b:b0:2c6:e595:44e1]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2f4c:b0:2c9:9a19:10c with SMTP id d9443c01a7336-2c99a19037fmr10641045ad.40.1782509754664; Fri, 26 Jun 2026 14:35:54 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 26 Jun 2026 14:35:28 -0700 In-Reply-To: <20260626213534.3866178-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: <20260626213534.3866178-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260626213534.3866178-16-seanjc@google.com> Subject: [PATCH v8 15/20] KVM: selftests: Add kvm_gettid() wrapper and convert users From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Sean Christopherson Cc: Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, David Matlack , Josh Hilke Content-Type: text/plain; charset="UTF-8" From: Josh Hilke Add a KVM wrapper for the gettid() syscall so that tests don't have to open code the syscall() themselves. Unfortunately, not all flavors of libc that KVM selftests support provide gettid(). Convert all existing users of the syscall to the new wrapper. Note, per the gettid() manpage[1], "This call is always successful", i.e. prefixing kvm_ to the syscall name is aligned with the goal of providing syscall wrappers that guarantee success. No functional changes intended. Link: https://man7.org/linux/man-pages/man2/gettid.2.html [1] Suggested-by: Sean Christopherson Signed-off-by: Josh Hilke [sean: massage changelog] Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/demand_paging_test.c | 2 +- tools/testing/selftests/kvm/include/kvm_syscalls.h | 5 +++++ tools/testing/selftests/kvm/lib/assert.c | 8 ++------ tools/testing/selftests/kvm/lib/test_util.c | 3 ++- tools/testing/selftests/kvm/rseq_test.c | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c index 302c4923d093..f8b3d0b68830 100644 --- a/tools/testing/selftests/kvm/demand_paging_test.c +++ b/tools/testing/selftests/kvm/demand_paging_test.c @@ -57,7 +57,7 @@ static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) static int handle_uffd_page_request(int uffd_mode, int uffd, struct uffd_msg *msg) { - pid_t tid = syscall(__NR_gettid); + pid_t tid = kvm_gettid(); u64 addr = msg->arg.pagefault.address; struct timespec start; struct timespec ts_diff; diff --git a/tools/testing/selftests/kvm/include/kvm_syscalls.h b/tools/testing/selftests/kvm/include/kvm_syscalls.h index 6cb3bed29b81..dc4fb97aef8d 100644 --- a/tools/testing/selftests/kvm/include/kvm_syscalls.h +++ b/tools/testing/selftests/kvm/include/kvm_syscalls.h @@ -83,6 +83,11 @@ static inline int kvm_dup(int fd) return new_fd; } +static inline pid_t kvm_gettid(void) +{ + return syscall(__NR_gettid); +} + __KVM_SYSCALL_DEFINE(munmap, 2, void *, mem, size_t, size); __KVM_SYSCALL_DEFINE(close, 1, int, fd); __KVM_SYSCALL_DEFINE(fallocate, 4, int, fd, int, mode, loff_t, offset, loff_t, len); diff --git a/tools/testing/selftests/kvm/lib/assert.c b/tools/testing/selftests/kvm/lib/assert.c index 8be0d09ecf0f..1d72dcdfce3b 100644 --- a/tools/testing/selftests/kvm/lib/assert.c +++ b/tools/testing/selftests/kvm/lib/assert.c @@ -10,6 +10,7 @@ #include #include "kselftest.h" +#include "kvm_syscalls.h" #ifdef __GLIBC__ #include @@ -64,11 +65,6 @@ static void test_dump_stack(void) static void test_dump_stack(void) {} #endif -static pid_t _gettid(void) -{ - return syscall(SYS_gettid); -} - void __attribute__((noinline)) test_assert(bool exp, const char *exp_str, const char *file, unsigned int line, const char *fmt, ...) @@ -81,7 +77,7 @@ test_assert(bool exp, const char *exp_str, fprintf(stderr, "==== Test Assertion Failure ====\n" " %s:%u: %s\n" " pid=%d tid=%d errno=%d - %s\n", - file, line, exp_str, getpid(), _gettid(), + file, line, exp_str, getpid(), kvm_gettid(), errno, strerror(errno)); test_dump_stack(); if (fmt) { diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c index e208a57f190c..6b00ab11f3c0 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -17,6 +17,7 @@ #include "linux/kernel.h" #include "test_util.h" +#include "kvm_syscalls.h" sigjmp_buf expect_sigbus_jmpbuf; @@ -395,7 +396,7 @@ long get_run_delay(void) long val[2]; FILE *fp; - sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid)); + sprintf(path, "/proc/%ld/schedstat", (long)kvm_gettid()); fp = fopen(path, "r"); /* Return MIN_RUN_DELAY_NS upon failure just to be safe */ if (fscanf(fp, "%ld %ld ", &val[0], &val[1]) < 2) diff --git a/tools/testing/selftests/kvm/rseq_test.c b/tools/testing/selftests/kvm/rseq_test.c index f80ad6b47d16..6510fbfd64f1 100644 --- a/tools/testing/selftests/kvm/rseq_test.c +++ b/tools/testing/selftests/kvm/rseq_test.c @@ -244,7 +244,7 @@ int main(int argc, char *argv[]) vm = vm_create_with_one_vcpu(&vcpu, guest_code); pthread_create(&migration_thread, NULL, migration_worker, - (void *)(unsigned long)syscall(SYS_gettid)); + (void *)(unsigned long)kvm_gettid()); if (latency >= 0) { /* -- 2.55.0.rc0.799.gd6f94ed593-goog