From: Ajay Singh <ajay.kathat@microchip.com>
To: Claudiu Beznea <Claudiu.Beznea@microchip.com>
Cc: <linux-wireless@vger.kernel.org>, <devel@driverdev.osuosl.org>,
<gregkh@linuxfoundation.org>, <ganesh.krishna@microchip.com>,
<venkateswara.kaja@microchip.com>, <aditya.shankar@microchip.com>,
<adham.abozaeid@microchip.com>
Subject: Re: [PATCH 12/24] staging: wilc1000: move static variable 'terminated_handle' to wilc_vif struct
Date: Mon, 27 Aug 2018 10:57:31 +0530 [thread overview]
Message-ID: <20180827105731.19919c22@ajaysk-VirtualBox> (raw)
In-Reply-To: <e21007c8-c043-54aa-433e-e7a2467fbda8@microchip.com>
On Fri, 24 Aug 2018 11:46:39 +0300
Claudiu Beznea <Claudiu.Beznea@microchip.com> wrote:
> On 23.08.2018 17:36, Ajay Singh wrote:
> > On Thu, 23 Aug 2018 11:11:18 +0300
> > Claudiu Beznea <Claudiu.Beznea@microchip.com> wrote:
> >
> >> On 14.08.2018 09:50, Ajay Singh wrote:
> >>> Remove the use of static variable 'terminated_handle' and instead
> >>> move in wilc_vif struct.
> >>> After moving this variable to wilc_vif struct its not required to
> >>> keep 'terminated_handle', so changed it to boolean type.
> >>
> >> You can remove it at all and use wilc->hif_deinit_lock mutex also
> >> in wilc_scan_complete_received() and wilc_network_info_received()
> >> it is used in wilc_gnrl_async_info_received().
> >
> > In my understanding, 'terminated_handle' is used to know the
> > status when interface is getting deinit(). During deinitialization
> > of an interface if any async event received for the interface(from
> > firmware) should be ignored.
>
> 'terminated_handle' true only inside mutex. So, outside of it it will
> be false, so *mostly* it will tell you when mutex is locked for
> deinit. *Mostly*, because context switches may happen while a mutex
> is locked.
>
Yes, outside the mutex 'terminated_handle' would be false.
I already agreed that while fixing the bug using 'terminated_handle'
all the scenarios are not handled but as you suggested before
to remove 'terminated_handle' and only use 'mutex' will also not
help to address all corner scenarios. So, I suggest to keep the
current status by making use of this flag and handle all scenario in
later patch to de-initialization graceful.
> With the current approach you have this code:
>
> int wilc_deinit(struct wilc_vif *vif)
> {
> // ...
> mutex_lock(&vif->wilc->hif_deinit_lock);
>
> // (A)
>
> vif->is_termination_progress = true;
> // ...
> vif->is_termination_progress = false;
>
> mutex_unlokc(&vif->wilc->hif_deinit_lock);
> }
>
> And:
>
> void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32
> length) {
> // ...
> if (!hif_drv || vif->is_termination_progress) {
> netdev_err(vif->ndev, "driver not init[%p]\n",
> hif_drv); return;
> }
>
> // ...
>
> // (B)
> result = wilc_enqueue_work(msg);
> // ...
> }
>
> And:
>
> static int wilc_enqueue_work(struct host_if_msg *msg)
>
> {
>
> INIT_WORK(&msg->work, msg->fn);
>
>
>
> if (!msg->vif || !msg->vif->wilc
> || !msg->vif->wilc->hif_workqueue)
>
> return -EINVAL;
>
>
> // (C)
> if (!queue_work(msg->vif->wilc->hif_workqueue, &msg->work))
>
> return -EINVAL;
>
>
>
> return 0;
>
> }
>
>
> You may have the following scenario:
> 1. context switch in wilc_deinit() just after the mutex is taken
> (point A above). vif->is_termination_progress = false at this point.
>
> 2. a new packet is received and wilc_network_info_received() gets
> executed and execution reaches point B, goes to wilc_enqueue_work()
> and suspend at point C then context switch.
>
Thanks for explaining the scenario with an example.
For the given scenario, I think not only here it can even suspend
after posting the work queue and start the execution of handler
function eg. handle_recvd_gnrl_async_info()(there is no protection in
handle function)
There are some combination of these scenario, I will relook into these
cases and check how to handle them separately.
> 3. wilc_deinit() resumes and finish its execution.
>
> 4. wilc_enqueue_work() resumes and queue_work() is executed but you
> already freed the hif_workqueue. You will have a crash here.
>
> Notice that hif_drv is not set to NULL on wilc_deinit() after it is
> kfree().
>
> >
> > In my opinion its not right to only wait for the mutex in any of
> > callback e.g wilc_scan_complete_received() because it will delay the
> > handling of callback and try to process the event once lock is
> > available for the interface which is already de-initialized.
>
> But this is already done for wilc_gnrl_async_info_received().
>
> >
> > Based on my understand 'mutex' alone is not enough to
> > handle this and we some extra check to know if interface is down.
>
> terminated_handle will *mostly* tell you when the mutex is locked,
> nothing more.
>
> I will
> > check more about this patch how to handle the extra scenario for
> > this case.
> > Please suggest if someone has better idea on how to handle this.
> >
next prev parent reply other threads:[~2018-08-27 9:12 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-14 6:49 [PATCH 00/24] staging: wilc1000: avoid use of static and global variable Ajay Singh
2018-08-14 6:49 ` [PATCH 01/24] staging: wilc1000: move 'wilc_enable_ps' global variable into 'wilc' struct Ajay Singh
2018-08-14 6:49 ` [PATCH 02/24] staging: wilc1000: move 'aging_timer' static variable to wilc_priv struct Ajay Singh
2018-08-14 6:49 ` [PATCH 03/24] staging: wilc1000: fix to use correct index to free scanned info in clear_shadow_scan() Ajay Singh
2018-08-14 6:49 ` [PATCH 04/24] staging: wilc1000: remove unnecessary NULL check " Ajay Singh
2018-08-14 6:49 ` [PATCH 05/24] staging: wilc1000: moved last_scanned_shadow & last_scanned_cnt to wilc_priv struct Ajay Singh
2018-08-14 6:49 ` [PATCH 06/24] staging: wilc1000: move during_ip_timer & wilc_optaining_ip to 'wilc_vif' struct Ajay Singh
2018-08-23 8:09 ` Claudiu Beznea
2018-08-23 9:43 ` Ajay Singh
2018-08-24 8:47 ` Claudiu Beznea
2018-08-14 6:49 ` [PATCH 07/24] staging: wilc1000: remove unused variable 'op_ifcs' Ajay Singh
2018-08-14 6:50 ` [PATCH 08/24] staging: wilc1000: avoid use of extra 'if' condition in wilc_init() Ajay Singh
2018-08-14 6:50 ` [PATCH 09/24] staging: wilc1000: move static variable clients_count to 'wilc' structure Ajay Singh
2018-08-23 8:09 ` Claudiu Beznea
2018-08-25 0:13 ` Adham Abozaeid
2018-08-14 6:50 ` [PATCH 10/24] staging: wilc1000: move wilc_multicast_mac_addr_list to 'wilc_vif' struct Ajay Singh
2018-08-23 8:10 ` Claudiu Beznea
2018-08-23 10:00 ` Ajay Singh
2018-08-24 8:47 ` Claudiu Beznea
2018-08-25 0:32 ` Adham Abozaeid
2018-08-27 5:40 ` Ajay Singh
2018-08-14 6:50 ` [PATCH 11/24] staging: wilc1000: move hif specific static variables to 'wilc' structure Ajay Singh
2018-08-23 8:11 ` Claudiu Beznea
2018-08-23 10:09 ` Ajay Singh
2018-08-24 8:47 ` Claudiu Beznea
2018-08-14 6:50 ` [PATCH 12/24] staging: wilc1000: move static variable 'terminated_handle' to wilc_vif struct Ajay Singh
2018-08-23 8:11 ` Claudiu Beznea
2018-08-23 14:36 ` Ajay Singh
2018-08-24 8:46 ` Claudiu Beznea
2018-08-27 5:27 ` Ajay Singh [this message]
2018-08-14 6:50 ` [PATCH 13/24] staging: wilc1000: move 'periodic_rssi' as part of 'wilc_vif' struct Ajay Singh
2018-08-14 6:50 ` [PATCH 14/24] staging: wilc1000: rename 'dummy_statistics' variable to 'periodic_stat' Ajay Singh
2018-08-14 6:50 ` [PATCH 15/24] staging: wilc1000: move 'rcv_assoc_resp' as part of hif_drv Ajay Singh
2018-08-14 6:50 ` [PATCH 16/24] staging: wilc1000: refactor tcp_process() to avoid extra leading tabs Ajay Singh
2018-08-14 6:50 ` [PATCH 17/24] staging: wilc1000: use lowercase for get_BSSID() and HIL variable Ajay Singh
2018-08-14 6:50 ` [PATCH 18/24] staging: wilc1000: move tcp_ack_filter algo related variables to 'wilc_vif' struct Ajay Singh
2018-08-14 6:50 ` [PATCH 19/24] staging: wilc1000: avoid line over 80 chars in wilc_wlan_txq_filter_dup_tcp_ack() Ajay Singh
2018-08-23 8:11 ` Claudiu Beznea
2018-08-23 12:18 ` Ajay Singh
2018-08-14 6:50 ` [PATCH 20/24] staging: wilc1000: avoid line over 80 chars in tcp_process() Ajay Singh
2018-08-23 8:12 ` Claudiu Beznea
2018-08-23 10:33 ` Ajay Singh
2018-08-24 9:31 ` Claudiu Beznea
2018-08-27 5:24 ` Ajay Singh
2018-08-27 12:00 ` Dan Carpenter
2018-08-28 4:29 ` Ajay Singh
2018-08-14 6:50 ` [PATCH 21/24] staging: wilc1000: remove unused code to set and get IP address Ajay Singh
2018-08-14 6:50 ` [PATCH 22/24] staging: wilc1000: move 'chip_ps_state' static variable as part of 'wilc' struct Ajay Singh
2018-08-14 6:50 ` [PATCH 23/24] staging: wilc1000: move 'wilc_connecting' static variable to 'wilc_vif' struct Ajay Singh
2018-08-23 8:12 ` Claudiu Beznea
2018-08-23 10:55 ` Greg KH
2018-08-23 11:27 ` Ajay Singh
2018-08-23 12:37 ` Dan Carpenter
2018-08-23 13:06 ` Ajay Singh
2018-08-14 6:50 ` [PATCH 24/24] staging: wilc1000: remove unnecessary static variable 'p2p_listen_state' Ajay Singh
2018-08-23 8:13 ` Claudiu Beznea
2018-08-23 12:07 ` Ajay Singh
2018-08-23 8:09 ` [PATCH 00/24] staging: wilc1000: avoid use of static and global variable Claudiu Beznea
2018-08-23 9:35 ` Ajay Singh
2018-08-27 17:10 ` Greg KH
2018-08-28 4:35 ` Ajay Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180827105731.19919c22@ajaysk-VirtualBox \
--to=ajay.kathat@microchip.com \
--cc=Claudiu.Beznea@microchip.com \
--cc=adham.abozaeid@microchip.com \
--cc=aditya.shankar@microchip.com \
--cc=devel@driverdev.osuosl.org \
--cc=ganesh.krishna@microchip.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-wireless@vger.kernel.org \
--cc=venkateswara.kaja@microchip.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.