From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (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 BC15546983C for ; Thu, 30 Jul 2026 19:19:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785439163; cv=none; b=Qgjito9dJ2L2+eMsVKEA9krmNLPp3UGddhKZTI2WLSFeoYFQIv/+oteefCwJriWv4P8qfhmpseaAbSF/ocQtUrkn0IXntdHheSpaHCpyNbxePb1q101HrBrtmhuDhdePAatH7SQ09whV/HReZ9BwqMJU3pcemptS3AqCZy4nLOk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785439163; c=relaxed/simple; bh=9eB1/vxRZMNrMuybVouYj9D4B4rxtHe2oati0JA5JD4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=T5D0VWmWAMrl7VqQBmsEbeD72XWfcx0rBWN7XS0ZKbgINDaJviiRrGmAlRqw5zx9b9rH3+Vb3uxSgmxz2cxp022olvRA0Ff0If31dsqb3Vk263cyORZul80tD1CZDk7cNlluX1Ybo5ev1LK95W8d0BOs2egpPYfYHhhJDFFMghQ= 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=Tq6Kcc7r; arc=none smtp.client-ip=209.85.210.200 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="Tq6Kcc7r" Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-84eccf9d899so271763b3a.2 for ; Thu, 30 Jul 2026 12:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785439161; x=1786043961; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:from:to:cc:subject:date:message-id :reply-to:content-type; bh=YgYOnGbE/Qcoxe+WXdzA3Ub6YZQpGia+1p7vtjJDY/M=; b=Tq6Kcc7r/3UZ12tn80gyC8i7e9tUmgPFdpnOq5m6hHIV8JDIDXnR1SGunzhRMMDCPy 4nvrgZdnMGPZcBpn/Qxu2dvP8Qx0MKaavSFd6d2gW+U2vxjIRJVxdA4M+Se0ewAZXDfZ CBh1FPDyKXDnaZcm32VDdOEY4zng/HSLos8sSdf+qiHNAof8wT1QeZnmy+7MNlacJ4LR fW02SIwUOPmM4pNEdwGjrW730mB+CI0HLlCuTX8WHxkYfMfn8z8TRX8jS7ci66ccc1B9 ZYA/UM5b3Z1wueVm9zJ4AY+9UOljgOGKQl10otB0ZoEP7SOT+w2i/S/YDN323xIJh6pu 3JQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785439161; x=1786043961; h=content-type: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:content-type; bh=YgYOnGbE/Qcoxe+WXdzA3Ub6YZQpGia+1p7vtjJDY/M=; b=bTmEl4Ns8mjAoW+jQ9YY0jSAN0GqYYV11gMVXcJ0Dqi64phAl39MRzPgJa0uC9ueX0 Lpe/eFlsn2pKYzePV+Eo6oPk/nYLNJ50l3hSi/CrskYiAlLfbDQ6atoD9xbh2lJVcl5O MD57cqKpd9fzC17lZLGpGTI1UDt7FNq2Hqec5eJebIEvDeBwfikxQpD4GSrJGUw5NLEt CeU/6uY5ajsFHOBup0aOsXdVpRSl5iuFvdzSN59/3uHUFB1QbQ2sHLphn8Bp7rWXoq/i YvQGG+sUhMNmGldnhEFiQw3KD6fKDF8ZUKCrl9q9Ze7R9G6m9/ZxKEYASIJOvk7zlMYp XvWw== X-Forwarded-Encrypted: i=1; AHgh+RoN7nsOz4xU5qZyv19mrk9u8YJiuyQ/LLQ0j7q8Y5lfwoXJfHUdFXokdXid8KgGLaF6ouKK2YzqbeIe00w=@vger.kernel.org X-Gm-Message-State: AOJu0YznzHwUrzXR+nM+ZCjvkdCO9tW+BJikKmzKxRCugdCl+SigZK5O 0kas0EH0b0+8ZPSoTVYyXTdAfQOOPzFLv+Me4lb0bTRbQ/XkflNP7QZPgVQ9TQtVUWMrkGdNY3/ N7yNqgQ== X-Received: from pfoi22.prod.google.com ([2002:aa7:87d6:0:b0:847:823c:d265]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:12da:b0:848:2d1d:836f with SMTP id d2e1a72fcca58-84ebc22e880mr3456538b3a.28.1785439160801; Thu, 30 Jul 2026 12:19:20 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 30 Jul 2026 12:19:07 -0700 In-Reply-To: <20260730191908.2084803-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: <20260730191908.2084803-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.508.g3f0d502094-goog Message-ID: <20260730191908.2084803-9-seanjc@google.com> Subject: [PATCH 8/9] KVM: selftests: Add KVM syscall wrappers for pthread_{g,s}etaffinity_np() From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson Cc: Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , David Hildenbrand , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Add and use KVM wrappers for pthread_{g,s}etaffinity_np() so that selftests don't need to manually assert that the syscalls succeeded, and so that they don't need to manually pass in sizeof(cpu_set_t) for the size. Note, the steal time test didn't assert success, but the TEST_ASSERT() one line later makes it quite clear the test relies on pthread_getaffinity_np() succeeding. Signed-off-by: Sean Christopherson --- .../selftests/kvm/hardware_disable_test.c | 12 ++---------- .../testing/selftests/kvm/include/kvm_syscalls.h | 16 ++++++++++++++++ tools/testing/selftests/kvm/steal_time.c | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/kvm/hardware_disable_test.c b/tools/testing/selftests/kvm/hardware_disable_test.c index 38ebacaa0fce..bcca42182656 100644 --- a/tools/testing/selftests/kvm/hardware_disable_test.c +++ b/tools/testing/selftests/kvm/hardware_disable_test.c @@ -54,14 +54,6 @@ static void *sleeping_thread(void *arg) TEST_FAIL("%s: exited", __func__); } -static inline void check_set_affinity(pthread_t thread, cpu_set_t *cpu_set) -{ - int r; - - r = pthread_setaffinity_np(thread, sizeof(cpu_set_t), cpu_set); - TEST_ASSERT(r == 0, "%s: failed set affinity", __func__); -} - static void run_test(u32 run) { struct kvm_vcpu *vcpu; @@ -76,11 +68,11 @@ static void run_test(u32 run) vcpu = vm_vcpu_add(vm, i, guest_code); kvm_pthread_create(&thread, NULL, run_vcpu, vcpu); - check_set_affinity(thread, &child_cpu_set); + kvm_pthread_setaffinity(thread, &child_cpu_set); for (j = 0; j < SLEEPING_THREAD_NUM; ++j) { kvm_pthread_create(&thread, NULL, sleeping_thread, (void *)NULL); - check_set_affinity(thread, &child_cpu_set); + kvm_pthread_setaffinity(thread, &child_cpu_set); } } pr_debug("%s: [%d] all threads launched\n", __func__, run); diff --git a/tools/testing/selftests/kvm/include/kvm_syscalls.h b/tools/testing/selftests/kvm/include/kvm_syscalls.h index 002b5a4e59eb..3d82351bef92 100644 --- a/tools/testing/selftests/kvm/include/kvm_syscalls.h +++ b/tools/testing/selftests/kvm/include/kvm_syscalls.h @@ -97,6 +97,22 @@ __KVM_SYSCALL_DEFINE(ftruncate, 2, unsigned int, fd, off_t, length); __KVM_SYSCALL_DEFINE(madvise, 3, void *, addr, size_t, length, int, advice); __KVM_SYSCALL_DEFINE(sched_getaffinity, 3, pid_t, pid, size_t, cpusetsize, cpu_set_t *, mask); +__KVM_SYSCALL_DEFINE(pthread_getaffinity_np, 3, pthread_t, thread, + size_t, cpusetsize, cpu_set_t *, cpuset); +__KVM_SYSCALL_DEFINE(pthread_setaffinity_np, 3, pthread_t, thread, + size_t, cpusetsize, const cpu_set_t *, cpuset); + +static inline void kvm_pthread_getaffinity(pthread_t thread, cpu_set_t *cpuset) +{ + kvm_pthread_getaffinity_np(thread, sizeof(cpu_set_t), cpuset); +} + +static inline void kvm_pthread_setaffinity(pthread_t thread, + const cpu_set_t *cpuset) +{ + kvm_pthread_setaffinity_np(thread, sizeof(cpu_set_t), cpuset); +} + typedef void *(*pthread_fn_t)(void *); __KVM_SYSCALL_DEFINE(pthread_create, 4, pthread_t *, thread, const pthread_attr_t *, attr, pthread_fn_t, fn, void *, arg); diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c index 6cb1eb4c40c9..bc3c62b72c58 100644 --- a/tools/testing/selftests/kvm/steal_time.c +++ b/tools/testing/selftests/kvm/steal_time.c @@ -549,7 +549,7 @@ int main(int ac, char **av) /* Steal time from the VCPU. The steal time thread has the same CPU affinity as the VCPUs. */ run_delay = get_run_delay(); kvm_pthread_create(&thread, NULL, do_steal_time, NULL); - pthread_getaffinity_np(thread, sizeof(cpuset), &cpuset); + kvm_pthread_getaffinity(thread, &cpuset); TEST_ASSERT(CPU_COUNT(&cpuset) == 1 && CPU_ISSET(cpu, &cpuset), "Worker failed to inherit parent's CPU affinity"); -- 2.55.0.508.g3f0d502094-goog