From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423189AbcBZVfI (ORCPT ); Fri, 26 Feb 2016 16:35:08 -0500 Received: from p3plsmtps2ded02.prod.phx3.secureserver.net ([208.109.80.59]:51652 "EHLO p3plsmtps2ded02.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753495AbcBZVfE (ORCPT ); Fri, 26 Feb 2016 16:35:04 -0500 x-originating-ip: 72.167.245.219 From: "K. Y. Srinivasan" To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, vkuznets@redhat.com, jasowang@redhat.com Cc: "K. Y. Srinivasan" Subject: [PATCH 3/8] Drivers: hv: vmbus: remove code duplication in message handling Date: Fri, 26 Feb 2016 15:13:17 -0800 Message-Id: <1456528402-21982-3-git-send-email-kys@microsoft.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1456528402-21982-1-git-send-email-kys@microsoft.com> References: <1456528381-21943-1-git-send-email-kys@microsoft.com> <1456528402-21982-1-git-send-email-kys@microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfCKWJIR0xT20G5hyAPjuWyNnhcXtbP/mB0LTezW0eJlqsO6b5s1PHr8lfgVV1jTbrNFkiI6/XgknNbwg6SE/SY/3dIjY5hJ7Kd2GVCt7DeV2bFb6Veqw Sa5bAzLXwR8cMxrOgcybhkYN4T9YPmU/8ffaFBJEXYXSOJ9Q2yxwwke6AILDP7u1qjMhQ1HZj7qa8k43ekKih/qu3I39Zy2XJ4HXuFLyFmebG0x1sYdFeBtt fXaVuBuaKc7XaHCqow34XBCsOQYnwVPt76bDL/jtlqo8L3tq9mIDlmi1I0z+EIWygeaUgLlz/KUs61rniCGjEO8B79tcYL/FrfGtE5/eEd/o+s/0+4LDPQiw 0dg0f7W7ORifZ/zGIdMwuBr2yOqahVRVMUNostMHj1Gc+hLvAVXS+15z+m2WI8mHRmXbMUE/ Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vitaly Kuznetsov We have 3 functions dealing with messages and they all implement the same logic to finalize reads, move it to vmbus_signal_eom(). Suggested-by: Radim Krcmar Signed-off-by: Vitaly Kuznetsov Reviewed-by: Radim Kr.má Signed-off-by: K. Y. Srinivasan --- drivers/hv/channel_mgmt.c | 10 +--------- drivers/hv/hyperv_vmbus.h | 24 ++++++++++++++++++++++++ drivers/hv/vmbus_drv.c | 40 ++-------------------------------------- 3 files changed, 27 insertions(+), 47 deletions(-) diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index f70e352..73a17be 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -614,15 +614,7 @@ static void vmbus_wait_for_unload(void) if (hdr->msgtype == CHANNELMSG_UNLOAD_RESPONSE) unloaded = true; - msg->header.message_type = HVMSG_NONE; - /* - * header.message_type needs to be written before we do - * wrmsrl() below. - */ - mb(); - - if (msg->header.message_flags.msg_pending) - wrmsrl(HV_X64_MSR_EOM, 0); + vmbus_signal_eom(msg); if (unloaded) break; diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index b0299da..cada56a 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -624,6 +624,30 @@ struct vmbus_channel_message_table_entry { extern struct vmbus_channel_message_table_entry channel_message_table[CHANNELMSG_COUNT]; +/* Free the message slot and signal end-of-message if required */ +static inline void vmbus_signal_eom(struct hv_message *msg) +{ + msg->header.message_type = HVMSG_NONE; + + /* + * Make sure the write to MessageType (ie set to + * HVMSG_NONE) happens before we read the + * MessagePending and EOMing. Otherwise, the EOMing + * will not deliver any more messages since there is + * no empty slot + */ + mb(); + + if (msg->header.message_flags.msg_pending) { + /* + * This will cause message queue rescan to + * possibly deliver another msg from the + * hypervisor + */ + wrmsrl(HV_X64_MSR_EOM, 0); + } +} + /* General vmbus interface */ struct hv_device *vmbus_device_create(const uuid_le *type, diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index c8f1671..6cd12f1 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -709,25 +709,7 @@ static void hv_process_timer_expiration(struct hv_message *msg, int cpu) if (dev->event_handler) dev->event_handler(dev); - msg->header.message_type = HVMSG_NONE; - - /* - * Make sure the write to MessageType (ie set to - * HVMSG_NONE) happens before we read the - * MessagePending and EOMing. Otherwise, the EOMing - * will not deliver any more messages since there is - * no empty slot - */ - mb(); - - if (msg->header.message_flags.msg_pending) { - /* - * This will cause message queue rescan to - * possibly deliver another msg from the - * hypervisor - */ - wrmsrl(HV_X64_MSR_EOM, 0); - } + vmbus_signal_eom(msg); } static void vmbus_on_msg_dpc(unsigned long data) @@ -765,25 +747,7 @@ static void vmbus_on_msg_dpc(unsigned long data) entry->message_handler(hdr); msg_handled: - msg->header.message_type = HVMSG_NONE; - - /* - * Make sure the write to MessageType (ie set to - * HVMSG_NONE) happens before we read the - * MessagePending and EOMing. Otherwise, the EOMing - * will not deliver any more messages since there is - * no empty slot - */ - mb(); - - if (msg->header.message_flags.msg_pending) { - /* - * This will cause message queue rescan to - * possibly deliver another msg from the - * hypervisor - */ - wrmsrl(HV_X64_MSR_EOM, 0); - } + vmbus_signal_eom(msg); } static void vmbus_isr(void) -- 1.7.4.1