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

Re: [PATCH] hvc/xen: prevent concurrent accesses to the shared ring


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Wed, 30 Nov 2022 11:10:32 +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=DTzxxCZ+Kq9uX93zQZa8I0RFtDAt2genjXSVBUCq8JI=; b=jW14PKRD+ei8o+EnK+KZ8NJ61DMQedOBQl6RMMV5aeiYgPFhnWIrmldy4Svk6o3gVCV86yZrstAwBd1VhZIJLDEE0iIhh+BxPuLtKpL+Mo6pV6q2TugLDanQHZvX1JM9uZWFzWjjO5wiq82MIGUqTvOrO34muTwMKkX4rvNbQS18xYk0fsWKDImHQKargVJegNa6r8RWjm4HsyOzV2x0Gvdh5dcpva0faCUYUfpU0sBR7USm/wiCo8nsNyLV3IR0BbW/Lr/tjs1HDfDwrJRN73w+aCVGkq8/21W9qmnK+9I4Ne08ZmT4gWvtC7dn0UE/VOI268bTaX5BuVOa4pLOjA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CZSxt/gR2W64BWQZ5+oqJDk0093zuxW+2EKC8/QLcNfPWHu/dyU3dIe2D8cjYiZEmLwOzl/fq6SWEfbTkUtuI6mzAWUsIdym2RSmw30SWfcdyCBSVNPxY7ozbVxQrH3EJrUuXB0l/UZQku70IF2UUDeq75zi0P375wyjNxNnCF3yDw7T2FqDyx/W5CHUiMnsxlMSiGjGeyDlqp8HUzTD2k85AeZXuN1HvxSfmE5ctUQIz8U/fd1pp00Yuq1ZFHmOM6LK9qMheSRgCW+4ibdlMLg8NXWLdZxnazDIgnkDkckhaIGGBzSxfP08gY1h6Y3zrnPRMdiyCa1KG3qYSiUNfg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: linux-kernel@xxxxxxxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>, Jiri Slaby <jirislaby@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>, Olof Johansson <olof@xxxxxxxxx>, Ingo Molnar <mingo@xxxxxxx>, Chris Wright <chrisw@xxxxxxxxxxxx>, linuxppc-dev@xxxxxxxxxxxxxxxx, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Wed, 30 Nov 2022 10:11:04 +0000
  • Ironport-data: A9a23:PzltvqM0wtnI1k/vrR3el8FynXyQoLVcMsEvi/4bfWQNrUok3z1Vy mdOC22Caa7cazehKN9/atm/9h4BuZ+AmIcwHAto+SlhQUwRpJueD7x1DKtS0wC6dZSfER09v 63yTvGacajYm1eF/k/F3oDJ9CU6jufQA+KmU4YoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGj9SuvzrRC9H5qyo4mpB5QRmP5ingXeF/5UrJMNHTU2OByOQrrl8RoaSW +vFxbelyWLVlz9F5gSNy+uTnuUiG9Y+DCDW4pZkc/HKbitq/0Te5p0TJvsEAXq7vh3S9zxHJ HehgrTrIeshFvWkdO3wyHC0GQkmVUFN0OevzXRSLaV/ZqAJGpfh66wGMa04AWEX0uYqBEVVx aFGEmBTcD+BtfOb5e6eVcA506zPLOGzVG8ekldJ6GiASNwAEdXESaiM4sJE1jAtgMwIBezZe 8cSdTtoalLHfgFLPVAUTpk5mY9EhFGmK2Ee9A3T+PpxujaCpOBy+OGF3N79YNuFSN8Thk+Fj mnH4374ElcRM9n3JT+toi/82rOfx32TtIQ6E7aq9KNXgH+v9jZKNg8SDVC+naeIlRvrMz5YA wlOksY0loAw/kG2Stj2XzWjvWWJ+BUbXrJ4F+w89RHIyafO5QudLnYLQyQHa9E8ssIyAzsw2 Tehj97vQDBirrCRYXac7auP6yO/PzAPKm0PbjNCShEKi/Hsuow8jRLnStdlDb67icDzFTjsw jeM6i8kiN07j88R1r6/9FrWqzGhvJ7ESkgy/Aq/dmCq9ARif6a+epelr1Pc6J5oJoGDT0LHu 2MYgc+A9+MfJZaXnSeJTaMGG7TBz/GBNzP0hV9/GJxn8Tmxk1amfIZf5xlzIFtkdMYZERfiY FXSohx5/5hOJz6xaqsxZJi+Y+wuzK79Bcz9XbXYY8RmZplqaBTB+zNqbESLmWf3nyAEirojM J2WdcKtC3cyCql9yjeyAeAH3tcWKjsWwGrSQdXxyUSh2L/HPXqNE+5bYR2Jc/wz676CrEPN6 dFDOsCWyhJZFurjfi3Q9o1VJlcPRZQmOa3LRwVsXrbrCmJb9KsJUpc9HZtJl1RZoplo
  • Ironport-hdrordr: A9a23:JXa0zK8mLkkVg0jRR8huk+D1I+orL9Y04lQ7vn2ZESYlC/Bw5P rEoB1773XJYVMqNU3I9urwXZVoLUmzyXcx2/h2AV7AZniahILLFvAH0WKK+VSJd0LDH6xmpM BdmsNFaOEYeGIK7/oSlzPIcOrIruPnzEniv5an854kd3AQV0hP1XYCNjqm
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Wed, Nov 30, 2022 at 10:34:41AM +0100, Jan Beulich wrote:
> On 30.11.2022 10:26, Roger Pau Monné wrote:
> > On Tue, Nov 29, 2022 at 02:12:10PM -0800, Stefano Stabellini wrote:
> >> On Tue, 29 Nov 2022, Roger Pau Monne wrote:
> >>> The hvc machinery registers both a console and a tty device based on
> >>> the hv ops provided by the specific implementation.  Those two
> >>> interfaces however have different locks, and there's no single locks
> >>> that's shared between the tty and the console implementations, hence
> >>> the driver needs to protect itself against concurrent accesses.
> >>> Otherwise concurrent calls using the split interfaces are likely to
> >>> corrupt the ring indexes, leaving the console unusable.
> >>>
> >>> Introduce a lock to xencons_info to serialize accesses to the shared
> >>> ring.  This is only required when using the shared memory console,
> >>> concurrent accesses to the hypercall based console implementation are
> >>> not an issue.
> >>>
> >>> Note the conditional logic in domU_read_console() is slightly modified
> >>> so the notify_daemon() call can be done outside of the locked region:
> >>> it's an hypercall and there's no need for it to be done with the lock
> >>> held.
> >>>
> >>> Fixes: b536b4b96230 ('xen: use the hvc console infrastructure for Xen 
> >>> console')
> >>> Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
> >>> ---
> >>> While the write handler (domU_write_console()) is used by both the
> >>> console and the tty ops, that's not the case for the read side
> >>> (domU_read_console()).  It's not obvious to me whether we could get
> >>> concurrent poll calls from the poll_get_char tty hook, hence stay on
> >>> the safe side also serialize read accesses in domU_read_console().
> >>
> >> I think domU_read_console doesn't need it. struct hv_ops and struct
> >> console are both already locked although independently locked.
> >>
> >> I think we shouldn't add an unrequired lock there.
> > 
> > Not all accesses are done using the tty lock.  There's a path using
> > tty_find_polling_driver() in kgdboc.c that directly calls into the
> > ->poll_get_char() hook without any locks apparently taken.
> 
> Simply by the name of the file I'm inclined to say that debugger code
> not respecting locks may be kind of intentional (but would then need
> to be accompanied by certain other precautions there).

I'm also confused because hvc_poll() which calls get_chars() does so
while holding an hvc lock, while hvc_poll_get_char() calls get_chars()
without holding any lock.  The call to get_chars() being done with a
lock held in hvc_poll() might just be a side-effect of the lock
being hold to keep consistency in the hvc_struct struct.

I also wonder whether new users of tty_find_polling_driver() and
->poll_get_char() could start appearing and assuming that the
underlying implementation would already take the necessary locks for
consistency.  Just looking at hvc_vio.c it does take a lock in
its get_chars() implementation to serialize accesses to the buffer.

Thanks, Roger.



 


Rackspace

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