From mboxrd@z Thu Jan 1 00:00:00 1970 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 C98314C6F0F for ; Thu, 4 Jun 2026 17:27:31 +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=1780594053; cv=none; b=Kw+tVqkfc6Z+4Q6T2oHFVE4JDRYMuez2PwkuF1ZGFc2y5gjZ2qEnaLaIptEDktX2xVbvNofNM/0oM0oXCIjmfQBrASP1YF3YLWnf1tbdaSd6TNeYy3zcIQCLJqaFJ+aA1jD9wHzFs/2XznSJ2OXmsS11fp5N+gSv5xf0bZ942To= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780594053; c=relaxed/simple; bh=JwWV856tZhQRbvWwA5YTL5FY1rX+zrsPCS+w2CdpZRs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XCvAYgbq7KVDID5FIA7L8IS27mQjJrKOnDznApMF6OFF8AtmhbxMf/FfUNurYwjxxy/MfWzG543eetymJmzww3LEfJdo1he/aqH184fsWylqz3/4geWD3QZRdOUPulrQfjWzhkihKiz23cRvl24ShbBAt3aUN/ydsi3qL2z9f0Y= 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=rO6laRmP; 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="rO6laRmP" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-36d97415004so2136167a91.2 for ; Thu, 04 Jun 2026 10:27:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780594051; x=1781198851; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=AFq5d3x5ye3mknGU4YVD43umBtdzTEPmebuap4yJYfo=; b=rO6laRmPEAswEJB9V+go3TLBJboevMaTMRxV/PkZeox+8GT4sJPROoKdjcxLOiwlbs pPpWZ2t2KEaZ6WFEmBpebsT6Yo/5NVnVV1WfUP0mvE/P8R/G7GIoMrQ9cgp8qTw2tPoI s3i3vaJ8pnQHuL2/ysCMt57pjTDesgCIlIvuS5rBI+ISSYf19oSPWUFUlZG3x/kGQyjV gAF1QBM5Ru5uTHsl3Vqykk5oiINvxUcorivd4XMbPFQjnCia2PrvbfI1Dragj9V5Rdtl bdVyD76VQHrOXcBYexjz1wV8VVgrAi+iDggesc2hR3ZMacuwabgy87WC7EVsMsd8LPR2 lkRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780594051; x=1781198851; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AFq5d3x5ye3mknGU4YVD43umBtdzTEPmebuap4yJYfo=; b=ZBxGr6qbcfqSkG4tDGojefV6iqjeKOtB4xTkfIVJ0OmGWXU2M9XKdNxiS3cypj63tA KA6nYn5cHOjIrD1eS29bqm/17V578KO+8TJkgnULSgGUYkjNNYXp6caDZz4P9mOTcd49 LTb2Bqfkn4JJpFr98LQA3qVPIZSZYIwr7Z5mO0e/WdM0zs2pHcrblbE8iRUAg+AeOT5b lRlj3tPpWzg+iqE/u6VpzvkksMQ31hD6XBiF/w7BV0mMUW8r9+7AxittWXJwd3cRzh3D AieEnU7xTRuhA/RVCSOD66sVkvkB8ZdteKxrsVsRx4R85eTBSCwjmABkKT6mzlisntjy F4nA== X-Forwarded-Encrypted: i=1; AFNElJ9ZbsUdFVaZ4TY5YSJ5hdRVlYW9wwX2+ufa8evArzRQgoxsGTjxoJM0nYqx0pQOL30aAfSScklGuIVZrBs=@vger.kernel.org X-Gm-Message-State: AOJu0Yxg+qP4P8OQL4VVZ9ctwKJEhOr4qpiUKDmbw2cIjpXJHERLFnsZ C39rK3W0fuQjVzoyWoD43YYfDh79l9Kuu9g+PU0FkHkbkBQvWPO8xM3ZkInWpAATA4bQXaAOATb 3/qQQEw== X-Received: from pjto20.prod.google.com ([2002:a17:90a:c714:b0:36b:dbd1:f512]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5628:b0:36b:2179:6d23 with SMTP id 98e67ed59e1d1-36e3294e53dmr9915991a91.7.1780594049270; Thu, 04 Jun 2026 10:27:29 -0700 (PDT) Date: Thu, 4 Jun 2026 10:27:28 -0700 In-Reply-To: <20260604020143.748245-19-jrhilke@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260604020143.748245-1-jrhilke@google.com> <20260604020143.748245-19-jrhilke@google.com> Message-ID: Subject: Re: [PATCH v5 18/21] KVM: selftests: Verify vCPU migration during IRQ delivery in IRQ test From: Sean Christopherson To: Josh Hilke Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , Alex Williamson Content-Type: text/plain; charset="us-ascii" On Thu, Jun 04, 2026, Josh Hilke wrote: > From: David Matlack > > Add the '-m' flag to tools/testing/selftests/kvm/irq_test.c to migrate > vCPU threads across random physical CPUs during the test. This validates > KVM's ability to handle vCPUs changing physical CPUs while interrupts > are actively being injected. > > Co-developed-by: Josh Hilke > Signed-off-by: Josh Hilke > Signed-off-by: David Matlack > --- > tools/testing/selftests/kvm/irq_test.c | 33 ++++++++++++++++++++++++-- > 1 file changed, 31 insertions(+), 2 deletions(-) > > diff --git a/tools/testing/selftests/kvm/irq_test.c b/tools/testing/selftests/kvm/irq_test.c > index ed48562318bf..5f7df76005ec 100644 > --- a/tools/testing/selftests/kvm/irq_test.c > +++ b/tools/testing/selftests/kvm/irq_test.c > @@ -18,6 +18,8 @@ static u64 timeout_ns = 2ULL * 1000 * 1000 * 1000; > static bool guest_ready_for_irqs[KVM_MAX_VCPUS]; > static bool guest_received_irq[KVM_MAX_VCPUS]; > static bool guest_received_nmi[KVM_MAX_VCPUS]; > +static pid_t vcpu_tids[KVM_MAX_VCPUS]; This doesn't need to exist. > +static bool migrate_vcpus; This doesn't need to be globally visible. > static bool irq_affinity; > static bool block_vcpus; > static bool done; > @@ -67,12 +69,23 @@ static void *vcpu_thread_main(void *arg) > struct kvm_vcpu *vcpu = arg; > struct ucall uc; > > + WRITE_ONCE(vcpu_tids[vcpu->id], kvm_gettid()); ... > @@ -246,6 +264,14 @@ int main(int argc, char **argv) > */ > irq_cpu = -1; > > + if (migrate_vcpus) { > + kvm_sched_getaffinity(vcpu_tids[0], sizeof(available_cpus), &available_cpus); This is silly, just use the affinity of the main task. There's no reason to go look at a child task's affinity. > + > + if (nr_vcpus > CPU_COUNT(&available_cpus)) { > + printf("There are more vCPUs than pCPUs; refusing to migrate.\n"); Why? Overcommitting vCPUs:pCPUs is quite common, and arguably more interesting for this test. And it's not like the test prevents overlap anyways (it is random after all). > + migrate_vcpus = false; > + } > + } > for (i = 0; i < nr_irqs; i++) { > const bool do_clear_routes = clear_routes && (i & BIT(3)); > const bool do_use_nmi = use_nmi && (i & BIT(2)); > @@ -262,6 +288,9 @@ int main(int argc, char **argv) > write_proc_irq_smp_affinity_list(irq_affinity_fp, irq, irq_cpu); > } > > + if (migrate_vcpus && vcpu->id == 0) > + migrate_vcpu_threads(nr_vcpus, vcpu_threads, &available_cpus); Meh, rather than shuffle everything in a batch, just change the affinity for the target vCPU. That makes the code easier to read, and is arguably more interesting because there's at least some chance the task will be migrated while the interrupt is being delivered, whereas migrating everything up front means the migrations will have completed before the interrupt is sent the vast majority of the time. > + > for (j = 0; j < nr_vcpus; j++) { > TEST_ASSERT(!GUEST_RECEIVED_IRQ(vcpus[j]), > "IRQ flag for vCPU %d not clear prior to test", > -- > 2.54.0.1032.g2f8565e1d1-goog >