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

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


  • To: Michael Ellerman <mpe@xxxxxxxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Fri, 10 Mar 2023 10:18: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=isv7pyswxh4k7JvnZXYR3aaQSe4UF5A2aKOxjW1mFpU=; b=FL2AH6LbdKxdL3CwOYra7m/8gu3s1kBtPj9AVz7GhYmgkP4exIJIg9YYx8WMdi/f1Ki5ZH4HU51xYN+yZG2oeVznBSlpzGpx+0wptNSIU35D9rmcqVx+HjR5GUfcpkE9YcwrY5cVv1TJvBr+1+HxJ33nqqL3oHB0+BMn6DdptnXxvj19/ZXWOP66S48Cdlr2ByFcIUAQYXFsr/VBnbtij7EUN2/VyJ7eFt1JqLZZz3ZmFAjMNl+mlTS4PMRGgPB6QBE/FS6BrOKm8Cbk6zeNsr4S2G9oV1JJak39TyMyS8GVvKp8cVxZnUf0OPPE+DLz0OPWIC6XQSGWVSValSzP1A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E3cAHFupXgiLqlR4UYUipZiXR/MKnEZKZzhc81DSpZ/iPNGZnyV7svywErGjgNQV9ENj/hvkwNBO7ElzDs66/65Oa45Yv+e6j94H+r6NcnZMKN8NzvUhvZsICUhZKzeHoRsBhURLU3FsQvG6FCi4PrQzkwofkoSQocpvz/w8nrM5CAU7zTxgxudh3Wti3ec5GTSSciAELvmE2IEJ3BGIlmpsZR8rZcQP4lSHZedYdH+LhMyIZW89ehrJUUXNzyc1dFlYNu1RC86nWwZF2deHAKginZC9D2WqeMowSzPpp61jx8lc7/yvDnxPLSMykpqtc5cN1p5gJkswVM4sQ7lJRw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>, Jiri Slaby <jirislaby@xxxxxxxxxx>, linux-kernel@xxxxxxxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx, linuxppc-dev@xxxxxxxxxxxxxxxx
  • Delivery-date: Fri, 10 Mar 2023 09:19:28 +0000
  • Ironport-data: A9a23:JtusRK/OavLdGZ3uCnMXDrUDNX+TJUtcMsCJ2f8bNWPcYEJGY0x3z GAWWGDVOKuIY2Sme4pwPdmwo0sE6J/QzddqTQJp/iA8E34SpcT7XtnIdU2Y0wF+jCHgZBk+s 5hBMImowOQcFCK0SsKFa+C5xZVE/fjUAOG6UKicYXoZqTZMEE8JkQhkl/MynrlmiN24BxLlk d7pqojUNUTNNwRcawr40Ire7kI/1BjOkGlA5AdmPqkT5Aa2e0Q9V/rzG4ngdxMUfaEMdgKKb 76r5K20+Grf4yAsBruN+losWhRXKlJ6FVHmZkt+A8BOsDAbzsAB+v9T2M4nQVVWk120c+VZk 72hg3ASpTABZcUgkMxFO/VR/roX0aduoNcrKlDn2SCfItGvn9IBDJyCAWlvVbD09NqbDklX0 uAmK2hXViuDguW27eOUcsZ8uecseZyD0IM34hmMzBn/JNN/GNXvZvuP4tVVmjAtmspJAPDSI dIDbiZiZwjBZBsJPUoLDJU5n6GjgXyXnz9w8QrJ4/ZopTWMilUvgNABM/KMEjCObd9SkUuC4 HrP4kzyAw0ANczZwj2Amp6prr6exHuhB9xDfFG+3uJOrWSOgWAvNCMTZVTig+Tnsm6ZROsKf iT4/QJr98De7neDS8HwdxC8pHOeuxcaHdtcVeQngCmW0bbd6QudAmkCTxZCZcYguctwQiYlv neLkMnuHidHq6CORDSW8bL8hTyoNCcWLUcGZCkZXQUC/t/vqZ0yiRSJScxseIa3j8f0AjX5y SGiryUkgbgXy8kR2M2T+VHBniLppZXTSAMxzhvYU3jj7Q5jYoOhIYuy5jDz/ftGaYqUUFSFl HwFgNSFqvADC4mXky6AS/lLG6umj96BMTvBkUZ3FNwt+iqF/3+4YZsW5yN6LU1ydMEedlfUj FT7vApQ4NpfOSWsZKouOoapUZ10ne7nCMjvUe3SYpxWeJ9teQSb/SZoI0mNw2Tql0tqmqY6U XuGTfuR4b8hIfwP5FKLqy01i+9DKvwWrY8Lea3G8g==
  • Ironport-hdrordr: A9a23:cJoaBKOm7wHldcBcTjGjsMiBIKoaSvp037By7TEIdfUnSL3iqy nOpoVl6faQskdlZJhOo6HnBEDtewK+yXcX2/huAV7BZniehILAFugLhuGOr1KPek3DH4VmpM Jdmt1FebrN5C9B/KLHCWeDYrQd6ejC34ztvOHaz318CSFGApsQn3YLe3Sm+wZNNXN77NICZe ehz9sCoyC/PXcaasn+AXUaRe3OusDGj/vdEG877jAcmXWzsQ8=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Fri, Mar 10, 2023 at 10:01:39AM +1100, Michael Ellerman wrote:
> Roger Pau Monné <roger.pau@xxxxxxxxxx> writes:
> > On Mon, Dec 12, 2022 at 01:36:48PM +0100, Roger Pau Monné wrote:
> >> On Fri, Dec 02, 2022 at 12:40:05PM +0100, Roger Pau Monné wrote:
> >> > On Wed, Nov 30, 2022 at 05:08:06PM -0800, Stefano Stabellini wrote:
> >> > > On Wed, 30 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.
> >> > >
> >> > > For domU_read_console: I don't mean to block this patch but we need to
> >> > > be sure about the semantics of hv_ops.get_chars. Either it is expected
> >> > > to be already locked, then we definitely shouldn't add another lock to
> >> > > domU_read_console. Or it is not expected to be already locked, then we
> >> > > should add the lock.
> >> > >
> >> > > My impression is that it is expected to be already locked, but I think
> >> > > we need Greg or Jiri to confirm one way or the other.
> >> >
> >> > Let me move both to the 'To:' field then.
> >> >
> >> > My main concern is the usage of hv_ops.get_chars hook in
> >> > hvc_poll_get_char(), as it's not obvious to me that callers of
> >> > tty->poll_get_char hook as returned by tty_find_polling_driver() will
> >> > always do so with the tty lock held (in fact the only user right now
> >> > doesn't seem to hold the tty lock).
> >> >
> >> > > Aside from that the rest looks fine.
> >
> > I guess I could reluctantly remove the lock in the get_chars hook,
> > albeit I'm not convinced at all the lock is not needed there.
> 
> I don't know the xen driver, but other HVC backends have a lock around
> their private state in their get_chars() implementations.
> 
> See eg. hvterm_raw_get_chars().

Yes, that was one of the motivation for adding the lock also here, and
it has already been mentioned.  The other is the usage of the hooks by
callers of hvc_poll_get_char().

Thanks, Roger.



 


Rackspace

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