Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1502542rwb; Tue, 29 Nov 2022 14:40:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf6wtL7vknqIN20KRRN26MY8z/RSHiGgkzmVr9UjBy2OjkjghLe/UyKaEmbq6jTq4U4mqP0i X-Received: by 2002:a17:902:7009:b0:189:71b9:6183 with SMTP id y9-20020a170902700900b0018971b96183mr20713684plk.121.1669761611822; Tue, 29 Nov 2022 14:40:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669761611; cv=none; d=google.com; s=arc-20160816; b=XeS3apsaTbts1foqCHdlONzGup/G1FOq+hWqbZ2TJREkgNH3vyNEhSyC4/btvVzFcp SM9cxUM9bj8poWvwCm9hWaOqhdK8oYOiiyBhx2YBu7I3aIxTfdTDtqrG3WA5zJdZpP0e Hfval3NUSZVgjL7SMArSxWYNJ2vB1rBUeyRmAsDqnlJ7RHNLQzKwekQep3X/VK0foSqt gtsQH00ZJiweW6rZkIvgY6wlYeQ6BkO40YcNs56z8MNORrNV4eFn2nCfD0q5dsW9XAM2 EL/HZZvyZ8DpPO7s2A/IrGMAoJFr0mkcAbO/AO+eN5Vw7gtyr08BkTF6B5FmYBEIO8la 9BeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-id:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=I9DvgOodQtYKq+s929M3Oa28qfba53fG+rP30HDu9KA=; b=Mg5xe0QrVFu5bm7LMhdH8MC7ysEiOCVwYhxhWA4jYUw3HTKElssPP3hEv1Y/uhXnE9 a6GwuEK430WqrYuEmoeOAH+5Yt4CM6WXFtRrn/+SA/NXFIzyi4NQMd/+6AG++hw37rRc a2LVC3jyZ5T6nkaaeDOdzKBa+K/00tudf9FkpcjoopXCBxbxMEzP84Iu6QPTtGgkIA0U RtXBrLMlBHaWeC4aozTPESlHfrP9f1eBVSkSikOdjUKofCzVFD2Gbs8yIXYv0ON5ZX// Skt3E1RkOFYkoKMGQmVhYpuui0/tLxWn05vBTk1GYagO+fmsXTlGTUrDCoD1gDn+oTf6 q/Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bcuwe401; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j190-20020a638bc7000000b0041a4bf40469si16125911pge.271.2022.11.29.14.40.00; Tue, 29 Nov 2022 14:40:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bcuwe401; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236780AbiK2WZS (ORCPT + 84 others); Tue, 29 Nov 2022 17:25:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236051AbiK2WZQ (ORCPT ); Tue, 29 Nov 2022 17:25:16 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 411976D964 for ; Tue, 29 Nov 2022 14:25:16 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CB02161959 for ; Tue, 29 Nov 2022 22:25:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEBD4C433D6; Tue, 29 Nov 2022 22:25:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669760715; bh=MTi3eCesRlzQNLX++3E0N9zK19ByIHxrBbpWGeJzPsc=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=bcuwe4011W1EV7m7lqiLQCoubqhZSBuRQ4IFeHON2n+irELW9/XO4T1BNRrd3sFQG C8iloTFvWqOLLjrasPmVZmRvL21w4m6XgrxeaQN0n4oMWpI5BcMR7N1pRcEDfOKd6l qXAWhElGrrP2DeS840ArAoGgl089SvzMDKI7/ex75BkDHXInBDU4I0NddEENZLVRQv iicP73qxnn1g0HG4cOdXTIzzhHBtWPP3wYxFDpAREURYvnonHpJ2DMGLPlUgEZrEnZ 1AFf1zpagYRmQrVpTa5kXCcEa1QdfAR0C2uN9O1uzX9dqGVrTqTYdfMPg4D8nRlPOF ycJ+Oe2l21X8A== Date: Tue, 29 Nov 2022 14:25:12 -0800 (PST) From: Stefano Stabellini X-X-Sender: sstabellini@ubuntu-linux-20-04-desktop To: Roger Pau Monne cc: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, Greg Kroah-Hartman , Jiri Slaby , Juergen Gross , Stefano Stabellini , Boris Ostrovsky , Jan Beulich , Konrad Rzeszutek Wilk , linuxppc-dev@lists.ozlabs.org Subject: Re: [PATCH] hvc/xen: lock console list traversal In-Reply-To: <20221129143145.4234-1-roger.pau@citrix.com> Message-ID: References: <20221129143145.4234-1-roger.pau@citrix.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="8323329-503985613-1669760387=:4039" Content-ID: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-503985613-1669760387=:4039 Content-Type: text/plain; CHARSET=UTF-8 Content-Transfer-Encoding: 8BIT Content-ID: On Tue, 29 Nov 2022, Roger Pau Monne wrote: > The currently lockless access to the xen console list in > vtermno_to_xencons() is incorrect, as additions and removals from the > list can happen anytime, and as such the traversal of the list to get > the private console data for a given termno needs to happen with the > lock held. Note users that modify the list already do so with the > lock taken. > > While there switch from using list_for_each_entry_safe to > list_for_each_entry: the current entry cursor won't be removed as > part of the code in the loop body, so using the _safe variant is > pointless. > > Fixes: 02e19f9c7cac ('hvc_xen: implement multiconsole support') > Signed-off-by: Roger Pau Monné > --- > drivers/tty/hvc/hvc_xen.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c > index d65741983837..117dc48f980e 100644 > --- a/drivers/tty/hvc/hvc_xen.c > +++ b/drivers/tty/hvc/hvc_xen.c > @@ -53,17 +53,22 @@ static DEFINE_SPINLOCK(xencons_lock); > > static struct xencons_info *vtermno_to_xencons(int vtermno) > { > - struct xencons_info *entry, *n, *ret = NULL; > + struct xencons_info *entry, *ret = NULL; > + unsigned long flags; > > - if (list_empty(&xenconsoles)) > - return NULL; > + spin_lock_irqsave(&xencons_lock, flags); If xencons_lock requires irqsave then we need to change all the xencons_lock spinlocks to call irqsave, including the ones in xen_hvm_console_init if they can happen at runtime. > + if (list_empty(&xenconsoles)) { > + spin_unlock_irqrestore(&xencons_lock, flags); > + return NULL; > + } > > - list_for_each_entry_safe(entry, n, &xenconsoles, list) { > + list_for_each_entry(entry, &xenconsoles, list) { > if (entry->vtermno == vtermno) { > ret = entry; > break; > } > } > + spin_unlock_irqrestore(&xencons_lock, flags); > > return ret; > } > -- > 2.37.3 > --8323329-503985613-1669760387=:4039--