From nobody Fri Oct 31 09:42:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=invisiblethingslab.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 17481828507841005.9220096848501; Sun, 25 May 2025 07:20:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.997155.1378149 (Exim 4.92) (envelope-from ) id 1uJCD6-0006R3-Ea; Sun, 25 May 2025 14:20:20 +0000 Received: by outflank-mailman (output) from mailman id 997155.1378149; Sun, 25 May 2025 14:20:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJCD6-0006Qj-9x; Sun, 25 May 2025 14:20:20 +0000 Received: by outflank-mailman (input) for mailman id 997155; Sun, 25 May 2025 14:20:19 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJCD5-0005ip-7H for xen-devel@lists.xenproject.org; Sun, 25 May 2025 14:20:19 +0000 Received: from fhigh-b6-smtp.messagingengine.com (fhigh-b6-smtp.messagingengine.com [202.12.124.157]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5dd335ca-3973-11f0-a2fb-13f23c93f187; Sun, 25 May 2025 16:20:11 +0200 (CEST) Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfhigh.stl.internal (Postfix) with ESMTP id 2CB1325400E4; Sun, 25 May 2025 10:20:10 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Sun, 25 May 2025 10:20:10 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 25 May 2025 10:20:07 -0400 (EDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5dd335ca-3973-11f0-a2fb-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1748182810; x=1748269210; bh=mWRLy4XWSq kSuh6T5T7Y3St8a2sE7Qw37t+DvXZ+raM=; b=Da3ocC0z9Oj3C3eZsJM8FFZPuo kE6bc1tOLyO/0duJYj1Id7jy5QyMJd9Z5gEL9iDx9aAfHt2a1Z77Pb5bIuXMgf1x hX49WmOgmIxVLiat9nAdwCjAZnnyWrk9C6KiV+qk6z9+Lq+9ejiB5OK3KCVvqCMD wG6SScj5crRiFKkz/HOx6SELcFxkLc6AKNSWO6YPyBRQTJwtj6bUuvyWjBmC8hH0 ZvST6VCHWOanhCqBdGwdCRvDvm9TcJPT9bBXlmZUrPYV6kPOh8w1w1fb4+ulEV4P f5G5UujJr2ELQ0E7PWWebuMXEdvMIjqCC9jX1P0HBkclvagvJDr4heIeWFUQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1748182810; x= 1748269210; bh=mWRLy4XWSqkSuh6T5T7Y3St8a2sE7Qw37t+DvXZ+raM=; b=m r1wNI8FH5Td8UIM+Lxd6D01f9iNgGooYb1lpw4FZ9rrQdiM7aqB8W0LqogNfPaaD n3ylZGqgHAICqKjIRr1fr+V4OPi6c8A4eUMH9hdm7zchfyWd8NyWdQZTnr5MaY3H V+zuqhW3da+qZnzaqqf/KTg55kX5qLQqjjbCZ29cLcO3pRQcZ1Z7ysWcSrwoP16c +L5JOFEDQRKaVbNC0KeLgsE5aZ3AI16UBkKPanBbGz+N4ue2g79khPgLy2j6lxfW 1IRvtAexWAyUilqw2x8Gm1HLQAuUfU0+Rr1rCfn2CaVwcsPSh1pQJWSyeZ4Pz6F1 cpTvSMkwBdCEoXBQRwzfg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgddugeekfeculddtuddrgeefvddrtd dtmdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggft fghnshhusghstghrihgsvgdpuffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftd dtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffo jghfgggtgfesthekredtredtjeenucfhrhhomhepofgrrhgvkhcuofgrrhgtiiihkhhofi hskhhiqdfikphrvggtkhhiuceomhgrrhhmrghrvghksehinhhvihhsihgslhgvthhhihhn ghhslhgrsgdrtghomheqnecuggftrfgrthhtvghrnhepgfeuudehgfdvfeehhedujeehfe duveeugefhkefhheelgeevudetueeiudfggfffnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomhepmhgrrhhmrghrvghksehinhhvihhsihgslhgvth hhihhnghhslhgrsgdrtghomhdpnhgspghrtghpthhtohepledpmhhouggvpehsmhhtphho uhhtpdhrtghpthhtohepgigvnhdquggvvhgvlheslhhishhtshdrgigvnhhprhhojhgvtg htrdhorhhgpdhrtghpthhtohepmhgrrhhmrghrvghksehinhhvihhsihgslhgvthhhihhn ghhslhgrsgdrtghomhdprhgtphhtthhopehjsggvuhhlihgthhesshhushgvrdgtohhmpd hrtghpthhtoheprghnughrvgifrdgtohhophgvrhefsegtihhtrhhigidrtghomhdprhgt phhtthhopehrohhgvghrrdhprghusegtihhtrhhigidrtghomhdprhgtphhtthhopegrnh hthhhonhihrdhpvghrrghrugesvhgrthgvshdrthgvtghhpdhrtghpthhtohepmhhitghh rghlrdhorhiivghlsegrmhgurdgtohhmpdhrtghpthhtohepjhhulhhivghnseigvghnrd horhhgpdhrtghpthhtohepshhsthgrsggvlhhlihhniheskhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i1568416f:Fastmail From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xenproject.org Cc: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Anthony PERARD , Michal Orzel , Julien Grall , Stefano Stabellini Subject: [PATCH v1 1/5] console: add relocation hook Date: Sun, 25 May 2025 16:15:42 +0200 Message-ID: <4f1889dc03ec4aa2cc0cd2bd14523a2c6f670bdb.1748182535.git-series.marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1748182851463116600 The XHCI console uses DMA, so it's sensitive for relocating its structures, even if their virtual addresses remain the same. Add a new console initialization hooks called before+after Xen relocation. Relocation happens conditionally, but call the hooks unconditionally, as that simplifies logic in the driver (and if needed, the driver can easily detect if relocation happened anyway). Thanks to that, a driver may use it to finalize init steps that need physical address but can be delayed - this way, it doesn't need un-doing on relocation. The most important part is the post-relocation hook, but add also pre-relocation one to simplify clean handling of in-flight data. Signed-off-by: Marek Marczykowski-G=C3=B3recki --- I considered more limited scope - calling them just around move_xen() (or even from within that function), but that complicates iommu_add_extra_reserved_device_memory() call - see the next patch. As for the post-relocation hook, I have considered a parameter with info whether the relocation actually happened, but driver can figure it out on its own anyway. --- xen/arch/x86/setup.c | 8 ++++++++ xen/drivers/char/console.c | 10 ++++++++++ xen/drivers/char/serial.c | 18 ++++++++++++++++++ xen/include/xen/console.h | 2 ++ xen/include/xen/serial.h | 6 ++++++ 5 files changed, 44 insertions(+) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 25189541244d..3ef819a252e4 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1481,6 +1481,8 @@ void asmlinkage __init noreturn __start_xen(void) highmem_start &=3D ~((1UL << L3_PAGETABLE_SHIFT) - 1); #endif =20 + console_init_pre_relocate(); + /* * Iterate backwards over all superpage-aligned RAM regions. * @@ -1606,6 +1608,12 @@ void asmlinkage __init noreturn __start_xen(void) if ( !xen_phys_start ) panic("Not enough memory to relocate Xen\n"); =20 + /* + * Notify console drivers about relocation, before reusing old Xen's + * memory. + */ + console_init_post_relocate(); + /* FIXME: Putting a hole in .bss would shatter the large page mapping.= */ if ( using_2M_mapping() ) efi_boot_mem_unused(NULL, NULL); diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index c15987f5bbe2..12898b684b5e 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -1120,6 +1120,16 @@ void __init console_init_ring(void) printk("Allocated console ring of %u KiB.\n", opt_conring_size >> 10); } =20 +void __init console_init_pre_relocate(void) +{ + serial_init_pre_relocate(); +} + +void __init console_init_post_relocate(void) +{ + serial_init_post_relocate(); +} + void __init console_init_irq(void) { serial_init_irq(); diff --git a/xen/drivers/char/serial.c b/xen/drivers/char/serial.c index 591a00900869..95f7410afa9c 100644 --- a/xen/drivers/char/serial.c +++ b/xen/drivers/char/serial.c @@ -447,6 +447,24 @@ void __init serial_init_preirq(void) com[i].driver->init_preirq(&com[i]); } =20 +void __init serial_init_pre_relocate(void) +{ + unsigned int i; + + for ( i =3D 0; i < ARRAY_SIZE(com); i++ ) + if ( com[i].driver && com[i].driver->init_pre_relocate ) + com[i].driver->init_pre_relocate(&com[i]); +} + +void __init serial_init_post_relocate(void) +{ + unsigned int i; + + for ( i =3D 0; i < ARRAY_SIZE(com); i++ ) + if ( com[i].driver && com[i].driver->init_post_relocate ) + com[i].driver->init_post_relocate(&com[i]); +} + void __init serial_init_irq(void) { unsigned int i; diff --git a/xen/include/xen/console.h b/xen/include/xen/console.h index 83cbc9fbdafc..d563777ad9e2 100644 --- a/xen/include/xen/console.h +++ b/xen/include/xen/console.h @@ -18,6 +18,8 @@ void console_init_preirq(void); void console_init_ring(void); void console_init_irq(void); void console_init_postirq(void); +void console_init_pre_relocate(void); +void console_init_post_relocate(void); void console_endboot(void); int console_has(const char *device); =20 diff --git a/xen/include/xen/serial.h b/xen/include/xen/serial.h index 63a82b032dde..1ee3df2624fb 100644 --- a/xen/include/xen/serial.h +++ b/xen/include/xen/serial.h @@ -64,6 +64,9 @@ struct uart_driver { void (*init_preirq)(struct serial_port *port); void (*init_irq)(struct serial_port *port); void (*init_postirq)(struct serial_port *port); + /* Hooks around optional Xen relocation. */ + void (*init_pre_relocate)(struct serial_port *port); + void (*init_post_relocate)(struct serial_port *port); /* Hook to clean up after Xen bootstrap (before domain 0 runs). */ void (*endboot)(struct serial_port *port); /* Driver suspend/resume. */ @@ -103,6 +106,9 @@ struct uart_driver { void serial_init_preirq(void); void serial_init_irq(void); void serial_init_postirq(void); +/* Notify drivers about Xen relocation (relevant for those using DMA). */ +void serial_init_pre_relocate(void); +void serial_init_post_relocate(void); =20 /* Clean-up hook before domain 0 runs. */ void serial_endboot(void); --=20 git-series 0.9.1 From nobody Fri Oct 31 09:42:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=invisiblethingslab.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1748182848129120.07224788947008; Sun, 25 May 2025 07:20:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.997153.1378129 (Exim 4.92) (envelope-from ) id 1uJCD2-0005wm-Qz; Sun, 25 May 2025 14:20:16 +0000 Received: by outflank-mailman (output) from mailman id 997153.1378129; Sun, 25 May 2025 14:20:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJCD2-0005wf-OE; Sun, 25 May 2025 14:20:16 +0000 Received: by outflank-mailman (input) for mailman id 997153; Sun, 25 May 2025 14:20:14 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJCD0-0005ip-Oc for xen-devel@lists.xenproject.org; Sun, 25 May 2025 14:20:14 +0000 Received: from fhigh-b6-smtp.messagingengine.com (fhigh-b6-smtp.messagingengine.com [202.12.124.157]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5f64952b-3973-11f0-a2fb-13f23c93f187; Sun, 25 May 2025 16:20:14 +0200 (CEST) Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id 9600A25400D1; Sun, 25 May 2025 10:20:12 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Sun, 25 May 2025 10:20:13 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 25 May 2025 10:20:10 -0400 (EDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5f64952b-3973-11f0-a2fb-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1748182812; x=1748269212; bh=8CMSnPMAp3 syd0lBA/8zYatGO1sF4jnrTcxo0LaBsrA=; b=b4lucCwqi3SvL0HUvsVIP8vjlH +EYrfwvSMGJXO9DviZVhTXkh01oJ4CFToSRW0pGVXk6CMvGZUjEf9J8v01EuKbib DRi4E41mQ95IAV9Bh2D7Lo2D9kClBnbPmRK0qAGDZ59URFFQVcB6qfvFp8CVQEud mVYYO0uCJpPPzaQR1W7TrkAEUjANU2NZ6KHGG/l/BQF+GOg+PkFxtDlDqtoUtbgp 5J3jMWYrYrkxrtuCjSqqG5hRRhhPvzHfruM/wUHZi7n08+Wf8+XM6pSrMqSVO4BE wp9Nlb1cOmG2kaVj51xyrwMB1glCrpsY067wPMGBw9PbFzXS9Qp/NR5neRSA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1748182812; x= 1748269212; bh=8CMSnPMAp3syd0lBA/8zYatGO1sF4jnrTcxo0LaBsrA=; b=C po66eGfPKySe+NvrvRO3Nv/TA4Dtu/A3MGL9EGl73luPSliCSU/CiRkveEJLBIqB 3O6B4y/VRDLxK4yvoZYD+PMlYoqyUHn6DQk//TnD6DCnWv8ZvoXIb9H9LdCIIaMj gJcrhPbQG874uuDc+CWi6LUmrd9SPEpuFuwogwL2KJVqqXfXVEslyUzr4uHwUacO r95B7rvVcE+pjhlD0v6rufnUrQXwUfzezPyK4vb11Oa7aHxJhRqdlLmjfxiDAPF0 te3zmUbU5nRV2dr9L/JQCLfvkD7TbMT+pU+tL9x6V5Mg5IJf5uhFEguOKDA85ptE n5sFmuR9cE+3t/4xViYkg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgddugeekfeculddtuddrgeefvddrtd dtmdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggft fghnshhusghstghrihgsvgdpuffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftd dtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffo jghfgggtgfesthekredtredtjeenucfhrhhomhepofgrrhgvkhcuofgrrhgtiiihkhhofi hskhhiqdfikphrvggtkhhiuceomhgrrhhmrghrvghksehinhhvihhsihgslhgvthhhihhn ghhslhgrsgdrtghomheqnecuggftrfgrthhtvghrnhepgfeuudehgfdvfeehhedujeehfe duveeugefhkefhheelgeevudetueeiudfggfffnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomhepmhgrrhhmrghrvghksehinhhvihhsihgslhgvth hhihhnghhslhgrsgdrtghomhdpnhgspghrtghpthhtohepledpmhhouggvpehsmhhtphho uhhtpdhrtghpthhtohepgigvnhdquggvvhgvlheslhhishhtshdrgigvnhhprhhojhgvtg htrdhorhhgpdhrtghpthhtohepmhgrrhhmrghrvghksehinhhvihhsihgslhgvthhhihhn ghhslhgrsgdrtghomhdprhgtphhtthhopegrnhgurhgvfidrtghoohhpvghrfeestghith hrihigrdgtohhmpdhrtghpthhtoheprghnthhhohhnhidrphgvrhgrrhgusehvrghtvghs rdhtvggthhdprhgtphhtthhopehmihgthhgrlhdrohhriigvlhesrghmugdrtghomhdprh gtphhtthhopehjsggvuhhlihgthhesshhushgvrdgtohhmpdhrtghpthhtohepjhhulhhi vghnseigvghnrdhorhhgpdhrtghpthhtoheprhhoghgvrhdrphgruhestghithhrihigrd gtohhmpdhrtghpthhtohepshhsthgrsggvlhhlihhniheskhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i1568416f:Fastmail From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xenproject.org Cc: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 2/5] drivers/char: Handle Xen relocation in the XHCI console driver Date: Sun, 25 May 2025 16:15:43 +0200 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1748182849569116600 The XHCI uses DMA for a bunch of configuration structures and also for transfer rings. Since those buffers live in .bss it's sensitive for Xen relocation. Use the newly added hooks to handle this case: In pre-relocation hook wait for all the data already sent to be handled and pause sending any more. In the post-relocation hook detect if relocation happened (check if physical address of one of the structures matches what was programmed into hardware) and if so - re-initialize all structures carying physical addresses and program XHCI with new addresses. And then resume console - this needs to happen in no-relocation case too, to undo pausing done in pre-relocation. Move the iommu_add_extra_reserved_device_memory() call post relocation, as it needs physical addresses. It needs to happen before setting up IOMMU (specifically before the acpi_iommu_init() call) but that's the only ordering constraint - moving it is simpler than doing it initially with pre-relocation addresses and then un-doing during relocation. This is also the place where calling post-relocation hook unconditionally (even if relocation didn't actually happened) is helpful - otherwise the iommu_add_extra_reserved_device_memory() call would need to be done conditionally in two places. Finally, move dbc_dma_bufs declaration near top of the file, as it's used earlier now. Unfortunately, changes to several registers require flipping DCE (Debug Capability Enable) to 0 and then back to 1 which results in the device disconnect for a short time. Linux's xhci_dbc driver appears to do some synchronization (or buffering?) so if one re-connects to the /dev/USB0 fast enough (for example by running minicom/picocom/etc in a loop), no messages are lost. But technically there is no guarantee of that... Signed-off-by: Marek Marczykowski-G=C3=B3recki --- I tried to avoid flipping DCE, but it seems to be a limitation actually enforced by the hardware. The XHCI spec says "just" this about a bunch of registers: Software shall initialize this register before setting the Debug Capability Enable bit in the Debug Capability Control Register to =E2= =80=981=E2=80=99. As for the implicit console flush in pre-relocation hook, technically it could be avoided in the no-relocation case, but that would complicate code structure (see note about reserved device memory). For the relocation case, avoiding it might be possible, if the driver could access old pages somehow (as without the flush the device might have modified them in the meantime), but again - IMO it's not worth it. Alternative would be flipping DCE also in the no-relocation case, which is IMO worse than just the flush. --- xen/drivers/char/xhci-dbc.c | 89 +++++++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 25 deletions(-) diff --git a/xen/drivers/char/xhci-dbc.c b/xen/drivers/char/xhci-dbc.c index c45e4b6825cc..c4bb371ff78f 100644 --- a/xen/drivers/char/xhci-dbc.c +++ b/xen/drivers/char/xhci-dbc.c @@ -264,6 +264,24 @@ struct dbc { uint16_t pci_cr; }; =20 +/* Those are accessed via DMA. */ +struct dbc_dma_bufs { + struct xhci_trb evt_trb[DBC_TRB_RING_CAP]; + struct xhci_trb out_trb[DBC_TRB_RING_CAP]; + struct xhci_trb in_trb[DBC_TRB_RING_CAP]; + uint8_t out_wrk_buf[DBC_WORK_RING_CAP]; + uint8_t in_wrk_buf[DBC_WORK_RING_CAP]; + struct xhci_erst_segment erst __aligned(16); + struct xhci_dbc_ctx ctx __aligned(16); + struct xhci_string_descriptor str_buf[DBC_STRINGS_COUNT]; + /* + * Don't place anything else on this page - it will be + * DMA-reachable by the USB controller. + */ +}; +static struct dbc_dma_bufs __section(".bss.page_aligned") __aligned(PAGE_S= IZE) + dbc_dma_bufs; + static void *dbc_sys_map_xhc(uint64_t phys, size_t size) { size_t i; @@ -1189,6 +1207,50 @@ static void __init cf_check dbc_uart_init_preirq(str= uct serial_port *port) uart->lock =3D &port->tx_lock; } =20 +static void __init cf_check dbc_uart_init_pre_relocate(struct serial_port = *port) +{ + struct dbc_uart *uart =3D port->uart; + struct dbc *dbc =3D &uart->dbc; + + /* Wait for all the data already sent to be handled. */ + while ( xhci_trb_ring_size(&dbc->dbc_oring) ) + dbc_pop_events(dbc); + /* Do not send any more data until after relocation. */ + dbc->suspended =3D true; +} + +static void __init cf_check dbc_uart_init_post_relocate(struct serial_port= *port) +{ + struct dbc_uart *uart =3D port->uart; + struct dbc *dbc =3D &uart->dbc; + + if ( readq(&dbc->dbc_reg->erstba) !=3D virt_to_maddr(dbc->dbc_erst) ) + { + /* + * Do not use dbc_init_work_ring() to not discard queued data, just + * update the DMA address. + */ + dbc->dbc_owork.dma =3D virt_to_maddr(dbc->dbc_owork.buf); + dbc->dbc_iwork.dma =3D virt_to_maddr(dbc->dbc_iwork.buf); + + if ( !dbc_init_dbc(dbc) ) + { + dbc_error("relocate failed\n"); + return; + } + + dbc_enable_dbc(dbc); + } + + dbc->suspended =3D false; + + iommu_add_extra_reserved_device_memory( + PFN_DOWN(virt_to_maddr(&dbc_dma_bufs)), + PFN_UP(sizeof(dbc_dma_bufs)), + uart->dbc.sbdf, + "XHCI console"); +} + static void __init cf_check dbc_uart_init_postirq(struct serial_port *port) { struct dbc_uart *uart =3D port->uart; @@ -1310,6 +1372,8 @@ static void cf_check dbc_uart_resume(struct serial_po= rt *port) static struct uart_driver dbc_uart_driver =3D { .init_preirq =3D dbc_uart_init_preirq, .init_postirq =3D dbc_uart_init_postirq, + .init_pre_relocate =3D dbc_uart_init_pre_relocate, + .init_post_relocate =3D dbc_uart_init_post_relocate, .tx_ready =3D dbc_uart_tx_ready, .putc =3D dbc_uart_putc, .getc =3D dbc_uart_getc, @@ -1318,24 +1382,6 @@ static struct uart_driver dbc_uart_driver =3D { .resume =3D dbc_uart_resume, }; =20 -/* Those are accessed via DMA. */ -struct dbc_dma_bufs { - struct xhci_trb evt_trb[DBC_TRB_RING_CAP]; - struct xhci_trb out_trb[DBC_TRB_RING_CAP]; - struct xhci_trb in_trb[DBC_TRB_RING_CAP]; - uint8_t out_wrk_buf[DBC_WORK_RING_CAP]; - uint8_t in_wrk_buf[DBC_WORK_RING_CAP]; - struct xhci_erst_segment erst __aligned(16); - struct xhci_dbc_ctx ctx __aligned(16); - struct xhci_string_descriptor str_buf[DBC_STRINGS_COUNT]; - /* - * Don't place anything else on this page - it will be - * DMA-reachable by the USB controller. - */ -}; -static struct dbc_dma_bufs __section(".bss.page_aligned") __aligned(PAGE_S= IZE) - dbc_dma_bufs; - static int __init cf_check xhci_parse_dbgp(const char *opt_dbgp) { struct dbc_uart *uart =3D &dbc_uart; @@ -1425,14 +1471,7 @@ void __init xhci_dbc_uart_init(void) dbc->dbc_str =3D dbc_dma_bufs.str_buf; =20 if ( dbc_open(dbc) ) - { - iommu_add_extra_reserved_device_memory( - PFN_DOWN(virt_to_maddr(&dbc_dma_bufs)), - PFN_UP(sizeof(dbc_dma_bufs)), - uart->dbc.sbdf, - "XHCI console"); serial_register_uart(SERHND_XHCI, &dbc_uart_driver, &dbc_uart); - } } =20 #ifdef DBC_DEBUG --=20 git-series 0.9.1 From nobody Fri Oct 31 09:42:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=invisiblethingslab.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1748182836674247.28810343554153; Sun, 25 May 2025 07:20:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.997154.1378140 (Exim 4.92) (envelope-from ) id 1uJCD5-0006BW-2Y; Sun, 25 May 2025 14:20:19 +0000 Received: by outflank-mailman (output) from mailman id 997154.1378140; Sun, 25 May 2025 14:20:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJCD4-0006BL-Vq; Sun, 25 May 2025 14:20:18 +0000 Received: by outflank-mailman (input) for mailman id 997154; Sun, 25 May 2025 14:20:18 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJCD4-0006Ah-Dd for xen-devel@lists.xenproject.org; Sun, 25 May 2025 14:20:18 +0000 Received: from fhigh-b6-smtp.messagingengine.com (fhigh-b6-smtp.messagingengine.com [202.12.124.157]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 60c7751d-3973-11f0-b893-0df219b8e170; Sun, 25 May 2025 16:20:16 +0200 (CEST) Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.stl.internal (Postfix) with ESMTP id 2D70C25400CC; Sun, 25 May 2025 10:20:15 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Sun, 25 May 2025 10:20:15 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 25 May 2025 10:20:13 -0400 (EDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 60c7751d-3973-11f0-b893-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1748182815; x=1748269215; bh=nvcA2fXb3e hl89J7/qQltbJE5fahzJ7yWRoiR9gW1UA=; b=N7xmPgvQPZcNs9lOryH9mVo0H2 C/IMDast8elvfpA7z4GK4FC9KtXik2CKq5cQgep7UrNSlve3fom8gGMCsKtTxTXd wKmjdjcW8VQ3104kRF9ldRH63pXNilT4SKDcvj5NuWKVnvtJIEPJiIxpiL6oOuJR oSW/xipriiITpzsF/N0GWi7rnC/EwokrVItsP/gkVlAe4zBt9LS3709/iGmRyram YTsgO6cKMx3D6obygIQa5p3gBcFftAI5jwyVZ3fl9HohxQyAFD0oK8Qu1iFqvbDm BN/wCG/aO2NRCzQdckuB8O3OS9qKwQqQ4ZChLqH1ps2TJg1Z0kQq7DlK1AcQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1748182815; x= 1748269215; bh=nvcA2fXb3ehl89J7/qQltbJE5fahzJ7yWRoiR9gW1UA=; b=X XtrMxeAK/jPJSKa3qy4t50Q+dIe/AwjbOrOR4Fz7gr1zS+NFoIMoLghJrTW1Loyq p38mTYO4/WVQeDjAZ/+iPC5lnXNV39p1OgMVUhOka/Dh4hZ+poign3YXWDGgcJz/ kl3Nw7cizV05yon97NW4At+j6LfknwoM0V46iJzlfZeAZNAr0KpPakM18AA+psYw rhhdZTZkffBbfIp+sKfehKMFC6bX8uQ+piF4ZlFwzIVBX5qrTMq3eaPWhlMPXBwc 3NK50R6ZazKciR9ocVifr9GdREpp9Kvtk/lmpnx3Ledg2JoePqxUX7wQg3RnvUZj VVCyELCWkb3IIRWEEbzVg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgddugeekfeculddtuddrgeefvddrtd dtmdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggft fghnshhusghstghrihgsvgdpuffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftd dtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffo jghfgggtgfesthekredtredtjeenucfhrhhomhepofgrrhgvkhcuofgrrhgtiiihkhhofi hskhhiqdfikphrvggtkhhiuceomhgrrhhmrghrvghksehinhhvihhsihgslhgvthhhihhn ghhslhgrsgdrtghomheqnecuggftrfgrthhtvghrnhepgfeuudehgfdvfeehhedujeehfe duveeugefhkefhheelgeevudetueeiudfggfffnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomhepmhgrrhhmrghrvghksehinhhvihhsihgslhgvth hhihhnghhslhgrsgdrtghomhdpnhgspghrtghpthhtohepledpmhhouggvpehsmhhtphho uhhtpdhrtghpthhtohepgigvnhdquggvvhgvlheslhhishhtshdrgigvnhhprhhojhgvtg htrdhorhhgpdhrtghpthhtohepmhgrrhhmrghrvghksehinhhvihhsihgslhgvthhhihhn ghhslhgrsgdrtghomhdprhgtphhtthhopegrnhgurhgvfidrtghoohhpvghrfeestghith hrihigrdgtohhmpdhrtghpthhtoheprghnthhhohhnhidrphgvrhgrrhgusehvrghtvghs rdhtvggthhdprhgtphhtthhopehmihgthhgrlhdrohhriigvlhesrghmugdrtghomhdprh gtphhtthhopehjsggvuhhlihgthhesshhushgvrdgtohhmpdhrtghpthhtohepjhhulhhi vghnseigvghnrdhorhhgpdhrtghpthhtoheprhhoghgvrhdrphgruhestghithhrihigrd gtohhmpdhrtghpthhtohepshhsthgrsggvlhhlihhniheskhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i1568416f:Fastmail From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xenproject.org Cc: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 3/5] drivers/char: make dbc_uart_dump() a bit more useful Date: Sun, 25 May 2025 16:15:44 +0200 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1748182837305116600 Make it safe to call also if xhci console is not enabled. And make it non-static, to require one less modification when actually using it. When using it, one still needs to add its declaration in some header (or just next to the call site). Signed-off-by: Marek Marczykowski-G=C3=B3recki --- IIUC Misra would not be happy about a declaration of an usused function. And I'd rather avoid extending DBC_DEBUG scope beyond that single file. --- xen/drivers/char/xhci-dbc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xen/drivers/char/xhci-dbc.c b/xen/drivers/char/xhci-dbc.c index c4bb371ff78f..ced28cae0a29 100644 --- a/xen/drivers/char/xhci-dbc.c +++ b/xen/drivers/char/xhci-dbc.c @@ -1498,11 +1498,14 @@ static void dbc_dump(struct dbc *dbc) readq(&r->cp) =3D=3D virt_to_maddr(dbc->dbc_ctx)); } =20 -static void dbc_uart_dump(void) +void dbc_uart_dump(void) { struct dbc_uart *uart =3D &dbc_uart; struct dbc *dbc =3D &uart->dbc; =20 + if ( !dbc->enable ) + return; + dbc_dump(dbc); } #endif --=20 git-series 0.9.1 From nobody Fri Oct 31 09:42:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=invisiblethingslab.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 174818284131876.54652191328091; Sun, 25 May 2025 07:20:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.997156.1378160 (Exim 4.92) (envelope-from ) id 1uJCD7-0006gA-Lx; Sun, 25 May 2025 14:20:21 +0000 Received: by outflank-mailman (output) from mailman id 997156.1378160; Sun, 25 May 2025 14:20:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJCD7-0006fr-I2; Sun, 25 May 2025 14:20:21 +0000 Received: by outflank-mailman (input) for mailman id 997156; Sun, 25 May 2025 14:20:20 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJCD6-0005ip-7J for xen-devel@lists.xenproject.org; Sun, 25 May 2025 14:20:20 +0000 Received: from fout-b8-smtp.messagingengine.com (fout-b8-smtp.messagingengine.com [202.12.124.151]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6231fc7c-3973-11f0-a2fb-13f23c93f187; Sun, 25 May 2025 16:20:19 +0200 (CEST) Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.stl.internal (Postfix) with ESMTP id 863F611400ED; Sun, 25 May 2025 10:20:17 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Sun, 25 May 2025 10:20:17 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 25 May 2025 10:20:15 -0400 (EDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6231fc7c-3973-11f0-a2fb-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1748182817; x=1748269217; bh=mL74JBhQ+2 8XfBxZeuQdBPRzlrPHx/K6JFX3Qfsm+Mw=; b=mZuX5yyLOH1As6zDQ0bvZXIkZr x8RcEnx3vLGN05OtAp+wE0D7ZyCoyFVq95tvks9N7C5fOhBI78ZGcJZXyXVw9Zag n/dZLeoMtd+5syfcHE1M5edt4/QrQErQlWom0S2YqyxLADzqwzSPaVBRQsqQ1TtS iDaIplHtE1EBQ/nwu38Dn3zIyghjJZQCTtvUik4PqQFqNfuxyzZcb/SpctY21MEM BS5dxzslSHmlPY2nXanrQbkgW9IkJcNOxj1MbL4zLHuomRZmxu+TFiJTO7CydwN1 s69MBrID0YrKqh5rn/xiK1aLOlTipE/DYX52JubYcAcrkO46OMV+IueDPW9w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1748182817; x= 1748269217; bh=mL74JBhQ+28XfBxZeuQdBPRzlrPHx/K6JFX3Qfsm+Mw=; b=n GKnhgb+GwXDV0n1D9jjRkF3m6YHQIMUbFmAeD14kCSxjme86uJrdCRblS07Bpr76 OOGXiyZoJaXbW3YFOZ/4V0gcL983+QWpokrklGNShWSKEzkEFS1Owiz2lGOJUy/F vqkoayyuHznvd3+HecxsgkiO3NmAWW5Mit9hHH6nHp1b6IumGcDL6eKSJn05uFv0 W2/7qtx+QJ9P6MsWqjqtf16bC39ztVmkX6VXkiY7bH0fxjVzveCc9/y01n0Y1vIE egLxDPNpqzOto/eiQAkVeaeAlk2bXwMTAaPVO1h9525iUkUW6BRsMkwACeQD6tkr aBCL6VbAAIvbpbVeLKRUw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgddugeekfeculddtuddrgeefvddrtd dtmdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggft fghnshhusghstghrihgsvgdpuffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftd dtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffo jghfgggtgfesthekredtredtjeenucfhrhhomhepofgrrhgvkhcuofgrrhgtiiihkhhofi hskhhiqdfikphrvggtkhhiuceomhgrrhhmrghrvghksehinhhvihhsihgslhgvthhhihhn ghhslhgrsgdrtghomheqnecuggftrfgrthhtvghrnhepgfeuudehgfdvfeehhedujeehfe duveeugefhkefhheelgeevudetueeiudfggfffnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomhepmhgrrhhmrghrvghksehinhhvihhsihgslhgvth hhihhnghhslhgrsgdrtghomhdpnhgspghrtghpthhtohepledpmhhouggvpehsmhhtphho uhhtpdhrtghpthhtohepgigvnhdquggvvhgvlheslhhishhtshdrgigvnhhprhhojhgvtg htrdhorhhgpdhrtghpthhtohepmhgrrhhmrghrvghksehinhhvihhsihgslhgvthhhihhn ghhslhgrsgdrtghomhdprhgtphhtthhopegrnhgurhgvfidrtghoohhpvghrfeestghith hrihigrdgtohhmpdhrtghpthhtoheprghnthhhohhnhidrphgvrhgrrhgusehvrghtvghs rdhtvggthhdprhgtphhtthhopehmihgthhgrlhdrohhriigvlhesrghmugdrtghomhdprh gtphhtthhopehjsggvuhhlihgthhesshhushgvrdgtohhmpdhrtghpthhtohepjhhulhhi vghnseigvghnrdhorhhgpdhrtghpthhtoheprhhoghgvrhdrphgruhestghithhrihigrd gtohhmpdhrtghpthhtohepshhsthgrsggvlhhlihhniheskhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i1568416f:Fastmail From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xenproject.org Cc: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 4/5] drivers/char: remove outdated comment in xhci driver Date: Sun, 25 May 2025 16:15:45 +0200 Message-ID: <6abaf3a05c8ea7204bea2046a799bc577e0b77e8.1748182535.git-series.marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1748182843550116600 The input handling is already implemented, and that limitation is not there anymore. Signed-off-by: Marek Marczykowski-G=C3=B3recki Acked-by: Jan Beulich --- xen/drivers/char/xhci-dbc.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/xen/drivers/char/xhci-dbc.c b/xen/drivers/char/xhci-dbc.c index ced28cae0a29..3692776cec11 100644 --- a/xen/drivers/char/xhci-dbc.c +++ b/xen/drivers/char/xhci-dbc.c @@ -672,10 +672,6 @@ static void dbc_rx_trb(struct dbc *dbc, struct xhci_tr= b *trb, cache_flush(&ring->buf[start], end - start); } =20 -/* - * Note that if IN transfer support is added, then this - * will need to be changed; it assumes an OUT transfer ring only - */ static void dbc_pop_events(struct dbc *dbc) { struct dbc_reg *reg =3D dbc->dbc_reg; --=20 git-series 0.9.1 From nobody Fri Oct 31 09:42:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=invisiblethingslab.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1748182852217491.64772725285025; Sun, 25 May 2025 07:20:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.997158.1378170 (Exim 4.92) (envelope-from ) id 1uJCDC-00072W-Vq; Sun, 25 May 2025 14:20:26 +0000 Received: by outflank-mailman (output) from mailman id 997158.1378170; Sun, 25 May 2025 14:20:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJCDC-00072F-SO; Sun, 25 May 2025 14:20:26 +0000 Received: by outflank-mailman (input) for mailman id 997158; Sun, 25 May 2025 14:20:24 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJCDA-0006Ah-Os for xen-devel@lists.xenproject.org; Sun, 25 May 2025 14:20:24 +0000 Received: from fhigh-b6-smtp.messagingengine.com (fhigh-b6-smtp.messagingengine.com [202.12.124.157]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 638175e0-3973-11f0-b893-0df219b8e170; Sun, 25 May 2025 16:20:20 +0200 (CEST) Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfhigh.stl.internal (Postfix) with ESMTP id B9CF425400CA; Sun, 25 May 2025 10:20:19 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Sun, 25 May 2025 10:20:19 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 25 May 2025 10:20:17 -0400 (EDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 638175e0-3973-11f0-b893-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1748182819; x=1748269219; bh=8N0UZzKt4D QbodDXdvRtwVlKHw5NKvan8QfhJwtoCk8=; b=BhL1n/QeRiZ5LIM3pw/lE4MNPI jnNyVsgCW6EOTbt2MYUlrmmicZ0DHbaaY66u0Tn3MULNqBXJQ7ZdxerNg4aoFKto 7AVB++4Ow+EemU1aLbdkOXf90Zm9A2ONnf2HrrtKe/wwNPr5ruBFtbpTzMVG9xBW AL2GLp319pmzi+eqYbDN6kXnMYYDoSSp31gtGfdJCvoH3UA+sVArHJuDBm7Cnffg 1NKQHXOUPdgv0xI1EjoTslHWNuyKr6lXNlkNd7HNgHVlJ+GE3ps3FkdsVOEAap0A VQQLRT6ZyLJbUgOTfZOhZbP7IjZvcoVnBVQnS062uUHVl46niQ2qL7r71wgQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1748182819; x= 1748269219; bh=8N0UZzKt4DQbodDXdvRtwVlKHw5NKvan8QfhJwtoCk8=; b=U J6bOiBqrsmflyAGrQZRClJtBba3espjZkLKDVsCaIB8dyAhfwDIAyqZVTidk47dV XwHNuU3Ych4r/eXVYN9e7Z+/GyPgAeh/HvIHIiNTrwvli+uIu/YfWEqpA8S3FWXa W1JjiawMc6IJj6NxOWbaRn6mh91IqZCrCgHcjK/tC4pObbxyjKRwhIsqUSJakS/q M+lklnhY6RTixkKJ1ddubGMVO67JYgGPFCBEbBQI66I5RghW6JL9oC2bW/c/KQ+J yGr1g47hL2hLsbCyWjVu6J949DJER4yrQavgKkYL9p5Z2IDn3Up0270ej9Nr7FWU 0Uovp1mdjiPYRHICDMQiQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgddugeekfeculddtuddrgeefvddrtd dtmdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggft fghnshhusghstghrihgsvgdpuffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftd dtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffo jghfgggtgfesthekredtredtjeenucfhrhhomhepofgrrhgvkhcuofgrrhgtiiihkhhofi hskhhiqdfikphrvggtkhhiuceomhgrrhhmrghrvghksehinhhvihhsihgslhgvthhhihhn ghhslhgrsgdrtghomheqnecuggftrfgrthhtvghrnhepffeitdegveffteelvdeghffhve fghfefkeelheeujeejgedvvdfgffejuedtvdelnecuffhomhgrihhnpehkvghrnhgvlhdr ohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hmrghrmhgrrhgvkhesihhnvhhishhisghlvghthhhinhhgshhlrggsrdgtohhmpdhnsggp rhgtphhtthhopeelpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopeigvghnqdguvg hvvghlsehlihhsthhsrdigvghnphhrohhjvggtthdrohhrghdprhgtphhtthhopehmrghr mhgrrhgvkhesihhnvhhishhisghlvghthhhinhhgshhlrggsrdgtohhmpdhrtghpthhtoh eprghnughrvgifrdgtohhophgvrhefsegtihhtrhhigidrtghomhdprhgtphhtthhopegr nhhthhhonhihrdhpvghrrghrugesvhgrthgvshdrthgvtghhpdhrtghpthhtohepmhhitg hhrghlrdhorhiivghlsegrmhgurdgtohhmpdhrtghpthhtohepjhgsvghulhhitghhsehs uhhsvgdrtghomhdprhgtphhtthhopehjuhhlihgvnhesgigvnhdrohhrghdprhgtphhtth hopehrohhgvghrrdhprghusegtihhtrhhigidrtghomhdprhgtphhtthhopehsshhtrggs vghllhhinhhisehkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i1568416f:Fastmail From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xenproject.org Cc: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 5/5] console: support multiple serial console simultaneously Date: Sun, 25 May 2025 16:15:46 +0200 Message-ID: <98ff383ff2ee3dc162b2d12afaea2b3f1406d99e.1748182535.git-series.marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1748182853671116600 Previously only one serial console was supported at the same time. Using console=3Dcom1,dbgp,vga silently ignored all but last serial console (in this case: only dbgp and vga were active). Fix this by storing not a single sercon_handle, but an array of them, up to MAX_SERCONS entries. The value of MAX_SERCONS can be chosen in kconfig, the default (4) is arbitrary, inspired by the number of SERHND_IDX values. Make console_steal() aware of multiple consoles too. It can now either steal output from specific console (for gdbstub), or from all of them at once (for console suspend). Signed-off-by: Marek Marczykowski-G=C3=B3recki --- This was posted before as part of initial xhci console submission, it reached v6 (but last changes were in v4), but wasn't considered useful enough to review/ack: https://lore.kernel.org/xen-devel/Yu0XHUhsebE+WG0g@mail-itl/ Since I needed this feature again, to debug xhci console issue, I'm including this patch again in the series. Changes in v4: - use unsigned int for loop counters - other minor changes Changes in v3: - adjust console_steal() for multiple consoles too - add MAX_SERCONS to kconfig - add warning about sync_console impact - add warning if too many consoles are configured - log issue with PCI spec parsing --- docs/misc/xen-command-line.pandoc | 4 +- xen/drivers/char/Kconfig | 11 ++++- xen/drivers/char/console.c | 98 ++++++++++++++++++++++++-------- xen/include/xen/serial.h | 1 +- 4 files changed, 92 insertions(+), 22 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index b0eadd2c5d58..052c01f87bfc 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -456,6 +456,9 @@ only available when used together with `pv-in-pvh`. `none` indicates that Xen should not use a console. This option only makes sense on its own. =20 +Specifying more than one serial console will increase console latency, +especially when `sync_console` option is used. + ### console_timestamps > `=3D none | date | datems | boot | raw` =20 @@ -2637,6 +2640,7 @@ Intel SA-00982. Intel suggest that some workloads wi= ll benefit from this. =20 Flag to force synchronous console output. Useful for debugging, but not suitable for production environments due to incurred overhead. +If multiple consoles are configured, the incurred overhead is even bigger. =20 ### tboot (x86) > `=3D 0x` diff --git a/xen/drivers/char/Kconfig b/xen/drivers/char/Kconfig index e6e12bb41397..76305fcb4afa 100644 --- a/xen/drivers/char/Kconfig +++ b/xen/drivers/char/Kconfig @@ -96,6 +96,17 @@ config SERIAL_TX_BUFSIZE =20 Default value is 32768 (32KiB). =20 +config MAX_SERCONS + int "Maximum number of serial consoles active at once" + default 4 + help + Controls how many serial consoles can be active at once. Configuring mo= re + using `console=3D` parameter will be ignored. + When multiple consoles are configured, overhead of `sync_console` option + is even bigger. + + Default value is 4. + config XHCI bool "XHCI DbC UART driver" depends on X86 diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 12898b684b5e..e306986bfcbc 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -134,7 +134,9 @@ static char *__read_mostly conring =3D _conring; static uint32_t __read_mostly conring_size =3D _CONRING_SIZE; static uint32_t conringc, conringp; =20 -static int __read_mostly sercon_handle =3D -1; +#define MAX_SERCONS CONFIG_MAX_SERCONS +static int __read_mostly sercon_handle[MAX_SERCONS]; +static unsigned int __read_mostly nr_sercon_handle =3D 0; =20 #ifdef CONFIG_X86 /* Tristate: 0 disabled, 1 user enabled, -1 default enabled */ @@ -424,32 +426,61 @@ long read_console_ring(struct xen_sysctl_readconsole = *op) static char serial_rx_ring[SERIAL_RX_SIZE]; static unsigned int serial_rx_cons, serial_rx_prod; =20 -static void (*serial_steal_fn)(const char *str, size_t nr) =3D early_puts; +/* The last entry means "steal from all consoles" */ +static void (*serial_steal_fn[])(const char *str, size_t nr) =3D { + [MAX_SERCONS] =3D early_puts, +}; =20 +/* + * Redirect console *handle* output to *fn*. Use SERHND_STEAL_ALL as *hand= le* to + * redirect all the consoles.=20 + */ int console_steal(int handle, void (*fn)(const char *str, size_t nr)) { - if ( (handle =3D=3D -1) || (handle !=3D sercon_handle) ) - return 0; + unsigned int i; + + if ( handle =3D=3D -1 ) + return -ENOENT; + if ( serial_steal_fn[MAX_SERCONS] !=3D NULL ) + return -EBUSY; + if ( handle =3D=3D SERHND_STEAL_ALL ) + { + serial_steal_fn[MAX_SERCONS] =3D fn; + return MAX_SERCONS; + } + for ( i =3D 0; i < nr_sercon_handle; i++ ) + if ( handle =3D=3D sercon_handle[i] ) + break; + if ( i =3D=3D nr_sercon_handle ) + return -ENOENT; =20 - if ( serial_steal_fn !=3D NULL ) + if ( serial_steal_fn[i] !=3D NULL ) return -EBUSY; =20 - serial_steal_fn =3D fn; - return 1; + serial_steal_fn[i] =3D fn; + return i; } =20 void console_giveback(int id) { - if ( id =3D=3D 1 ) - serial_steal_fn =3D NULL; + if ( id >=3D 0 && id <=3D MAX_SERCONS ) + serial_steal_fn[id] =3D NULL; } =20 void console_serial_puts(const char *s, size_t nr) { - if ( serial_steal_fn !=3D NULL ) - serial_steal_fn(s, nr); + unsigned int i; + + if ( serial_steal_fn[MAX_SERCONS] !=3D NULL ) + serial_steal_fn[MAX_SERCONS](s, nr); else - serial_puts(sercon_handle, s, nr); + for ( i =3D 0; i < nr_sercon_handle; i++ ) + { + if ( serial_steal_fn[i] !=3D NULL ) + serial_steal_fn[i](s, nr); + else + serial_puts(sercon_handle[i], s, nr); + } } =20 /* @@ -1026,6 +1057,7 @@ void __init console_init_preirq(void) { char *p; int sh; + unsigned int i; =20 serial_init_preirq(); =20 @@ -1046,8 +1078,12 @@ void __init console_init_preirq(void) continue; else if ( (sh =3D serial_parse_handle(p)) >=3D 0 ) { - sercon_handle =3D sh; - serial_steal_fn =3D NULL; + if ( nr_sercon_handle < MAX_SERCONS ) + sercon_handle[nr_sercon_handle++] =3D sh; + else + printk("Too many consoles (max %d), ignoring '%s'\n", + MAX_SERCONS, p); + serial_steal_fn[MAX_SERCONS] =3D NULL; } else { @@ -1065,7 +1101,8 @@ void __init console_init_preirq(void) opt_console_xen =3D 0; #endif =20 - serial_set_rx_handler(sercon_handle, serial_rx); + for ( i =3D 0; i < nr_sercon_handle; i++ ) + serial_set_rx_handler(sercon_handle[i], serial_rx); pv_console_set_rx_handler(serial_rx); =20 /* NB: send conring contents to all enabled physical consoles, if any = */ @@ -1084,7 +1121,8 @@ void __init console_init_preirq(void) =20 if ( opt_sync_console ) { - serial_start_sync(sercon_handle); + for ( i =3D 0; i < nr_sercon_handle; i++ ) + serial_start_sync(sercon_handle[i]); add_taint(TAINT_SYNC_CONSOLE); printk("Console output is synchronous.\n"); warning_add(warning_sync_console); @@ -1201,13 +1239,19 @@ int __init console_has(const char *device) =20 void console_start_log_everything(void) { - serial_start_log_everything(sercon_handle); + unsigned int i; + + for ( i =3D 0; i < nr_sercon_handle; i++ ) + serial_start_log_everything(sercon_handle[i]); atomic_inc(&print_everything); } =20 void console_end_log_everything(void) { - serial_end_log_everything(sercon_handle); + unsigned int i; + + for ( i =3D 0; i < nr_sercon_handle; i++ ) + serial_end_log_everything(sercon_handle[i]); atomic_dec(&print_everything); } =20 @@ -1223,23 +1267,32 @@ void console_unlock_recursive_irqrestore(unsigned l= ong flags) =20 void console_force_unlock(void) { + unsigned int i; + watchdog_disable(); spin_debug_disable(); rspin_lock_init(&console_lock); - serial_force_unlock(sercon_handle); + for ( i =3D 0 ; i < nr_sercon_handle ; i++ ) + serial_force_unlock(sercon_handle[i]); conring_no_notify =3D true; console_start_sync(); } =20 void console_start_sync(void) { + unsigned int i; + atomic_inc(&print_everything); - serial_start_sync(sercon_handle); + for ( i =3D 0 ; i < nr_sercon_handle ; i++ ) + serial_start_sync(sercon_handle[i]); } =20 void console_end_sync(void) { - serial_end_sync(sercon_handle); + unsigned int i; + + for ( i =3D 0; i < nr_sercon_handle; i++ ) + serial_end_sync(sercon_handle[i]); atomic_dec(&print_everything); } =20 @@ -1362,7 +1415,8 @@ static int suspend_steal_id; =20 int console_suspend(void) { - suspend_steal_id =3D console_steal(sercon_handle, suspend_steal_fn); + if ( nr_sercon_handle ) + suspend_steal_id =3D console_steal(SERHND_STEAL_ALL, suspend_steal= _fn); serial_suspend(); return 0; } diff --git a/xen/include/xen/serial.h b/xen/include/xen/serial.h index 1ee3df2624fb..31159814d883 100644 --- a/xen/include/xen/serial.h +++ b/xen/include/xen/serial.h @@ -101,6 +101,7 @@ struct uart_driver { #define SERHND_HI (1<<2) /* Mux/demux each transferred char by MSB. = */ #define SERHND_LO (1<<3) /* Ditto, except that the MSB is cleared. = */ #define SERHND_COOKED (1<<4) /* Newline/carriage-return translation? = */ +#define SERHND_STEAL_ALL 0xff /* Synthetic handle used in console_steal()= */ =20 /* Three-stage initialisation (before/during/after IRQ-subsystem setup). */ void serial_init_preirq(void); --=20 git-series 0.9.1