Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5741817rwb; Mon, 14 Nov 2022 08:51:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf6NmXdpqQECC48IKmV2HofKyj2EFKiF/FDmowFI0o4+Pq2rPp3iIqF/V/d3BrB7i9MIE9Yf X-Received: by 2002:a65:4d0e:0:b0:439:3b80:615d with SMTP id i14-20020a654d0e000000b004393b80615dmr12777196pgt.255.1668444665081; Mon, 14 Nov 2022 08:51:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668444665; cv=none; d=google.com; s=arc-20160816; b=KI4veCTicXhVroWldF5dHZd4IfGtdTjwWz7EMGvGYyaSAGkIiXvSdpg/q/ZBx59c5g Vi1DqhtlhsFPkMj016zf5JYVIq9Dq5dyl3hCAlpZ7nDOnku/W3pk7JAsStIn1ml2eBew +ZArOR6HEGnZ5Zn0adId2mL8QWumKr5SIWGLEAyGESkLPP1vqVedsHlVUTSwpsXAVn2A udWW1P5O5kaNp6A6tXsLalqUxI5lUFuJ5B0o94uAWzsm/x46QAR49oNsVerA0PgX2xz6 tOUumhopodsuf1XmYK1GrrWq67jjoiiizj6B+gHlPZK8mlyumKIPDcAp/WSmZ1TwWL3O tOzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=K3LyUM+r5jVQkHAHN42aopONxFCaTcAPhOkdoz+gpJM=; b=g01scMTsZOr3F3F87/AaG46Nm7Yf2bPHQQpfCSsLswvJ1PWfkbwYknWuvhblCGXXOF cJVswH5t9eDmkhglYUTVl3bBeXgnU/AT36mbzi4SCD18QuEqefqlzpzvOSAffEqHmzMe gNzZJ1NSEHWgrUVxOPg8ilzT5ncnEfXCkthK/4Q5TwRrSbmCXAtVyXPyGJeXdbKNw4zm JTN9QELwwvVMWQHrxXQqjg3Ei6er31H1OT7dmw1kMGo/SEGxGNrWPXY/7v46ufTckNuN ueM51k+XPE2dV9gsuM7i1h+3aulTwC6+aPSPtHGI69xAm6IBq0sM6wV1+h5Y+eS8qq10 +RiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="yfcJXHl/"; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d9-20020a056a0024c900b0056beba0b31dsi10559422pfv.8.2022.11.14.08.50.53; Mon, 14 Nov 2022 08:51:05 -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=@linuxfoundation.org header.s=korg header.b="yfcJXHl/"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237433AbiKNQTD (ORCPT + 88 others); Mon, 14 Nov 2022 11:19:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237450AbiKNQSn (ORCPT ); Mon, 14 Nov 2022 11:18:43 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1579B38F for ; Mon, 14 Nov 2022 08:18:27 -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 A638F612A4 for ; Mon, 14 Nov 2022 16:18:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2C8FC433D7; Mon, 14 Nov 2022 16:18:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1668442706; bh=AqtzYtgXN3z9nM+kNUs9g6opjfSPy/5KmOAnNI1Je7U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=yfcJXHl/qAG6UhIPzAWlKql8R2YTxkgePNZkoB8I8NWZmiEKmqYfi1uhCPxoI3NYl OGfPj1Tt77iI7zUf1D+TyWRFtZTxZgCJ5j7bVUv5VTN4r1ohjSqJNhTOUPdo/T0Jnw jZyOiBNTNPUxkdpLI0LWXbaswhvoUyMnH6i4XFnU= Date: Mon, 14 Nov 2022 17:18:22 +0100 From: Greg Kroah-Hartman To: =?iso-8859-1?Q?C=E9dric?= Le Goater Cc: Amit Shah , Arnd Bergmann , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] virtio_console: Use an atomic to allocate virtual console numbers Message-ID: References: <20221114080752.1900699-1-clg@kaod.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 On Mon, Nov 14, 2022 at 05:03:40PM +0100, C?dric Le Goater wrote: > On 11/14/22 09:57, Greg Kroah-Hartman wrote: > > On Mon, Nov 14, 2022 at 09:07:52AM +0100, C?dric Le Goater wrote: > > > When a virtio console port is initialized, it is registered as an hvc > > > console using a virtual console number. If a KVM guest is started with > > > multiple virtio console devices, the same vtermno (or virtual console > > > number) can be used to allocate different hvc consoles, which leads to > > > various communication problems later on. > > > > > > This is also reported in debugfs : > > > > > > # grep vtermno /sys/kernel/debug/virtio-ports/* > > > /sys/kernel/debug/virtio-ports/vport1p1:console_vtermno: 1 > > > /sys/kernel/debug/virtio-ports/vport2p1:console_vtermno: 1 > > > /sys/kernel/debug/virtio-ports/vport3p1:console_vtermno: 2 > > > /sys/kernel/debug/virtio-ports/vport4p1:console_vtermno: 3 > > > > > > Fix the issue with an atomic variable and start the first console > > > number at 1 as it is today. > > > > > > Signed-off-by: C?dric Le Goater > > > --- > > > drivers/char/virtio_console.c | 8 ++++---- > > > 1 file changed, 4 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c > > > index 9fa3c76a267f..253574f41e57 100644 > > > --- a/drivers/char/virtio_console.c > > > +++ b/drivers/char/virtio_console.c > > > @@ -58,12 +58,13 @@ struct ports_driver_data { > > > * We also just assume the first console being initialised was > > > * the first one that got used as the initial console. > > > */ > > > - unsigned int next_vtermno; > > > + atomic_t next_vtermno; > > > /* All the console devices handled by this driver */ > > > struct list_head consoles; > > > }; > > > -static struct ports_driver_data pdrvdata = { .next_vtermno = 1}; > > > + > > > +static struct ports_driver_data pdrvdata = { .next_vtermno = ATOMIC_INIT(0) }; > > > static DEFINE_SPINLOCK(pdrvdata_lock); > > > static DECLARE_COMPLETION(early_console_added); > > > @@ -1244,7 +1245,7 @@ static int init_port_console(struct port *port) > > > * pointers. The final argument is the output buffer size: we > > > * can do any size, so we put PAGE_SIZE here. > > > */ > > > - port->cons.vtermno = pdrvdata.next_vtermno; > > > + port->cons.vtermno = atomic_inc_return(&pdrvdata.next_vtermno); > > > > Why not use a normal ida/idr structure here? > > yes that works. > > > And why is this never decremented? > > The driver would then need to track the id allocation ... That's what an ida/idr does. > > and finally, why not use the value that created the "vportN" number > > instead? > > yes. we could also encode the tuple (vdev->index, port) using a bitmask, No need for that, you already have a unique number in the name above, why not use that? > possibly using 'max_nr_ports' to reduce the port width. Why is that an issue? Maybe I am confused as to what this magic "vtermno" is here. Who uses it and why is the vportN number not sufficient? > VIRTCONS_MAX_PORTS > seems a bit big for this device and QEMU sets the #ports to 31. > > An ida might be simpler. One drawback is that an id can be reused for a > different device/port tuple in case of an (unlikely) unplug/plug sequence. What's wrong with that? We do not have persistent device names from within the kernel. thanks, greg k-h