From nobody Tue Nov 26 10:54:26 2024 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 62C5B17C61; Fri, 18 Oct 2024 11:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729252701; cv=none; b=B0dvVfL106wuCIqTpHbqh+Dv/WDB+iBF/leCU85L7lLxq4+zKiQhnxTasDOxjBIYJpRJ1F2PioFaCNbiLTyO8dQEH4UrXrGaj4gF5PZPgVB1sHgNbDXt4+wOCZO9VsEVExjMO8h06mCQC/2SAV+xYn1eJ6wsCQdsnzUQtiBtSvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729252701; c=relaxed/simple; bh=YGAXuv4vpBvANdbwr/v9ZbCdCB90AepDrdWjSENjrGg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J4OpFIufd/d0q9+dQoZ5KeqjdTwcyYlquQxLt8cPNEeDqrZ/fUrVpTxE0yRD4iD6+AVHlOqVKu7z+OjdXmQscobiy9+o1XwZa1b/uWplu39YKdYWPMcFxRQQYDaJsDjmPF19NOgdO+y16JEn1ixTb5+Bdknj6wG8mwHS8d0tNro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=Zgp7pfVz; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="Zgp7pfVz" Received: from namjain-Virtual-Machine.corp.microsoft.com (unknown [131.107.147.150]) by linux.microsoft.com (Postfix) with ESMTPSA id 0C79D20FE9AB; Fri, 18 Oct 2024 04:58:18 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0C79D20FE9AB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1729252698; bh=puHCziW+wtYlhrGuaO6qgn3UMg3ZZmZ85y/SDJsH2cY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zgp7pfVzX3MVf6Z3UiTr365nfNuHh1PxO7V6iVnmZy3IiDOjBxVgN48c4dbDPFc4l sx6u+chbXZzVCpikoiW8MTAlItq164R1rO0ICVEHphTro2TRFRUvOhoqeZmbRgKANP 2vTCLSrxZOi07Ds9YC9Fm7OZLgMgjqMTTw2NgRbA= From: Naman Jain To: "K . Y . Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, Naman Jain , John Starks , jacob.pan@linux.microsoft.com, Easwar Hariharan Subject: [PATCH 1/2] Drivers: hv: vmbus: Wait for offers during boot Date: Fri, 18 Oct 2024 04:58:10 -0700 Message-Id: <20241018115811.5530-2-namjain@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241018115811.5530-1-namjain@linux.microsoft.com> References: <20241018115811.5530-1-namjain@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Channels offers are requested during vmbus initialization and resume from hibernation. Add support to wait for all channel offers to be delivered and processed before returning from vmbus_request_offers. This is to support user mode (VTL0) in OpenHCL (A Linux based paravisor for Confidential VMs) to ensure that all channel offers are present when init begins in VTL0, and it knows which channels the host has offered and which it has not. This is in analogy to a PCI bus not returning from probe until it has scanned all devices on the bus. Without this, user mode can race with vmbus initialization and miss channel offers. User mode has no way to work around this other than sleeping for a while, since there is no way to know when vmbus has finished processing offers. With this added functionality, remove earlier logic which keeps track of count of offered channels post resume from hibernation. Once all offers delivered message is received, no further offers are going to be received. Consequently, logic to prevent suspend from happening after previous resume had missing offers, is also removed. Co-developed-by: John Starks Signed-off-by: John Starks Signed-off-by: Naman Jain Reviewed-by: Easwar Hariharan --- drivers/hv/channel_mgmt.c | 38 +++++++++++++++++++++++--------------- drivers/hv/connection.c | 4 ++-- drivers/hv/hyperv_vmbus.h | 14 +++----------- drivers/hv/vmbus_drv.c | 16 ---------------- 4 files changed, 28 insertions(+), 44 deletions(-) diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 3c6011a48dab..ac514805dafe 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -944,16 +944,6 @@ void vmbus_initiate_unload(bool crash) vmbus_wait_for_unload(); } =20 -static void check_ready_for_resume_event(void) -{ - /* - * If all the old primary channels have been fixed up, then it's safe - * to resume. - */ - if (atomic_dec_and_test(&vmbus_connection.nr_chan_fixup_on_resume)) - complete(&vmbus_connection.ready_for_resume_event); -} - static void vmbus_setup_channel_state(struct vmbus_channel *channel, struct vmbus_channel_offer_channel *offer) { @@ -1109,8 +1099,6 @@ static void vmbus_onoffer(struct vmbus_channel_messag= e_header *hdr) =20 /* Add the channel back to the array of channels. */ vmbus_channel_map_relid(oldchannel); - check_ready_for_resume_event(); - mutex_unlock(&vmbus_connection.channel_mutex); return; } @@ -1297,12 +1285,11 @@ EXPORT_SYMBOL_GPL(vmbus_hvsock_device_unregister); /* * vmbus_onoffers_delivered - * This is invoked when all offers have been delivered. - * - * Nothing to do here. */ static void vmbus_onoffers_delivered( struct vmbus_channel_message_header *hdr) { + complete(&vmbus_connection.all_offers_delivered_event); } =20 /* @@ -1578,7 +1565,8 @@ void vmbus_onmessage(struct vmbus_channel_message_hea= der *hdr) } =20 /* - * vmbus_request_offers - Send a request to get all our pending offers. + * vmbus_request_offers - Send a request to get all our pending offers + * and wait for all offers to arrive. */ int vmbus_request_offers(void) { @@ -1596,6 +1584,10 @@ int vmbus_request_offers(void) =20 msg->msgtype =3D CHANNELMSG_REQUESTOFFERS; =20 + /* + * This REQUESTOFFERS message will result in the host sending an all + * offers delivered message. + */ ret =3D vmbus_post_msg(msg, sizeof(struct vmbus_channel_message_header), true); =20 @@ -1607,6 +1599,22 @@ int vmbus_request_offers(void) goto cleanup; } =20 + /* Wait for the host to send all offers. */ + while (wait_for_completion_timeout( + &vmbus_connection.all_offers_delivered_event, msecs_to_jiffies(10 * 1000= )) =3D=3D 0) { + pr_warn("timed out waiting for all offers to be delivered...\n"); + } + + /* + * Flush handling of offer messages (which may initiate work on + * other work queues). + */ + flush_workqueue(vmbus_connection.work_queue); + + /* Flush processing the incoming offers. */ + flush_workqueue(vmbus_connection.handle_primary_chan_wq); + flush_workqueue(vmbus_connection.handle_sub_chan_wq); + cleanup: kfree(msginfo); =20 diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index f001ae880e1d..8351360bba16 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -34,8 +34,8 @@ struct vmbus_connection vmbus_connection =3D { =20 .ready_for_suspend_event =3D COMPLETION_INITIALIZER( vmbus_connection.ready_for_suspend_event), - .ready_for_resume_event =3D COMPLETION_INITIALIZER( - vmbus_connection.ready_for_resume_event), + .all_offers_delivered_event =3D COMPLETION_INITIALIZER( + vmbus_connection.all_offers_delivered_event), }; EXPORT_SYMBOL_GPL(vmbus_connection); =20 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index d2856023d53c..80cc65dac740 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -287,18 +287,10 @@ struct vmbus_connection { struct completion ready_for_suspend_event; =20 /* - * The number of primary channels that should be "fixed up" - * upon resume: these channels are re-offered upon resume, and some - * fields of the channel offers (i.e. child_relid and connection_id) - * can change, so the old offermsg must be fixed up, before the resume - * callbacks of the VSC drivers start to further touch the channels. + * Completed once the host has offered all channels. Note that + * some channels may still be being process on a work queue. */ - atomic_t nr_chan_fixup_on_resume; - /* - * vmbus_bus_resume() waits for "nr_chan_fixup_on_resume" to - * drop to zero. - */ - struct completion ready_for_resume_event; + struct completion all_offers_delivered_event; }; =20 =20 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 9b15f7daf505..bd3fc41dc06b 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2427,11 +2427,6 @@ static int vmbus_bus_suspend(struct device *dev) if (atomic_read(&vmbus_connection.nr_chan_close_on_suspend) > 0) wait_for_completion(&vmbus_connection.ready_for_suspend_event); =20 - if (atomic_read(&vmbus_connection.nr_chan_fixup_on_resume) !=3D 0) { - pr_err("Can not suspend due to a previous failed resuming\n"); - return -EBUSY; - } - mutex_lock(&vmbus_connection.channel_mutex); =20 list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) { @@ -2456,17 +2451,12 @@ static int vmbus_bus_suspend(struct device *dev) pr_err("Sub-channel not deleted!\n"); WARN_ON_ONCE(1); } - - atomic_inc(&vmbus_connection.nr_chan_fixup_on_resume); } =20 mutex_unlock(&vmbus_connection.channel_mutex); =20 vmbus_initiate_unload(false); =20 - /* Reset the event for the next resume. */ - reinit_completion(&vmbus_connection.ready_for_resume_event); - return 0; } =20 @@ -2502,14 +2492,8 @@ static int vmbus_bus_resume(struct device *dev) if (ret !=3D 0) return ret; =20 - WARN_ON(atomic_read(&vmbus_connection.nr_chan_fixup_on_resume) =3D=3D 0); - vmbus_request_offers(); =20 - if (wait_for_completion_timeout( - &vmbus_connection.ready_for_resume_event, 10 * HZ) =3D=3D 0) - pr_err("Some vmbus device is missing after suspending?\n"); - /* Reset the event for the next suspend. */ reinit_completion(&vmbus_connection.ready_for_suspend_event); =20 --=20 2.34.1 From nobody Tue Nov 26 10:54:26 2024 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F54218028; Fri, 18 Oct 2024 11:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729252699; cv=none; b=GEbnLvst88FGoPQV9hqaJ1ySHZOBiWy2xfkklwnHVc06h2+6A7YR6/OWpcNPz0DO0R5J/aKtjf22lWmeUEGZitrsaegdrnACIJjOJMkLJG4LfLwmHOI/nl5xB5QbsLBKeWTAjoFagbyRZ0dBbe3YNQMw6VP82K06h/Jd4ZqYp/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729252699; c=relaxed/simple; bh=V7l0PvQcRAyt31Veefu5777dqgXNHKMi1nxNw1VdZ0s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=p8JeWHL24AsJbAxfZFroufdSHKSpVSgxaMdUInNxhm/YSfXRHKYgEqG3ES2FRSTvmLrsXKdFYSiZSIayUP0DwBEE4LLz6NxpwZsfar8wRZDwDCWw6u9Gx5OMLH9N48Z4bhDn/4YiOL/Rc7iprh1licYZihSBJ5ZzUJln3Wrv+tA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=qIpl0s3B; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="qIpl0s3B" Received: from namjain-Virtual-Machine.corp.microsoft.com (unknown [131.107.147.150]) by linux.microsoft.com (Postfix) with ESMTPSA id 3358220FE9B9; Fri, 18 Oct 2024 04:58:18 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3358220FE9B9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1729252698; bh=AgkvXZDH7v1BFpc7/7o0bMtbqPdIJtAQPe1CUK+wbLo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qIpl0s3BkG1bDpFcsFn13Y47VOv7Z+PlB8pvGEYmWW9Y5nYX5PXVHFrrIb6Glx6Bn Gw4pKyIPeCW8Vgxyt1ja/50KioS0Hr6shaCJ3VUnSumATV54SQQlKzMPqeaP+YPVZn vYHpYbWB5pr03/CYhlhR1lih/rexTpDgrsivsTJM= From: Naman Jain To: "K . Y . Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, Naman Jain , John Starks , jacob.pan@linux.microsoft.com, Easwar Hariharan Subject: [PATCH 2/2] Drivers: hv: vmbus: Log on missing offers Date: Fri, 18 Oct 2024 04:58:11 -0700 Message-Id: <20241018115811.5530-3-namjain@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241018115811.5530-1-namjain@linux.microsoft.com> References: <20241018115811.5530-1-namjain@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: John Starks When resuming from hibernation, log any channels that were present before hibernation but now are gone. Signed-off-by: John Starks Co-developed-by: Naman Jain Signed-off-by: Naman Jain Reviewed-by: Easwar Hariharan --- drivers/hv/vmbus_drv.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index bd3fc41dc06b..1f56d138210e 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2462,6 +2462,7 @@ static int vmbus_bus_suspend(struct device *dev) =20 static int vmbus_bus_resume(struct device *dev) { + struct vmbus_channel *channel; struct vmbus_channel_msginfo *msginfo; size_t msgsize; int ret; @@ -2494,6 +2495,21 @@ static int vmbus_bus_resume(struct device *dev) =20 vmbus_request_offers(); =20 + mutex_lock(&vmbus_connection.channel_mutex); + list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) { + if (channel->offermsg.child_relid !=3D INVALID_RELID) + continue; + + /* hvsock channels are not expected to be present. */ + if (is_hvsock_channel(channel)) + continue; + + pr_err("channel %pUl/%pUl not present after resume.\n", + &channel->offermsg.offer.if_type, + &channel->offermsg.offer.if_instance); + } + mutex_unlock(&vmbus_connection.channel_mutex); + /* Reset the event for the next suspend. */ reinit_completion(&vmbus_connection.ready_for_suspend_event); =20 --=20 2.34.1