From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E27C53A48F6; Fri, 5 Jun 2026 19:26:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780687587; cv=none; b=vBNpfOhytxNU1Uzpjd5CAQV59YF19BOLdL0eZ+dBKy9y7oiAuPuUCXYAh/n9CYtLhh26aCc6Af2a1Bz0pcpiEAvo7u7D4+x3hJwXkUUeJwBXfSLixLu3FBo9V9SnwzhdG571dtqnHrIxVDnBDVNYpuo1sQw1dPIZWIZ9srNG0E4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780687587; c=relaxed/simple; bh=HfJkDa57jybui0vuoTt7yhA0z+LitAmFSOiu3rAwRv0=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=W67xjDRj+7wgPgbDDW4+yezibHyyQqMT928Fo30apP3OEGkPXBWdgMs+6E9bRdYJyDAkuJ4iy2C49zH57e74+KoMt9kfIyxWt9wTy3yPkY753LtqwAETBJMDGKyH5qQU77rppfrmNO4OuZ9p/8yGO+WxqdiSGjEeUdNZnY+kghE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shazbot.org; spf=pass smtp.mailfrom=shazbot.org; dkim=pass (2048-bit key) header.d=shazbot.org header.i=@shazbot.org header.b=RCwLrvIz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MOBUBTLx; arc=none smtp.client-ip=103.168.172.159 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shazbot.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shazbot.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=shazbot.org header.i=@shazbot.org header.b="RCwLrvIz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MOBUBTLx" Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id D72DA1400147; Fri, 5 Jun 2026 15:26:19 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Fri, 05 Jun 2026 15:26:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shazbot.org; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1780687579; x=1780773979; bh=yNwqrh+OYmCtybS2nQNRCR8l0aa0V6Qbo/uTwuqkPUM=; b= RCwLrvIztI7ZnC8ChfwnOBunaaFGn9he6fyC8xbAGKnQQ+azTYen9AaxJxcqXEto Znx2dfjR2QRj2VLUjLq4GBEWKxnTySkewNKNtCz/sKqnkH3it3B2sXdaz+L7bYw1 ZvJoAWDug5B4IhDgW1g9tdVI57PHAMvkkIAF0r1K3lBgUetEKduh5BktpYiVqMA9 ICEi5p3LgCcHH7zVa0JCcEv7z2aWaB1UEpkxOjl9tR8yjkP7S0CBVQp5J07z0+jU h6ggC76aiMnlZTJRtRH1Ufs6zLUuwzYV++P3EtzPmVcupdIonCSxKAYcutnYhbP9 wBsA0uknKu82Lw/N9MsqWw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1780687579;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zotKBO LJw/gZsTN3L/9kCMZKx15btlkKtMFCXkeFaBZskJcIyyrC03HrmvGwW+39zQ X-ME-Proxy: Feedback-ID: i03f14258:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 5 Jun 2026 15:26:18 -0400 (EDT) Date: Fri, 5 Jun 2026 13:26:15 -0600 From: Alex Williamson To: Junrui Luo Cc: Shameer Kolothum , Yishai Hadas , Jason Gunthorpe , Shay Drory , Kevin Tian , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yuhao Jiang , stable@vger.kernel.org, alex@shazbot.org Subject: Re: [PATCH] vfio: prevent infinite loop in vfio_mig_get_next_state() on blocked arc Message-ID: <20260605132615.50a26aae@shazbot.org> In-Reply-To: References: X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 02 Jun 2026 16:58:48 +0800 Junrui Luo wrote: > vfio_mig_get_next_state() walks vfio_from_fsm_table[] one step at a time, > looping to skip optional states the device does not support until > *next_fsm is supported. A blocked transition is encoded as > VFIO_DEVICE_STATE_ERROR, which the trailing return reports as -EINVAL. > > The skip loop does not account for the ERROR sentinel. > state_flags_table[ERROR] is ~0U and vfio_from_fsm_table[ERROR][*] is > ERROR, so once *next_fsm becomes ERROR the loop condition stays true and > *next_fsm never changes. The blocked arcs STOP_COPY -> PRE_COPY and > STOP_COPY -> PRE_COPY_P2P map to ERROR yet pass the support check on a > precopy-capable device, causing the loop to spin forever while holding > the driver state mutex. This can result in a soft lockup, and a panic > with softlockup_panic set. > > Terminate the skip loop on the ERROR sentinel so a blocked transition > falls through to the existing return and reports -EINVAL. > > Fixes: 4db52602a607 ("vfio: Extend the device migration protocol with PRE_COPY") > Reported-by: Yuhao Jiang > Cc: stable@vger.kernel.org > Signed-off-by: Junrui Luo > --- > drivers/vfio/vfio_main.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c > index 6222376ab6ab..5e0422014523 100644 > --- a/drivers/vfio/vfio_main.c > +++ b/drivers/vfio/vfio_main.c > @@ -858,7 +858,8 @@ int vfio_mig_get_next_state(struct vfio_device *device, > * logical state, as per the above comment. > */ > *next_fsm = vfio_from_fsm_table[cur_fsm][new_fsm]; > - while ((state_flags_table[*next_fsm] & device->migration_flags) != > + while (*next_fsm != VFIO_DEVICE_STATE_ERROR && > + (state_flags_table[*next_fsm] & device->migration_flags) != > state_flags_table[*next_fsm]) > *next_fsm = vfio_from_fsm_table[*next_fsm][new_fsm]; > Applied to vfio next branch for v7.2. Thanks, Alex