From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796278091; b=xtlloWhdTClbXos6SlnMgYZm/l1Q+yNnHhzks2P3BICFZJa2+cn46NIxoBu23Pi1HdaV XzGAqWuN4SOwJbq+64vJXLyL7Clle2ASjbyxT9z/Dnjdn8zP2ByLt3DimOYieR8K0TqWO TqEGAvVs3KYbbFep2isGMMOQ28GytWONWuzh1uDi+Ia06rLAvy6gdEc6v029VnUnWs5Dm q+d11eTbeP3sji4PlKPW0T1lDY4Tg36o6dnpydy04c4DM/a/8xHU8fal2S4Szs8ywF0Fa Iv7EACUWE6B1HT3abZspt7jLr+UOIBKq9p91gpG1Bm8lcxbnmAhv3Ipdmg0zMufxmWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796278091; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=zl+t3bxPTvZtFDHjQQScsRWBtVRp5EAyF6ouE0Kbj4I=; b=MdhNEmylBKuGydwGOUbZrRNTRsG6YP83eTCmbrQAcLm4Nsu31JujPUCy5oocH2EgbSUi vXLzY+mDCluka471Q1KUtkR7nsAC2QcLO2RNKNE595HP49A0t7ooVOmZY0M64i63oBi2i OWaFN+dyCh1BkzF04WV6QJSuGwjfWx7m0/gCGTPMAThBS2AVd7vDNcx+huu7pIWoVn0yO 3W3T7MEQL8DdQyaOzB3SueCiHHwbI8VaVXW2qgMYg/D2kiqrnOOBUzONY/XwKuHelEKB8 U/pAFgurRZF5AQ/lakH8fxGv7QF1tbkbWftfMURI5g29fT3MPAhsZZWAY4Xk+dsB7VA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=m+5N6xvu; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEB27606A322 for ; Thu, 3 Dec 2026 06:08:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=m+5N6xvu Received: by smtp.kernel.org (Postfix) with ESMTPSA id A88B61F000C1; Thu, 3 Dec 2026 06:08:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796278091; bh=zl+t3bxPTvZtFDHjQQScsRWBtVRp5EAyF6ouE0Kbj4I=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=m+5N6xvuTl9ida5WOKVBtQsNOigVD2v5UNIl5gXvywhf8a6LnwfqJi2SGnEIDy1lk zSNUCdxid4k0W5rfozSbopySda2/z2lJLCqCRxshSlFJUPpu3G0wrHjvRwDGh75jqW FZRob+rdxZAavILgZnw/16gbTAu0jYdBJu5gnUBml+Q2o5gx49PGoKzRgcDnVoYCCV p1/WXWntYqnZYAY711STt5ltGipoRzgKMILt+KzgcbFysAD1mEwkHfhfdhSgb6IoPq 2CVzki2vPaGu3pBvrOF+6OFjX3VsuionVzzZ3ZNtqN3khsxHZhk3YDgW4BQBAuniUy M8df0G4YjVKMg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] mshv_vtl: Add a per-CPU transition statistics ioctl Reply-To: sashiko-reviews@lists.linux.dev To: "Naman Jain" Cc: linux-hyperv@vger.kernel.org In-Reply-To: <20261203054302.3544702-1-namjain@linux.microsoft.com> References: <20261203054302.3544702-1-namjain@linux.microsoft.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 06:08:11 +0000 X-Mailing-List: linux-hyperv@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] mshv_vtl: raw_spinlock_t on VTL switch path causes VP stalls and EAGAIN UAPI - [Medium] mshv_vtl: unaligned per-CPU mshv_vtl_cpu_stats causes cacheline false sharing -- commit 24b3fa8944af399cfdbaaec1aa9176459c9fd6c9 Author: Naman Jain mshv_vtl: Add a per-CPU transition statistics ioctl This commit adds the MSHV_GET_VTL_STATS ioctl and per-CPU accounting to track lower-VTL entry/exit counts, timestamps, and elapsed durations. > diff --git a/drivers/hv/mshv_vtl_main.c b/drivers/hv/mshv_vtl_main.c > index 2d4fe24cecbff..b7cb5817dd5b3 100644 > --- a/drivers/hv/mshv_vtl_main.c > +++ b/drivers/hv/mshv_vtl_main.c [ ... ] > @@ -102,7 +104,16 @@ static union hv_register_vsm_page_offsets mshv_vsm_p= age_offsets; > static union hv_register_vsm_capabilities mshv_vsm_capabilities; > =20 > static DEFINE_PER_CPU(struct mshv_vtl_poll_file, mshv_vtl_poll_file); > -static DEFINE_PER_CPU(unsigned long long, num_vtl0_transitions); > + > +struct mshv_vtl_cpu_stats { > + raw_spinlock_t lock; > + struct mshv_vtl_stats stats; > +}; > + > +static DEFINE_PER_CPU(struct mshv_vtl_cpu_stats, mshv_vtl_cpu_stats) =3D= { > + .lock =3D __RAW_SPIN_LOCK_UNLOCKED(mshv_vtl_cpu_stats.lock), > +}; > + > static DEFINE_PER_CPU(struct mshv_vtl_per_cpu, mshv_vtl_per_cpu); [Severity: Medium] Should mshv_vtl_cpu_stats use DEFINE_PER_CPU_SHARED_ALIGNED() to avoid cacheline false sharing? With plain DEFINE_PER_CPU(), this 88-byte structure sits unaligned between mshv_vtl_poll_file (80 bytes, ending with poll_file->cpu read remotely in mshv_vtl_poll_file_wake()) and mshv_vtl_per_cpu (read remotely via mshv_vtl_cpu_run() in mshv_vtl_cancel()). Local stats updates on every VTL switch then bounce cachelines shared with remote wakeups and stats queries, and can touch three cachelines instead of two. [ ... ] > @@ -649,6 +660,36 @@ static int mshv_vtl_get_set_reg(struct hv_register_a= ssoc *regs, bool set) > return 1; > } > =20 > +static void mshv_vtl_record_transition(bool entering) > +{ > + struct mshv_vtl_cpu_stats *cpu_stats =3D this_cpu_ptr(&mshv_vtl_cpu_sta= ts); > + struct mshv_vtl_stats *stats =3D &cpu_stats->stats; > + u64 now, elapsed; > + > + raw_spin_lock(&cpu_stats->lock); > + now =3D ktime_get_ns(); [ ... ] > + raw_spin_unlock(&cpu_stats->lock); > +} [ ... ] > +static long mshv_vtl_ioctl_get_stats(struct mshv_vtl_stats __user *user_= stats) > +{ > + struct mshv_vtl_cpu_stats *cpu_stats; > + struct mshv_vtl_stats stats; > + unsigned long flags; > + u32 cpu; > + > + if (get_user(cpu, &user_stats->cpu)) > + return -EFAULT; > + if (cpu >=3D nr_cpu_ids || !cpu_possible(cpu)) > + return -EINVAL; > + > + cpu_stats =3D per_cpu_ptr(&mshv_vtl_cpu_stats, cpu); > + if (!raw_spin_trylock_irqsave(&cpu_stats->lock, flags)) > + return -EAGAIN; > + stats =3D cpu_stats->stats; > + stats.cpu =3D cpu; > + stats.snapshot_ns =3D ktime_get_ns(); > + raw_spin_unlock_irqrestore(&cpu_stats->lock, flags); > + > + return copy_to_user(user_stats, &stats, sizeof(stats)) ? -EFAULT : 0; > +} [Severity: Medium] Can this use a per-CPU seqcount_t instead of raw_spinlock_t? mshv_vtl_record_transition() only runs from mshv_vtl_return() with preemption and IRQs disabled, so each per-CPU instance has a single local writer. Taking raw_spinlock_t adds two atomic RMW lock/unlock cycles and two ktime_get_ns() calls to every lower-VTL switch even when stats are never queried. When userspace polls MSHV_GET_VTL_STATS from another CPU, raw_spin_trylock_irqsave() dirties the target VP's cacheline and holds the lock across the struct copy and ktime_get_ns(), stalling the IRQ-disabled VP in raw_spin_lock(). Because hv_vcpu_is_preempted() always returns false under Hyper-V, host preemption of the reader vCPU magnifies that spin stall. Using trylock also exposes internal contention as -EAGAIN in the permanent UAPI (including between concurrent readers of an idle or offline CPU). A per-CPU seqcount_t keeps the local writer wait-free without atomic RMWs, prevents remote readers from stalling VPs, and removes -EAGAIN from the interface. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203054302.3544= 702-1-namjain@linux.microsoft.com?part=3D1