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

[PATCH] hvc/xen: lock console list traversal


  • To: linux-kernel@xxxxxxxxxxxxxxx
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Tue, 29 Nov 2022 15:31:37 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.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=OMIcbB390IYiCQeoKixgqUua7BwWYTILvEu0+nRR/V0=; b=AiOOum1J87fpNRaAuexpsUv+SF38lNHLAToHOT/tM1BnoZHonCHWgAjTNqS27upXv9R1k0K+tCgVf8OsXQlyuYXgZssmtqluzZ+P9A+k4RuotELtAy+TBomMEYBM6PVOursuQc2gjMwu5IEMeQDtncUTJpYwFOogdNCRLX26/60UeVYzcZ0muQutmcV7L2TmVwtHebx6CKARAxCU+lXW4E6/cJXLD56pMnrDuJytYSOkFliL8KxL4i03ROTzTkKrmnHYxqw5dSAqqOfv/qetUvYYfMN56T3iTjMNDN89PVVUX6hYwMxxV5jjM1hp9fIitzVWaqf9ZujFwgqGvGnHuA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QZKBCbiBTnCEogzgAqYo907pJGWx6+HgXe+ZP7tB8rvm5fEWqmrPxQ48tyOlrn1RZTvP+tyAaje8oLaEfX2Wi6fK4Zj412ZhjPoXuVxHyPj+L64dsqihx3PH0nBprxf6x59TBk8Lg00ttok1ip/65nJS4mirSziuaNGFxtITKAyRWuzsHUA0lXagjVAZW1vKW58dPeLEyHz55tp2i7oRiaqkWyF35cTIpgUBNsQ1tsdTvcxEsmlvY7EfFIDhkYxQtZN0Y9YLONm6wCs3ZaLA44GufPRdev/x2Ukz9KR8/ITppTZXqqdjXgrRsjDK/7oeeKiBMr9YFcs3FycsGhla/w==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>, Jiri Slaby <jirislaby@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>, linuxppc-dev@xxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 29 Nov 2022 14:32:49 +0000
  • Ironport-data: A9a23:GhxPraxsT9CLP1nFSPZ6t+dTxirEfRIJ4+MujC+fZmUNrF6WrkUPz DNOWzrUPqnbYGH8KYxwb4S+8EIAsJaEzddrG1c5rCAxQypGp/SeCIXCJC8cHc8wwu7rFxs7s ppEOrEsCOhuExcwcz/0auCJQUFUjP3OHfykTbaeYUidfCc8IA85kxVvhuUltYBhhNm9Emult Mj75sbSIzdJ4RYtWo4vw//F+U0HUMja4mtC5AVnP6ET5zcyqlFOZH4hDfDpR5fHatE88t6SH 47r0Ly/92XFyBYhYvvNfmHTKxBirhb6ZGBiu1IOM0SQqkEqSh8ai87XAME0e0ZP4whlqvgqo Dl7WT5cfi9yVkHEsLx1vxC1iEiSN4UekFPMCSDXXcB+UyQq2pYjqhljJBheAGEWxgp4KXxy9 fIqdwpSVRe41rKEm6DjFrVFvu12eaEHPKtH0p1h5RfwKK56BLrlE+DN79Ie2yosjMdTG/qYf 9AedTdkcBXHZVtIJ0sTD5U92uyvgxETcRUB8A7T+fVxvDSVkFYZPLvFabI5fvSQQsp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6e3pek52MgaNQ0AEtMDQ+SNRhmpFw0wRw9Fatmsc9bomIqM0q9 jsA+BNrvVjX8UWZaVyCKMqWs2sEFHARhrKLSa7PUnnLqcaIHjAwqSHrYnd3NvaNqDg8aFC2a goCDhjxC4PkgPVeIezNaRwg1/wqD7XZ0Wv9ilcj6IJyoEUCoCbcxFrc2pe7fdIk89vfvEzZM zDR66+e8WTS1cGObw5rTEWCKMiXEU2YYkyhusRfW6oj4biFrDK39arAco7YoCdWgoZZg==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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é <roger.pau@xxxxxxxxxx>
---
 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 (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




 


Rackspace

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