[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] xen/pvcalls: don't call bind_evtchn_to_irqhandler() under lock


  • To: Juergen Gross <jgross@xxxxxxxx>
  • From: Oleksandr Tyshchenko <Oleksandr_Tyshchenko@xxxxxxxx>
  • Date: Tue, 4 Apr 2023 15:36:57 +0000
  • Accept-language: en-US, ru-RU
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PKocZPDzP6zaQ8YHNKIM3Zxni4FGkO63dFSN+bSbAcI=; b=XeIuYHJ+2YvxozHs3wLpoGwpazeDCImpnUX6mve2efRBXjOD1n8KW8hoKHfS6AEFboefL4ycbGzgKpJR0uJShIE49eZokyMSyspNWgXRiTZyHtIspg2KNOX9ST3Ob3gBCK14iimnEo1IurmkPhfXiZhKyeeLZ2xt00s3hpFqpcsNNBRKkL0N7e53nbsw7YBsgoHnnFNML4+GbpeFhZwKtMR7puyAdtRLZms3/Zfe8/H0xGbzGV2AsVxy2jZgLnlzn5SU/Hm8E8nB8ZgoNhdc/Kb6cHKXm5+EmwZt0ILGvA/jYLORB4iK1Hho9x7O/0tftI1u2g8I3Rh+ej+98hl8SA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gi8KtCpTfwUune7wIX/QAE4BEQFpCNh3rzeu2BOTZIATozlX0m6N2HUQLtu7QOm1jAFebugUMMtx3vMXcOVIbW0RMyqTVvZskEnKcuFMuVOgHSSHban9LNa1Bc+d6cHRDtLtbv0qZSpYFOJoIEVfoGZyVvUls6ftq4hMjx84DRPd2Y4l93NTCP70uTDYTi1owYosILU6Pqbk/M7mIYLhrum6yoCldQZqJF5oNOkLZISBIY7UXqKiwhxlryYr70ywlBUjuns0HXkK24uwN0GxQ8ATEmiGaknXX6IE1ovO14w/vwyoJab36MJ681aQZ4T2jWQblgiJo6y1aoboBY+G5A==
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Dan Carpenter <error27@xxxxxxxxx>, "linux-kernel@xxxxxxxxxxxxxxx" <linux-kernel@xxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 04 Apr 2023 15:37:16 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHZZg59s4tqkaRFM0qaTjkzIaVOrq8bSm4A
  • Thread-topic: [PATCH v2] xen/pvcalls: don't call bind_evtchn_to_irqhandler() under lock


On 03.04.23 12:27, Juergen Gross wrote:


Hello Juergen

> bind_evtchn_to_irqhandler() shouldn't be called under spinlock, as it
> can sleep.
> 
> This requires to move the calls of create_active() out of the locked
> regions. This is no problem, as the worst which could happen would be
> a spurious call of the interrupt handler, causing a spurious wake_up().
> 
> Reported-by: Dan Carpenter <error27@xxxxxxxxx>
> Link: 
> https://urldefense.com/v3/__https://lore.kernel.org/lkml/Y*JUIl64UDmdkboh@kadam/__;Kw!!GF_29dbcQIUBPA!wTyU032PQPxqlpIfuWRwb-DYE1K8P0bRWJyJICa7IEbAwQ0_aeZwknAWwxJ_cv_tWGY42f5NPgn6JHtZsiGP$
>  [lore[.]kernel[.]org]
> Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
> ---
> V2:
> - remove stale spin_unlock() (Oleksandr Tyshchenko)


Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>



> ---
>   drivers/xen/pvcalls-front.c | 46 +++++++++++++++++++++----------------
>   1 file changed, 26 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
> index d5d589bda243..b72ee9379d77 100644
> --- a/drivers/xen/pvcalls-front.c
> +++ b/drivers/xen/pvcalls-front.c
> @@ -227,22 +227,30 @@ static irqreturn_t pvcalls_front_event_handler(int irq, 
> void *dev_id)
>   
>   static void free_active_ring(struct sock_mapping *map);
>   
> -static void pvcalls_front_free_map(struct pvcalls_bedata *bedata,
> -                                struct sock_mapping *map)
> +static void pvcalls_front_destroy_active(struct pvcalls_bedata *bedata,
> +                                      struct sock_mapping *map)
>   {
>       int i;
>   
>       unbind_from_irqhandler(map->active.irq, map);
>   
> -     spin_lock(&bedata->socket_lock);
> -     if (!list_empty(&map->list))
> -             list_del_init(&map->list);
> -     spin_unlock(&bedata->socket_lock);
> +     if (bedata) {
> +             spin_lock(&bedata->socket_lock);
> +             if (!list_empty(&map->list))
> +                     list_del_init(&map->list);
> +             spin_unlock(&bedata->socket_lock);
> +     }
>   
>       for (i = 0; i < (1 << PVCALLS_RING_ORDER); i++)
>               gnttab_end_foreign_access(map->active.ring->ref[i], NULL);
>       gnttab_end_foreign_access(map->active.ref, NULL);
>       free_active_ring(map);
> +}
> +
> +static void pvcalls_front_free_map(struct pvcalls_bedata *bedata,
> +                                struct sock_mapping *map)
> +{
> +     pvcalls_front_destroy_active(bedata, map);
>   
>       kfree(map);
>   }
> @@ -433,19 +441,18 @@ int pvcalls_front_connect(struct socket *sock, struct 
> sockaddr *addr,
>               pvcalls_exit_sock(sock);
>               return ret;
>       }
> -
> -     spin_lock(&bedata->socket_lock);
> -     ret = get_request(bedata, &req_id);
> +     ret = create_active(map, &evtchn);
>       if (ret < 0) {
> -             spin_unlock(&bedata->socket_lock);
>               free_active_ring(map);
>               pvcalls_exit_sock(sock);
>               return ret;
>       }
> -     ret = create_active(map, &evtchn);
> +
> +     spin_lock(&bedata->socket_lock);
> +     ret = get_request(bedata, &req_id);
>       if (ret < 0) {
>               spin_unlock(&bedata->socket_lock);
> -             free_active_ring(map);
> +             pvcalls_front_destroy_active(NULL, map);
>               pvcalls_exit_sock(sock);
>               return ret;
>       }
> @@ -821,28 +828,27 @@ int pvcalls_front_accept(struct socket *sock, struct 
> socket *newsock, int flags)
>               pvcalls_exit_sock(sock);
>               return ret;
>       }
> -     spin_lock(&bedata->socket_lock);
> -     ret = get_request(bedata, &req_id);
> +     ret = create_active(map2, &evtchn);
>       if (ret < 0) {
> -             clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT,
> -                       (void *)&map->passive.flags);
> -             spin_unlock(&bedata->socket_lock);
>               free_active_ring(map2);
>               kfree(map2);
> +             clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT,
> +                       (void *)&map->passive.flags);
>               pvcalls_exit_sock(sock);
>               return ret;
>       }
>   
> -     ret = create_active(map2, &evtchn);
> +     spin_lock(&bedata->socket_lock);
> +     ret = get_request(bedata, &req_id);
>       if (ret < 0) {
> -             free_active_ring(map2);
> -             kfree(map2);
>               clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT,
>                         (void *)&map->passive.flags);
>               spin_unlock(&bedata->socket_lock);
> +             pvcalls_front_free_map(bedata, map2);
>               pvcalls_exit_sock(sock);
>               return ret;
>       }
> +
>       list_add_tail(&map2->list, &bedata->socket_mappings);
>   
>       req = RING_GET_REQUEST(&bedata->ring, req_id);

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.