From nobody Sat May 18 23:44:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1679996401; cv=none; d=zohomail.com; s=zohoarc; b=Nrv8Gd5mdSZ3fQS7jLfDE72UCRI6QkUFKXD3D1cU/P42Rn7CuK/VUe+GgrMn8GRaBHyCVxhzMjMMYhava9fbcqZhIIqUvV4D79dzxyFKZRwI+2zz45oZB9Vzx/Q+7i0v4A6Zwkf4XZxl2BH3I63FhzL9c2TXZHT3ywx4rLeg9CI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679996401; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=UgfE83B87JnzYkBplYgpUKueaTqClGbainLz0Z27234=; b=MqGZdJGmFHqVgga4lIo3aHjw5eJ5b2LMNJabXgqd+2FJvRhDVbweh8/X5MBrI+AtMviLK3Dp/sWImEqMrYB3LHCx9Slhlhuw9S+nwss1/QS6vI8Ow/53LYgR3yirk3KX6EjbnCacSTwW7rg7jYUDS7yIGdVP01HoZEe4EcAiTAY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1679996400945559.5280640237365; Tue, 28 Mar 2023 02:40:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.515614.798658 (Exim 4.92) (envelope-from ) id 1ph5nf-0007Gj-Tn; Tue, 28 Mar 2023 09:39:31 +0000 Received: by outflank-mailman (output) from mailman id 515614.798658; Tue, 28 Mar 2023 09:39:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ph5nf-0007Gc-Qu; Tue, 28 Mar 2023 09:39:31 +0000 Received: by outflank-mailman (input) for mailman id 515614; Tue, 28 Mar 2023 09:39:30 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ph5ne-0007GW-Ms for xen-devel@lists.xenproject.org; Tue, 28 Mar 2023 09:39:30 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6f91195a-cd4c-11ed-85db-49a42c6b2330; Tue, 28 Mar 2023 11:39:29 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E8C561F8BA; Tue, 28 Mar 2023 09:39:28 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B4D771390B; Tue, 28 Mar 2023 09:39:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 7X7MKtC1ImS8TgAAMHmgww (envelope-from ); Tue, 28 Mar 2023 09:39:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6f91195a-cd4c-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1679996368; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=UgfE83B87JnzYkBplYgpUKueaTqClGbainLz0Z27234=; b=gfW4yDUUcpChSDwKbNwRwXDijsOrfTAYRLllKADw1zl14hMfdZIMuXN3TbT4u6uaSFrDqT Q2vFJQRYFbG8AjjFNyNEcn651PsaOqFI97MLfmMww8FlBy070mZdJ/W+m/I5+RASiIcqQa vOUS4k4u/p/h3gEUPsirmtaOOyp2Jec= From: Juergen Gross To: linux-kernel@vger.kernel.org Cc: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , xen-devel@lists.xenproject.org, Dan Carpenter Subject: [PATCH] xen/pvcalls: don't call bind_evtchn_to_irqhandler() under lock Date: Tue, 28 Mar 2023 11:39:24 +0200 Message-Id: <20230328093924.12260-1-jgross@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1679996403180100001 Content-Type: text/plain; charset="utf-8" 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 Link: https://lore.kernel.org/lkml/Y+JUIl64UDmdkboh@kadam/ Signed-off-by: Juergen Gross --- drivers/xen/pvcalls-front.c | 46 ++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c index d5d589bda243..6e5d712e3115 100644 --- a/drivers/xen/pvcalls-front.c +++ b/drivers/xen/pvcalls-front.c @@ -227,22 +227,31 @@ static irqreturn_t pvcalls_front_event_handler(int ir= q, void *dev_id) =20 static void free_active_ring(struct sock_mapping *map); =20 -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; =20 unbind_from_irqhandler(map->active.irq, map); =20 - 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); + } =20 for (i =3D 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); =20 kfree(map); } @@ -433,19 +442,18 @@ int pvcalls_front_connect(struct socket *sock, struct= sockaddr *addr, pvcalls_exit_sock(sock); return ret; } - - spin_lock(&bedata->socket_lock); - ret =3D get_request(bedata, &req_id); + ret =3D create_active(map, &evtchn); if (ret < 0) { - spin_unlock(&bedata->socket_lock); free_active_ring(map); pvcalls_exit_sock(sock); return ret; } - ret =3D create_active(map, &evtchn); + + spin_lock(&bedata->socket_lock); + ret =3D 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 +829,28 @@ int pvcalls_front_accept(struct socket *sock, struct = socket *newsock, int flags) pvcalls_exit_sock(sock); return ret; } - spin_lock(&bedata->socket_lock); - ret =3D get_request(bedata, &req_id); + ret =3D create_active(map2, &evtchn); if (ret < 0) { + free_active_ring(map2); + kfree(map2); clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, (void *)&map->passive.flags); spin_unlock(&bedata->socket_lock); - free_active_ring(map2); - kfree(map2); pvcalls_exit_sock(sock); return ret; } =20 - ret =3D create_active(map2, &evtchn); + spin_lock(&bedata->socket_lock); + ret =3D 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); =20 req =3D RING_GET_REQUEST(&bedata->ring, req_id); --=20 2.35.3