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

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


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 30 Nov 2022 10:34:41 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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=P7OasLtRjEnTQ4HsfFqZktftoC39064067NPmSIxSYY=; b=F+efMSguwg6LtYDyeX0LPNpHwzbluiWaTYRJuaxrLpGDB1KRTpNJKBtyVTX89EcZBby+uG7E40FHmD2tbnO9rHWL3HUHMLmXCcCR0Z2LV7VJn5zPqsoS/TFJRNhbI9lEMKYc5ndeBkFADfc8Sa3IwXZpqB9iprNzVqTz2vhPyx3DxTKu+mYGFBZsXTB8TItYwEXKzUiEjJAwaXua58nMWovSRGRLvEdkrUZFXOobGCYZeT8vGh31PDEbVjX54+zXcLCC/JKG4TXFGWbxqVjS5TsRFIszgGh4CGkzBQkLnxMU7ZmV9lpw4dhyon4C9fxVy2ptVjaOb4UEQGziTRy9wg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QEBAIyzbkqJUNUb/Yh1urlHZcevN+g0usnzuRZ+YU1pKFoDfIR+uFGCsSblw9mmqhiZmTvlZd9jLFf/bSI8FiSfVwIp8MIvxpyF5qLwcfRWkRiN8Z1pxQNDMJtYL2FVCWLo+4xbsPkcxpLVL2JF5H28jFZALi8v+U6PYY6co7S7eiLyS78nwVM/rSpz7XKeuBXaz5+NxqTEYImVSJPIw7D+B0299uioDVqOufIABXmgvxqhqmudro0N+fui2jWKBjcSx6AWkFvUTatnWy/AZO/MRLCpATPJR1GLy7Relomzxd3D9RMKih2f7bjTD64PLZsVXe5VprRePfW9Fh+pddQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.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 09:35:00 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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).

Jan



 


Rackspace

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