From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 F17792BFC60 for ; Thu, 4 Jun 2026 19:35:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780601732; cv=none; b=CgAUHSYtHhjY7n0N8Iw5kMKyr7MinPg4L2rlZJXGAK84s1j7klIHOUpqzGWjszwHTB+TUqv7P3QhPrwiITErn/IilKCrBZFeKbaPCxL8+vpsMO3l+Mr9xcAOxtCSDnRx7bV73qAJaFjq2CF8w6ZbbVVK2L/pAhKK//gdSLkuKik= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780601732; c=relaxed/simple; bh=1YofZpMtmmjQnKJt0AyFwdSGGDzL0tWdXXGyeCPJD5Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RtIkmTLVbgPwfhhL0M+cF18EFqMq9/y6Sfn7T3wEZCnBqL+kAjRYJbvGK3GmHKm+GvI0x6BKMLXe1XKDB8r3b0ME/RagsDIHlfDhkFxoXCwkWggFSkDxHZf+uKScka+ArHOSvDsLxeUtp2e6FKpq2aV63CLaBkvVBzBy35dw458= 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=mTQ1DiI4; arc=none smtp.client-ip=209.85.214.202 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="mTQ1DiI4" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2c0c20f7581so13569635ad.0 for ; Thu, 04 Jun 2026 12:35:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780601729; x=1781206529; 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=GNHuzQnVw7DPfnDwqoqnw8wQUPfIpTU62drof68ZIpc=; b=mTQ1DiI4ydiJr/5kaIBGZmMlUoRIoiY6xvj04WNJGYaTApORLIYwkX87QftEvWRVkl Rwca3oXQRd/vzqwzad0k6TT8ceas/ttYYjEuZMa2vODhZs5JUcnswDlBPIzU8QV/VInH UCQaaL1BM6XfLxvbEvazuZTjK+/bKRkeS5YMDo9Zvjrjo4yD9n9sL3pQHMSoWtLML2Eu HMPJu7NWzUyILs0AKrbAgpC8vBZ9tIHn3fT4tdIk0I2JIodILTMpbiLpmYXnDuXuJmlr Qy56DbHSJ2LiTKje3Iyeqnf/uCmcMo7654c3Bch8bfk2/ERq4FVMynlOdDNZaCpmzvNb UAYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780601729; x=1781206529; 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=GNHuzQnVw7DPfnDwqoqnw8wQUPfIpTU62drof68ZIpc=; b=PkBMVCc5Cthglr0xKE5nUHcEIeZYeYeJfhfZhm8XO03fcjV5whVzuLAjuwe+cd2YoE uRZxn5BhuOHkMPkENueFz1ANj7P9eB0no4aTamJwK7OrnJ0ShCAwYcBoZ104nDF7YMuQ kMG5ZQAjZ4XsoSTidYy6EYDgLc05epQS7J4D+HIvwY2Q725Cpju1rHh06T2tRNPH5WXv m8vY8TBF6J9R0O6zY7oYT3X+DOJ7gd1X8WqSNcyrRthizsmp0SeljkTEVU9cwl6yRUsZ sTHHqaK/IgSNaDP7VWpQpS26Akr20v/xivNa/ynRe11NKcTtPlnBWIkaHPCwJht/GKZ9 e71Q== X-Forwarded-Encrypted: i=1; AFNElJ9+5e3Bcz6ZkkqQTrk39szc7ACSRAOal2wZdrwHC4AXGxylAzq96JINoDTV6ci2esaKKpYu0aKO5eEjYiE=@vger.kernel.org X-Gm-Message-State: AOJu0Yy4AQ/y5y9p1+3x7oRrNMw2ZDzEWuaCIWvHXUjc4azuRHTBv2hr r+5vYW5MFrnVsJ87KgYWMXUZ5lNZVgI37Crv0hLCY7al7kLzaxF1CJog3AOonP20ibiFo3qZLVM xCM3Y5Q== X-Received: from plzv5.prod.google.com ([2002:a17:902:b7c5:b0:2bd:1ca5:b928]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ced1:b0:2c0:fa4e:91f6 with SMTP id d9443c01a7336-2c1e7d41eabmr291435ad.13.1780601729026; Thu, 04 Jun 2026 12:35:29 -0700 (PDT) Date: Thu, 4 Jun 2026 12:35:28 -0700 In-Reply-To: <20260604020143.748245-9-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-9-jrhilke@google.com> Message-ID: Subject: Re: [PATCH v5 08/21] KVM: selftests: Add helpers to write proc IRQ affinity for 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: > diff --git a/tools/testing/selftests/kvm/lib/proc_util.c b/tools/testing/selftests/kvm/lib/proc_util.c > index 84d30f055a0a..938c90d94f4d 100644 > --- a/tools/testing/selftests/kvm/lib/proc_util.c > +++ b/tools/testing/selftests/kvm/lib/proc_util.c > @@ -38,3 +38,23 @@ unsigned int vfio_msix_to_host_irq(const char *device_bdf, int msix) > return (unsigned int)irq; > } > > +FILE *open_proc_irq_smp_affinity_list(unsigned int irq) > +{ > + char path[PATH_MAX]; > + FILE *fp; > + > + snprintf(path, sizeof(path), "/proc/irq/%u/smp_affinity_list", irq); > + fp = fopen(path, "w"); > + TEST_ASSERT(fp, "fopen(%s) failed", path); > + > + return fp; > +} > + > +void write_proc_irq_smp_affinity_list(FILE *fp, unsigned int irq, int irq_cpu) > +{ > + int ret; > + > + ret = fprintf(fp, "%d\n", irq_cpu); > + TEST_ASSERT(ret > 0, "Failed to affinitize IRQ-%u to CPU %d", irq, irq_cpu); > + fflush(fp); As Sashiko points out, this is prone to failing silently. But rather than just "fix" that issue, this can be simplified to avoid the complexity of flushing buffers in the first place. That will also allow fixing another flaw: if the caller passes in the wrong, file, debugging the resulting failure will be annoying. I see no reason to risk that, it's not like opening a single file is going to meaningfully impact overall runtime. All in all, just this? void proc_irq_set_smp_affinity(unsigned int irq, int cpu) { char path[PATH_MAX]; int r, fd; snprintf(path, sizeof(path), "/proc/irq/%u/smp_affinity_list", irq); fd = open(path, O_RDWR); TEST_ASSERT(fd >= 0, "Failed to open %s", path); r = dprintf(fd, "%d\n", cpu); TEST_ASSERT(r > 0, "Failed to affinitize IRQ-%u to CPU %d", irq, cpu); kvm_close(fd); }