From patchwork Fri Dec 6 04:41:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 99776E77179 for ; Fri, 6 Dec 2024 04:41:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849412.1264039 (Exim 4.92) (envelope-from ) id 1tJQ9x-0005A7-V9; Fri, 06 Dec 2024 04:41:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849412.1264039; Fri, 06 Dec 2024 04:41:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQ9x-00058M-Oo; Fri, 06 Dec 2024 04:41:45 +0000 Received: by outflank-mailman (input) for mailman id 849412; Fri, 06 Dec 2024 04:41:43 +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 1tJQ9v-0004Ka-Li for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:43 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 617d6426-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:39 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 01D9E5C72FC; Fri, 6 Dec 2024 04:40:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 71ACCC4CEDD; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D5CBE77171; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) 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: 617d6426-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460097; bh=hhpepZyC6+B98tKRYu7FEASFfIF/3/TSsCfLQMcZ32A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=FgEft6ym49ftHh+ywRhew+yV7ooUsjJ9GgX7qlng7oFqZExFwgdQbJ3OZGbP2k1o8 hqWhBr48KvJajYXUC7s9kLqnORDaBpK0U5DsgE2yh8EUwvu7IWA4n9vf4y8pVWeHuL X0CNBMStmy163XE1QJQFbGSxnnzsiXE71hONAyET4ME7Jkfu4Y5PxY9DYQZi3ceIlX DUpDL78EXSQQxAzrVuEnY8ntTxHi4qhT0SXyQi334r+gmzvcqqV1ccgWwUuMKyjk+o Pf3N/SWiluN7VWPNThRC5ZB/bZ7FQAaFJaZWxzOL40fb6RU3SYMUULqSO3AtNoUJbS 6BhwXmARPGSWg== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:31 -0800 Subject: [PATCH v2 01/35] xen: introduce resource.h MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-1-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=4665; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=Q8GpN19knhkzccfTAV4prViqD1gvBrGqV7AxMvPxGlg=; b=pLKcxFd8odpX59gNXWYl0zBIJnHXlKMAZidA2yu9BapqleSET916m7mHU6Mvl0DNg3hQZIYM4 LVm76T+Dh3WCEayzQHVnI0ba7CbQu+O/yHEdwB8NsPJgJQ3XptYWOIA X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Move resource definitions to a new architecture-agnostic shared header file. It will be used in follow on NS8250 emulator code to describe legacy PC COM resources. Signed-off-by: Denis Mukhin --- xen/common/device-tree/device-tree.c | 21 +------------------ xen/drivers/passthrough/arm/smmu.c | 15 +------------- xen/include/xen/resource.h | 40 ++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 34 deletions(-) diff --git a/xen/common/device-tree/device-tree.c b/xen/common/device-tree/device-tree.c index d0528c5825651f7cc9ebca0c949229c9083063c6..e8f810b2fe10890c033ed3a9d4ca627010ad019b 100644 --- a/xen/common/device-tree/device-tree.c +++ b/xen/common/device-tree/device-tree.c @@ -24,6 +24,7 @@ #include #include #include +#include const void *device_tree_flattened; dt_irq_xlate_func dt_irq_xlate; @@ -535,26 +536,6 @@ int dt_child_n_size_cells(const struct dt_device_node *parent) return __dt_n_size_cells(parent, true); } -/* - * These are defined in Linux where much of this code comes from, but - * are currently unused outside this file in the context of Xen. - */ -#define IORESOURCE_BITS 0x000000ff /* Bus-specific bits */ - -#define IORESOURCE_TYPE_BITS 0x00001f00 /* Resource type */ -#define IORESOURCE_IO 0x00000100 /* PCI/ISA I/O ports */ -#define IORESOURCE_MEM 0x00000200 -#define IORESOURCE_REG 0x00000300 /* Register offsets */ -#define IORESOURCE_IRQ 0x00000400 -#define IORESOURCE_DMA 0x00000800 -#define IORESOURCE_BUS 0x00001000 - -#define IORESOURCE_PREFETCH 0x00002000 /* No side effects */ -#define IORESOURCE_READONLY 0x00004000 -#define IORESOURCE_CACHEABLE 0x00008000 -#define IORESOURCE_RANGELENGTH 0x00010000 -#define IORESOURCE_SHADOWABLE 0x00020000 - /* * Default translator (generic bus) */ diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index 03d22bce1e497e41834c273f9048b98dcbd48a54..aa6a968b574dce7cc753e8070fad3a6e585cd9e7 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -70,22 +71,8 @@ #define of_property_read_u32(np, pname, out) (!dt_property_read_u32(np, pname, out)) #define of_property_read_bool dt_property_read_bool #define of_parse_phandle_with_args dt_parse_phandle_with_args - -/* Xen: Helpers to get device MMIO and IRQs */ -struct resource -{ - paddr_t addr; - paddr_t size; - unsigned int type; -}; - -#define resource_size(res) (res)->size; - #define platform_device dt_device_node -#define IORESOURCE_MEM 0 -#define IORESOURCE_IRQ 1 - static struct resource *platform_get_resource(struct platform_device *pdev, unsigned int type, unsigned int num) diff --git a/xen/include/xen/resource.h b/xen/include/xen/resource.h new file mode 100644 index 0000000000000000000000000000000000000000..4962e17da8387b7f324317482b19cc9fe71433fc --- /dev/null +++ b/xen/include/xen/resource.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * System resource description. + * + * Reference: + * include/linux/ioport.h + */ +#if !defined(XEN__RESOURCE_H) +#define XEN__RESOURCE_H + +#define IORESOURCE_BITS 0x000000FFU /* Bus-specific bits */ + +#define IORESOURCE_TYPE_BITS 0x00001F00U /* Resource type */ +#define IORESOURCE_IO 0x00000100U /* PCI/ISA I/O ports */ +#define IORESOURCE_MEM 0x00000200U +#define IORESOURCE_REG 0x00000300U /* Register offsets */ +#define IORESOURCE_IRQ 0x00000400U +#define IORESOURCE_DMA 0x00000800U +#define IORESOURCE_BUS 0x00001000U + +#define IORESOURCE_PREFETCH 0x00002000U /* No side effects */ +#define IORESOURCE_READONLY 0x00004000U +#define IORESOURCE_CACHEABLE 0x00008000U +#define IORESOURCE_RANGELENGTH 0x00010000U +#define IORESOURCE_SHADOWABLE 0x00020000U + +#define IORESOURCE_UNKNOWN (~0U) + +struct resource { + paddr_t addr; + paddr_t size; + unsigned int type; +}; + +#define resource_size(res) (res)->size; + +#define foreach_resource(res) \ + for (; res && res->type != IORESOURCE_UNKNOWN; res++) + +#endif /* #if !defined(XEN__RESOURCE_H) */ From patchwork Fri Dec 6 04:41:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896485 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D0EAAE77181 for ; Fri, 6 Dec 2024 04:41:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849409.1264015 (Exim 4.92) (envelope-from ) id 1tJQ9w-0004cW-HV; Fri, 06 Dec 2024 04:41:44 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849409.1264015; Fri, 06 Dec 2024 04:41:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQ9w-0004a7-9D; Fri, 06 Dec 2024 04:41:44 +0000 Received: by outflank-mailman (input) for mailman id 849409; Fri, 06 Dec 2024 04:41:42 +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 1tJQ9u-0004Kb-J4 for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:42 +0000 Received: from nyc.source.kernel.org (nyc.source.kernel.org [2604:1380:45d1:ec00::3]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 616f521f-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:39 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id E2B9EA43E3F; Fri, 6 Dec 2024 04:39:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 7BA55C4CEDE; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C2F9E77175; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) 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: 616f521f-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460097; bh=jP7Qo7rqdlhdDtQjECWtHV/Nhjgbh2HMa37UuR2ELXI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=VzrVaW2cbMrG9x7Jrj87s43TAWtqcTNd2+m1z1Gk4WL/MKJSE10/C/PJtmrx8QnIW +yi2g+LLAwG4bFGgjXD7GdxPYQ5U3b+veIXKy1IR1p0WAi2YZIkpSJ2FawRLk0hfzz G408ojxg/NkVFunFlw8x++pozBR4dUWcimMaPCQbpdPpchIBOG+AdUSrzUTFLZIVwP ov2phTvjDnXcbeOgHXQZRaDgsXb1RftI6P9OwJiEMjGbQlicUsNet27BL/bhmbP0jo hW5Lbvqd70+/vqHuWhMOW92goNFvuO+txaM+S7Q3bDox9ukGih6lwNBJcdOi8foRGd pEfljzO0SwpgQ== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:32 -0800 Subject: [PATCH v2 02/35] xen/irq: introduce NO_IRQ MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-2-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=616; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=dP3fe+TbEoRyzDIKnwZpy2zc7XNhJoHUDN0gqSrT6Sc=; b=GKp4UmHhqYd4CVUECgv6TOG2tNjpaTsfFbUI/8w7Tg/1Iubs7IfYMbYiQH2BZuSCKukEeBIRd dw9amfh326NCUqU9lJxyOuAS13v+83XcJtUb9tN5Gt5oIKGchFjF22K X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Introduce definition for IRQ resource checks. Signed-off-by: Denis Mukhin --- xen/include/xen/irq.h | 1 + 1 file changed, 1 insertion(+) diff --git a/xen/include/xen/irq.h b/xen/include/xen/irq.h index 95034c0d6bb5f0aa7d5bb572aca59872508a438a..aee878293ecc0de6a938bcfea1140d36b4de745a 100644 --- a/xen/include/xen/irq.h +++ b/xen/include/xen/irq.h @@ -53,6 +53,7 @@ struct irqaction { #define AUTO_ASSIGN_IRQ (-1) #define NEVER_ASSIGN_IRQ (-2) #define FREE_TO_ASSIGN_IRQ (-3) +#define NO_IRQ (-4) struct irq_desc; From patchwork Fri Dec 6 04:41:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896482 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C1AC0E7717E for ; Fri, 6 Dec 2024 04:41:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849417.1264092 (Exim 4.92) (envelope-from ) id 1tJQA2-0006Ns-Sr; Fri, 06 Dec 2024 04:41:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849417.1264092; Fri, 06 Dec 2024 04:41:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQA2-0006La-24; Fri, 06 Dec 2024 04:41:50 +0000 Received: by outflank-mailman (input) for mailman id 849417; Fri, 06 Dec 2024 04:41:46 +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 1tJQ9x-0004Kb-Vk for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:45 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 617c78bd-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:39 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 3DC0C5C7300; Fri, 6 Dec 2024 04:40:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 8A1DAC4CED2; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 790DFE77178; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) 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: 617c78bd-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460097; bh=7koQaWLewXvB3SCK9dZyYM5ZVrnylbZtaIV5UaNbJIw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=hoHmD/h87nsVaTNuOwWGeJIP/ib+VrDqptGul4bHy+1jdGv6d0tesKtcPvEI/oaJe 5gYgVFGmwqoGY8HEbJxfhSqIJt2tDg0S2l/0824jsFFymZXukR9QdzTePCDTnKjc38 iodnbyM/HB9js6hJlTSJe5RkFB7ZexvdPVAjq3rXZkcAG4deVzj6gZX9VlOuUI2FN4 JCNQptf8RThz9o2L6YpvS5+FNqMfWtdvEWOzE6i8ERk9pL/nbNWc2BWNUTGXcEJyoC 1S96uEz9GWNeT1az2qZFamB5BR34pQ6pLzl92zrJhvSY57uAbe/pxoQ2Gi6vSMfzZa Pbpxih71Gdd6A== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:33 -0800 Subject: [PATCH v2 03/35] xen/ctype: introduce isconsole() MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-3-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=2965; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=VA1l2CgJQ6KceeM+tuMGN+rK6UFSe0FXEY/EUwUiYwI=; b=JGqXyT0nbX97Vn2mSNHSEgjpczcuciXKVCHfEW8CEpXFPzirY37JgpYwVuNT3Xh6fyHyQupM6 JwhVvYBYibZAg7WSsrLhqzDPlyDVc9R3X0g80jgVMZyQ7FNV0dbt/mw X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin There are several console drivers which have same checks w.r.t. printable characters. The check is moved to new isconsole() macro and re-used in the console drivers. Signed-off-by: Denis Mukhin --- xen/arch/arm/vuart.c | 3 +-- xen/arch/x86/hvm/hvm.c | 3 +-- xen/drivers/char/console.c | 2 +- xen/include/xen/ctype.h | 3 +++ 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/vuart.c b/xen/arch/arm/vuart.c index d5ba483f1e63245e545346ad5045098152b8c152..ac76e2327bb84f05ea5716c6f5550f94812d2827 100644 --- a/xen/arch/arm/vuart.c +++ b/xen/arch/arm/vuart.c @@ -79,8 +79,7 @@ static void vuart_print_char(struct vcpu *v, char c) struct domain *d = v->domain; struct vuart *uart = &d->arch.vuart; - /* Accept only printable characters, newline, and horizontal tab. */ - if ( !isprint(c) && (c != '\n') && (c != '\t') ) + if ( !isconsole(c) ) return ; spin_lock(&uart->lock); diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 74e58c653e6f697e7e563fd076bbbafaf257137d..493b699c708949b2109c26573a107565543f5d45 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -561,8 +561,7 @@ static int cf_check hvm_print_line( if ( dir != IOREQ_WRITE ) return X86EMUL_UNHANDLEABLE; - /* Accept only printable characters, newline, and horizontal tab. */ - if ( !isprint(c) && (c != '\n') && (c != '\t') ) + if ( !isconsole(c) ) return X86EMUL_OKAY; spin_lock(&cd->pbuf_lock); diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 7da8c5296f3b62c6c45131c58fe5cf0e393e9ef3..bb56953bab681a13da8d41431aba4632f1919df9 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -674,7 +674,7 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, c = *kin++; if ( c == '\n' ) break; - if ( isprint(c) || c == '\t' ) + if ( isconsole(c) ) *kout++ = c; } while ( --kcount > 0 ); diff --git a/xen/include/xen/ctype.h b/xen/include/xen/ctype.h index 773ac27aa44ac65e76e87cdec960450804310249..deebaad96ede34f16f61ece862c788232c1d1efd 100644 --- a/xen/include/xen/ctype.h +++ b/xen/include/xen/ctype.h @@ -4,6 +4,8 @@ /* * NOTE! This ctype does not handle EOF like the standard C * library is required to. + * + * See Rule 21.13 in docs/misra/rules.rst. */ #define _U 0x01 /* upper */ @@ -30,6 +32,7 @@ extern const unsigned char _ctype[]; #define isspace(c) ((__ismask(c)&(_S)) != 0) #define isupper(c) ((__ismask(c)&(_U)) != 0) #define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0) +#define isconsole(c) (isprint(c) || (c) == '\n' || (c) == '\t') #define isascii(c) (((unsigned char)(c))<=0x7f) #define toascii(c) (((unsigned char)(c))&0x7f) From patchwork Fri Dec 6 04:41:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896483 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CA446E7717B for ; Fri, 6 Dec 2024 04:41:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849406.1263994 (Exim 4.92) (envelope-from ) id 1tJQ9v-0004LD-Gw; Fri, 06 Dec 2024 04:41:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849406.1263994; Fri, 06 Dec 2024 04:41:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQ9v-0004L6-EE; Fri, 06 Dec 2024 04:41:43 +0000 Received: by outflank-mailman (input) for mailman id 849406; Fri, 06 Dec 2024 04:41:41 +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 1tJQ9t-0004Ka-Rt for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:41 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 617d9a13-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:39 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 438EA5C7301; Fri, 6 Dec 2024 04:40:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 96D5BC4CEE1; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85447E7716F; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) 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: 617d9a13-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460097; bh=8N48N7tGzPRpnph3uUKQy0qYgM/g5Ojg1QgMgxF7sN8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=B7AKTba+ZCUl25/KVnwXJy8Hx4furWv40RdLJaBnWVuOeZFlL/5lXJCq2aX3vKNY0 FOPix4J8eUDtwg7EjiUI9azlKC5V7Ci32+o22yC5GcEML6yz2jSqzMyg9ZW6vutoIM ZFTso8B0JdpV5SlGxqfc+o0tWdfJ4oeDBHAHJVm+WEwcrSxmZH6i5xaTkJY1josudm ZGXCgRot0jLMbpwx3mN+hBvdUELrLXlCeiCVP5OA9c89lUik+igDLmmsrAE+5evPFH RbJad18NKxmI4mCFErwyOwedH1ceSBgUOmilmdSsGu38B3PqTqJQw0wCP+BMf9v2GM JanRKrjFnDcvA== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:34 -0800 Subject: [PATCH v2 04/35] arm/vuart: use guest_printk() MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-4-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=1513; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=6dwRL08Xk+9xlKPfi6ImA8lNmAhhTdKU8a+CgXv8hC0=; b=r5qb9yLpCd19QazESKUYeqUw7XPz66116TcHZEi5I9uE5J5SBT20R+uyqiC8flWJlNa2WIADE piEke0mFrzmBELwfn54JWQkHGG+Fa1aPdvjA0UdJOW55FV1zieIoAsz X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Use guest_printk() in all current in-hypervisor UART emulators. That slightly improves the logging as guest_printk() already prints the domain ID. Signed-off-by: Denis Mukhin --- xen/arch/arm/vpl011.c | 2 +- xen/arch/arm/vuart.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c index 1fc3114cce9ddb48cf199834c8e9abe8cfba92b5..8ade6f2588b8bbcc58fb0f9edc324502a1992ce7 100644 --- a/xen/arch/arm/vpl011.c +++ b/xen/arch/arm/vpl011.c @@ -107,7 +107,7 @@ static void vpl011_write_data_xen(struct domain *d, uint8_t data) if ( data != '\n' ) intf->out[intf->out_prod++] = '\n'; intf->out[intf->out_prod++] = '\0'; - printk("DOM%u: %s", d->domain_id, intf->out); + guest_printk(d, "%s", intf->out); intf->out_prod = 0; } } diff --git a/xen/arch/arm/vuart.c b/xen/arch/arm/vuart.c index ac76e2327bb84f05ea5716c6f5550f94812d2827..38ce8cc14fac4132578059b696be952b29fab809 100644 --- a/xen/arch/arm/vuart.c +++ b/xen/arch/arm/vuart.c @@ -89,7 +89,7 @@ static void vuart_print_char(struct vcpu *v, char c) if ( c != '\n' ) uart->buf[uart->idx++] = '\n'; uart->buf[uart->idx] = '\0'; - printk(XENLOG_G_DEBUG "DOM%u: %s", d->domain_id, uart->buf); + guest_printk(d, "%s", uart->buf); uart->idx = 0; } spin_unlock(&uart->lock); From patchwork Fri Dec 6 04:41:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896487 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DBB57C3ABA1 for ; Fri, 6 Dec 2024 04:41:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849408.1264006 (Exim 4.92) (envelope-from ) id 1tJQ9w-0004U7-6C; Fri, 06 Dec 2024 04:41:44 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849408.1264006; Fri, 06 Dec 2024 04:41:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQ9v-0004RG-Ty; Fri, 06 Dec 2024 04:41:43 +0000 Received: by outflank-mailman (input) for mailman id 849408; Fri, 06 Dec 2024 04:41:42 +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 1tJQ9u-0004Kb-CC for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:42 +0000 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 617b5f8d-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:39 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 2A085A438D2; Fri, 6 Dec 2024 04:39:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 9F72EC4CEE3; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95DF9E77173; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) 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: 617b5f8d-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460097; bh=bTKPqZAc34jvickLJXvP5NAA91sRqludt+wCep7eH1g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=X1Z+RCdC6743SeS1lGFzXjH+Rno1zVaTL+63bSmr73koOsdjSsSgmtnwSh1zP/6rK f2XLz16uPLyy74nfOecLe3+f1fDKfG2p46fluY9dD7+3ziwzfupD96STPvqq9tbf0c bUYwxgg9CwB7c7ToN34dqGeaD1yV2WoYYRWtgEszLCXU/QIH7WE7VI2tURwUHGXtdy DSwjHzRuY7yqMqpCabccf6z8iDZpia+Fd/35Y6MjHKfXqyIoxDn5C9HwEp955fH0QR WqXGsUCLhzduH2XwMN9m+6EcCwUjgQOJORy6RMqxFmv7AM7tAUSs39u/qwM6aCi451 0JkBPjww/Wf+A== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:35 -0800 Subject: [PATCH v2 05/35] arm/vuart: make domain_has_vuart() public MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-5-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=3833; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=SVfYvrMsNY/TLDndYHXbgUHVOFhA4YTrVOLvr92vE7k=; b=KMBAyLtbB0Ts4a079gWdldbMDGnLogOr8Cebv62MircIQWQpRoRbNbWS6+p88uFLYfP/pXyVi Gzrxs1rf9uNBhhLQq24G16NdpQXXlSEicpPnATBvCVuUGsFulswQ37a X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Move domain_has_vuart() to arch namespace as preparation code change for architecture-agnostic way of forwarding physical console to the guest OS w/ in-hypervisor UART emulator. Signed-off-by: Denis Mukhin --- xen/arch/arm/dom0less-build.c | 2 ++ xen/arch/arm/domain.c | 19 ++++++++++++------- xen/arch/arm/domctl.c | 4 +++- xen/arch/arm/include/asm/domain.h | 9 +++++++++ xen/arch/arm/vuart.c | 2 -- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index f328a044e9d3bb5c9d358456c2ead5d2f125fbb1..de64ee930fdfe9a1c2842761275641485f69f675 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -831,6 +831,8 @@ static int __init construct_domU(struct domain *d, rc = domain_vpl011_init(d, NULL); if ( rc < 0 ) return rc; + + d->arch.emulation_flags |= ARM_EMU_VUART; } rc = prepare_dtb_domU(d, &kinfo); diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 3ba959f866338d2e7f7dc0e301cd79c10fbc4549..02f9d59b38b4b7f6f73d97c421c9948c90e681d5 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -769,14 +769,19 @@ int arch_domain_create(struct domain *d, if ( !vgic_reserve_virq(d, GUEST_EVTCHN_PPI) ) BUG(); } + else + { + /* + * Virtual UART is only used by linux early printk and decompress code. + * Only use it for the hardware domain because the linux kernel may not + * support multi-platform. + */ + rc = domain_vuart_init(d); + if ( rc ) + goto fail; - /* - * Virtual UART is only used by linux early printk and decompress code. - * Only use it for the hardware domain because the linux kernel may not - * support multi-platform. - */ - if ( is_hardware_domain(d) && (rc = domain_vuart_init(d)) ) - goto fail; + d->arch.emulation_flags |= ARM_EMU_VUART; + } if ( (rc = domain_vpci_init(d)) != 0 ) goto fail; diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c index 9d047065ba13ffe003d2565879cd073e78f76893..f80d34bf5f3d323a15db7f032073be52ea1009ae 100644 --- a/xen/arch/arm/domctl.c +++ b/xen/arch/arm/domctl.c @@ -42,9 +42,11 @@ static int handle_vuart_init(struct domain *d, return -EOPNOTSUPP; rc = domain_vpl011_init(d, &info); - if ( !rc ) + { vuart_op->evtchn = info.evtchn; + d->arch.emulation_flags |= ARM_EMU_VUART; + } return rc; } diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h index f1d72c6e48dfeba347b4cd091ca33603c368b7c0..2bbd3f472176bdcfbc0f95f9d8809343d11965c8 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -119,8 +119,17 @@ struct arch_domain void *tee; #endif + /* Emulated devices enabled bitmap. */ + uint32_t emulation_flags; + } __cacheline_aligned; +enum { + ARM_EMU_VUART = BIT(0, U), +}; + +#define domain_has_vuart(d) (!!((d)->arch.emulation_flags & ARM_EMU_VUART)) + struct arch_vcpu { struct { diff --git a/xen/arch/arm/vuart.c b/xen/arch/arm/vuart.c index 38ce8cc14fac4132578059b696be952b29fab809..1fd980bd3a83820b382f875eb87ce4b8d83ccebe 100644 --- a/xen/arch/arm/vuart.c +++ b/xen/arch/arm/vuart.c @@ -31,8 +31,6 @@ #include "vuart.h" -#define domain_has_vuart(d) ((d)->arch.vuart.info != NULL) - static int vuart_mmio_read(struct vcpu *v, mmio_info_t *info, register_t *r, void *priv); static int vuart_mmio_write(struct vcpu *v, mmio_info_t *info, From patchwork Fri Dec 6 04:41:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896490 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E7B54E77182 for ; Fri, 6 Dec 2024 04:41:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849413.1264050 (Exim 4.92) (envelope-from ) id 1tJQ9y-0005L0-IS; Fri, 06 Dec 2024 04:41:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849413.1264050; Fri, 06 Dec 2024 04:41:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQ9y-0005Gg-65; Fri, 06 Dec 2024 04:41:46 +0000 Received: by outflank-mailman (input) for mailman id 849413; Fri, 06 Dec 2024 04:41:44 +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 1tJQ9v-0004Kb-Vj for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:43 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 617c78a4-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:39 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 530575C7303; Fri, 6 Dec 2024 04:40:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id ADC4EC4CEE4; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3375E77171; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) 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: 617c78a4-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460097; bh=BvkwglhN7fVuiz9QCGrNgLj6KeYwL4hLgRPhmZlEXLs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=R0NAk2V8k78+YO2fyShNo4hL4Q1QuOCwlaxH70++zHg++M5jR9WmS6Pi218PwtJPl 1uhUrWRICPMVWKl2K8Mkq/9q9JewEjHT1yPgvVnUmiSpDJ8w1wez75Gu6MEWmTiG9+ QnwMPIzTmxlz5mWBy+xWIwQjijohFsGDT6Pj6XZqQbC6F/HvimDm5+u4Ftn7nalOtB RzWkCD9y6lTfSHZTodpumJK9JAwBPIrJ6yIZw96gsBGNTOQG71n1MJJzLW4oRw9gXx n9xM/MTAczUz0gbFiUXPhpuKIipcV5ZCfdScJ7fjJKx/eihIAZ6ON+mBuQjvf4wkjf sFWy5RETs+1Iw== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:36 -0800 Subject: [PATCH v2 06/35] riscv/domain: introduce domain_has_vuart() MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-6-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin , Oleksii Kurochko X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=737; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=+kPk8EKdgpPKuThGSrouRJGm0Vji6pKcYMUo97PKO3Q=; b=6hYpirrUtuGFg5SJ0XrKEsxgzUe45RwgR0LajeGuvIJ0aB25n1VGtzPpVnNKCGGGKS7oUgfI4 8U4z97HHmmfBzikcouSM5h0MFyMmyrQbcm5azQxSjCr9Bq6EhZyi00j X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Introduce domain_has_vuart() for RISC-V port to be used in the console driver. Signed-off-by: Denis Mukhin Reviewed-by: Oleksii Kurochko --- xen/arch/riscv/include/asm/domain.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xen/arch/riscv/include/asm/domain.h b/xen/arch/riscv/include/asm/domain.h index c3d965a559b6ce3661bf17166d0c51853ff295a2..efbc4f1ea2619a187fe30ede17d96de01e599220 100644 --- a/xen/arch/riscv/include/asm/domain.h +++ b/xen/arch/riscv/include/asm/domain.h @@ -10,6 +10,8 @@ struct hvm_domain uint64_t params[HVM_NR_PARAMS]; }; +#define domain_has_vuart(d) false + struct arch_vcpu_io { }; From patchwork Fri Dec 6 04:41:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896489 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E80EAE77183 for ; Fri, 6 Dec 2024 04:41:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849411.1264032 (Exim 4.92) (envelope-from ) id 1tJQ9x-00053D-Ib; Fri, 06 Dec 2024 04:41:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849411.1264032; Fri, 06 Dec 2024 04:41:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQ9x-00050h-Ab; Fri, 06 Dec 2024 04:41:45 +0000 Received: by outflank-mailman (input) for mailman id 849411; Fri, 06 Dec 2024 04:41:43 +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 1tJQ9u-0004Kb-VS for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:42 +0000 Received: from nyc.source.kernel.org (nyc.source.kernel.org [2604:1380:45d1:ec00::3]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6197751f-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:39 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 52687A43EE1; Fri, 6 Dec 2024 04:39:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id BC663C4CEE8; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1075E77175; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) 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: 6197751f-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460097; bh=W3lsM6sLlkNO6zjU1lHZ+u6ONjEFm+ba+WSVSjVypa4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=DzXyb2zjGR03GXUhiHI+xBOLA5fTxJrXkDBwuKdD2uykpkrZ+FUvzLyROXp6yAHfk gPqgyybJkcvTsxc15htT0OAM9Ivaj/BmebKPxvPKLGBuw5VzuI279sbQhQr9OKuovx 38W+0IFNSQLSeABoc7GgKPl6gv8MT6rIExY03ViEQYBHm1pKL5hi5B+uO+hiZu3QOO cX1pEb7BisWouEaN5ux86AiFRrq7o8+lg4NqBJSzzQ2tiIfF1x19Gy8zsSakAZCoWF GNR6U8WG+cbnhR4s+kP8mpNHOUh4XGXyj3F2U0R9JFTWCPPSaL1w4VztS1mLM+17wS 52WTHc1B2CF7w== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:37 -0800 Subject: [PATCH v2 07/35] ppc/domain: introduce domain_has_vuart() MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-7-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=728; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=t3QJZEOM8PRrx5tFAM37Q5lrsCWx/ouiwIRJrERCogM=; b=Miqdv195rw9t1S3j6p1XRsugjWUwQ1EFx/shKs1eSw6d+ul8/IaMuWZDk+NDDthwgf90m1sxh 3kbUZi6bZ/2BoWa5b05lZ0tlZtXQXK10znL6NDjaUHlqXg1kvLQo1tH X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Introduce domain_has_vuart() for PPC port to be used in the console driver. Signed-off-by: Denis Mukhin --- xen/arch/ppc/include/asm/domain.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xen/arch/ppc/include/asm/domain.h b/xen/arch/ppc/include/asm/domain.h index 3a447272c6f28586bf0d610929adbf228579e13f..764978e6a61b9d7220ec10fe0763e3424d07d27a 100644 --- a/xen/arch/ppc/include/asm/domain.h +++ b/xen/arch/ppc/include/asm/domain.h @@ -10,6 +10,8 @@ struct hvm_domain uint64_t params[HVM_NR_PARAMS]; }; +#define domain_has_vuart(d) false + /* TODO: Implement */ #define guest_mode(r) ({ (void)(r); BUG_ON("unimplemented"); 0; }) From patchwork Fri Dec 6 04:41:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896480 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A9590E7717D for ; Fri, 6 Dec 2024 04:41:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849414.1264068 (Exim 4.92) (envelope-from ) id 1tJQA0-0005wG-Bq; Fri, 06 Dec 2024 04:41:48 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849414.1264068; Fri, 06 Dec 2024 04:41:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQ9z-0005u6-Tt; Fri, 06 Dec 2024 04:41:47 +0000 Received: by outflank-mailman (input) for mailman id 849414; Fri, 06 Dec 2024 04:41:44 +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 1tJQ9w-0004Ka-Lc for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:44 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [2604:1380:4641:c500::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 62c9fd31-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:41 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 6BEB75C7306; Fri, 6 Dec 2024 04:40:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id CBE87C4CEEA; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0A58E77178; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) 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: 62c9fd31-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460097; bh=uX6eDC7J8gnEJzkAK+vFayV4YOh384qGm0SB3/a+eoo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=avrLbYKG1EF7oiTpLzSi+p6WiQ4UauuUO4vJI1wxBJfqP0HTep/fmdpbossvNA2co X20WpEpvBT3BOf005Ojs+fbuF7F0OjbqeNz+G3mag/JaxhthJYt2uDfK+TpLzUO7t+ Q99tKINVNihcqmQmoZ8ImR0pfr8Z/PVUbCas9rTHpEFTPPsCEv4EDUGpBKr0DTeD0N dMWZkTjIlI9pfmYIfsmOLE4CvrEvENBGrMZTrNw1brkmVFouX3W56rKC8mgFck5Pz5 R+NLN41O1RfOi56obCLFefiqr3kwGd0WSz9ifMw45arh6ghob7nChf5WANLv+Ln1f1 rmWq4AL3jL9ew== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:38 -0800 Subject: [PATCH v2 08/35] x86/domain: introduce domain_has_vuart() MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-8-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=889; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=d8+eK1EX7G4dAD9MTJCuZscRKOX31WZGg59AsNpMxsU=; b=cG7SkKjK5QUHyRM3m5wrGnS1pgFt0n85Fs1Xe2pmZs5Vlb0KOvwBf5tETIrxKlEyd7jpRII9O toWVU7GmrsPCS+fsxc/qQNc08AGwg1KYEmN2hQEgOOrZFF13XuOGfCc X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Introduce domain_has_vuart() for x86 port to be used in the console driver. Signed-off-by: Denis Mukhin --- xen/arch/x86/include/asm/domain.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xen/arch/x86/include/asm/domain.h b/xen/arch/x86/include/asm/domain.h index b79d6badd71c4d96279555df62fad75fe817a2b6..c1d0d1f47324e8cc678a4c76c43f86820a89e7b3 100644 --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -506,6 +506,9 @@ struct arch_domain #define has_pirq(d) (!!((d)->arch.emulation_flags & X86_EMU_USE_PIRQ)) #define has_vpci(d) (!!((d)->arch.emulation_flags & X86_EMU_VPCI)) +/* NB: same symbol as in Arm port */ +#define domain_has_vuart(d) false + #define gdt_ldt_pt_idx(v) \ ((v)->vcpu_id >> (PAGETABLE_ORDER - GDT_LDT_VCPU_SHIFT)) #define pv_gdt_ptes(v) \ From patchwork Fri Dec 6 04:41:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896492 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3017DE77185 for ; Fri, 6 Dec 2024 04:41:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849407.1264002 (Exim 4.92) (envelope-from ) id 1tJQ9v-0004OQ-Sm; Fri, 06 Dec 2024 04:41:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849407.1264002; Fri, 06 Dec 2024 04:41:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQ9v-0004Ng-Kb; Fri, 06 Dec 2024 04:41:43 +0000 Received: by outflank-mailman (input) for mailman id 849407; Fri, 06 Dec 2024 04:41:42 +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 1tJQ9u-0004Ka-50 for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:42 +0000 Received: from nyc.source.kernel.org (nyc.source.kernel.org [2604:1380:45d1:ec00::3]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 619fc92f-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:39 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 6750BA43EEF; Fri, 6 Dec 2024 04:39:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id D8D96C4CED1; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D21F2E77173; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) 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: 619fc92f-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460097; bh=2WgWqZsNDflVD6JmnKTRAOPbRC5jJUlqppnLV6LXXy4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=eFVU2m0MN1WdzL+1zbIbqDbDYwa9z1Mr9M1oPjJvCwWXkaXsAfzWiZQFuhrPbIcr2 nAvRMg5F3PJTqc6q153JNQkfmBacrI1Q4a9/ZMexcU7YmXwid8fTTZWdvPs8ZDkblq IcvJp8HzxF2lUT0tmHE6uokd+ncoq83kQEXK0lSsRF3DxAi0tNsqQXxx7Uw42xixnS gtiiQLpoNi6l7H/gPWv7j8rRyfZpzB+Hxo0gKKpxCQWFYnfb1TD6rfgytu5hGvkLx4 aA9DgEvxgSclbOxgr+uGf92wH0hC0TOvsyf/M8gC4XW1yUxs3R9m0dDTwgo0ZEPgtw IHtSBGOlOfKsg== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:39 -0800 Subject: [PATCH v2 09/35] x86/domain: print emulation_flags MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-9-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=1263; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=732gIMLcaCgGTFTHv9vAjNIT6ES/ZZttjeIUCT3F6PI=; b=Y7HK/z6jmiAxr9LffbLx3VzuTnpvsJKN4W5zpRGYQrcHh7C1xfTaL3qBH1d/hc6odnj49z0ll kg3ON+vpt6nA9uN2Ik2YEXEG2SpMz1AzDdlcvsmncdiJ05m4eO9kdq9 X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Print d->arch.emulation_flags on the console for better traceability while debugging in-hypervisor hardware emulators. Signed-off-by: Denis Mukhin --- xen/arch/x86/domain.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 78a13e6812c9120901d0a70fb3bc1bd6a8b6917d..c88d422a64544531c1e1058fa484364bb4277d1e 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -818,11 +818,15 @@ int arch_domain_create(struct domain *d, if ( !emulation_flags_ok(d, emflags) ) { - printk(XENLOG_G_ERR "d%d: Xen does not allow %s domain creation " + printk(XENLOG_G_ERR "d%d: Xen does not allow %s %sdomain creation " "with the current selection of emulators: %#x\n", - d->domain_id, is_hvm_domain(d) ? "HVM" : "PV", emflags); + d->domain_id, + is_hvm_domain(d) ? "HVM" : "PV", + is_hardware_domain(d) ? "(hardware) " : "", + emflags); return -EOPNOTSUPP; } + printk(XENLOG_G_INFO "d%d: emulation_flags %#x\n", d->domain_id, emflags); d->arch.emulation_flags = emflags; #ifdef CONFIG_PV32 From patchwork Fri Dec 6 04:41:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896493 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EA88FE77173 for ; Fri, 6 Dec 2024 04:42:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849421.1264124 (Exim 4.92) (envelope-from ) id 1tJQA7-0007VG-06; Fri, 06 Dec 2024 04:41:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849421.1264124; Fri, 06 Dec 2024 04:41:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQA6-0007RI-A9; Fri, 06 Dec 2024 04:41:54 +0000 Received: by outflank-mailman (input) for mailman id 849421; Fri, 06 Dec 2024 04:41:48 +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 1tJQ9z-0004Kb-W4 for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:47 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 62c8835c-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:41 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 6FFB45C7307; Fri, 6 Dec 2024 04:40:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id E9ACAC4CEE0; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E22EDE77175; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) 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: 62c8835c-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460097; bh=tVwGh2fI891yEmph9JS9g2v7QV1qSjDfL8jnuUT3Tb8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=DBzgJtybXhXq1eNkGfJ8DH1NhvocvW43UaWJ9Yx+ZaXnNmA7O91SFdmShOORcVfjc jJkau6mG4PfPNOa4/gtFMIMNBSuBVQ6+QULjgjSOucPgBbrGBRwBQdv3Q1JPenSYxo StTLy1K1v+DGdusUclQTcVrhsIMhXGkXujhnJcSKF6smgwfomcNBGKegVM17FzZBcR ILYV6ViRZ+htsoggtX+Xrtdx3yiRGKpZHQl9qXkuBHnW4wwrVYnPuxKSlGyqVeAtuh lKJdnFiqZHDxt2JE2VxWnV7BgfUTYJ/pYb8RrXVXFOzHNhAkH7Un/VfcFRnFQ28tLq bTNnIVfNOYHmw== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:40 -0800 Subject: [PATCH v2 10/35] xen/domain: add get_initial_domain_id() MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-10-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=3214; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=e/LNB+9Wk5d4Vu+ImwNmQARBXeefJiOOq9L8JfHstNA=; b=5L8rPCs4pZZiWY8ZAdYomk3nYievoOQV1OGbxK/bIoBZOmkf4+R9OBRrd2hxO0WaHFXCsqyvB h1bbyNFHNsVBIh6LUg6sY+kHC6raUY41Eek0IyLAbNbykEParYXDVD8 X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Move get_initial_domain_id() to a public API and enable for all architectures. That is pre-requisite change for console focus switch logic cleanup. Signed-off-by: Denis Mukhin --- xen/arch/x86/include/asm/pv/shim.h | 4 ++-- xen/arch/x86/pv/shim.c | 4 ++-- xen/common/domain.c | 10 ++++++++++ xen/include/xen/domain.h | 2 ++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/include/asm/pv/shim.h b/xen/arch/x86/include/asm/pv/shim.h index 6153e27005986881ad87e9db0b555b30edc59fc0..1515ad1b0680aa11ab91a152a1944fc1bb477a79 100644 --- a/xen/arch/x86/include/asm/pv/shim.h +++ b/xen/arch/x86/include/asm/pv/shim.h @@ -31,7 +31,7 @@ long cf_check pv_shim_cpu_up(void *data); long cf_check pv_shim_cpu_down(void *data); void pv_shim_online_memory(unsigned int nr, unsigned int order); void pv_shim_offline_memory(unsigned int nr, unsigned int order); -domid_t get_initial_domain_id(void); +domid_t pv_shim_initial_domain_id(void); uint64_t pv_shim_mem(uint64_t avail); void pv_shim_fixup_e820(void); const struct platform_bad_page *pv_shim_reserved_pages(unsigned int *size); @@ -76,7 +76,7 @@ static inline void pv_shim_offline_memory(unsigned int nr, unsigned int order) { ASSERT_UNREACHABLE(); } -static inline domid_t get_initial_domain_id(void) +static inline domid_t pv_shim_initial_domain_id(void) { return 0; } diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c index 81e4a0516d18b359561f471f1d96e38977661ca7..17cb30620290c76cf42251f70cfa4199c0e165d1 100644 --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -328,7 +328,7 @@ int pv_shim_shutdown(uint8_t reason) } /* Update domain id. */ - d->domain_id = get_initial_domain_id(); + d->domain_id = pv_shim_initial_domain_id(); /* Clean the iomem range. */ BUG_ON(iomem_deny_access(d, 0, ~0UL)); @@ -1016,7 +1016,7 @@ void pv_shim_offline_memory(unsigned int nr, unsigned int order) } } -domid_t get_initial_domain_id(void) +domid_t pv_shim_initial_domain_id(void) { uint32_t eax, ebx, ecx, edx; diff --git a/xen/common/domain.c b/xen/common/domain.c index 92263a4fbdc57159b4a32d9d4ee038f9f37804ed..2f67aa06ed50e69c27cedc8d7f6eb0b469fe81cd 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -45,6 +45,7 @@ #ifdef CONFIG_X86 #include +#include #endif /* Linux config option: propageted to domain0 */ @@ -2229,6 +2230,15 @@ int continue_hypercall_on_cpu( return 0; } +domid_t get_initial_domain_id(void) +{ +#ifdef CONFIG_X86 + return pv_shim_initial_domain_id(); +#else + return 0; +#endif +} + /* * Local variables: * mode: C diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 3de56352911347a54cce310f0211bcc213d8a08d..601ef431cf621af44c867400499b73b845eb137a 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -171,4 +171,6 @@ extern bool vmtrace_available; extern bool vpmu_is_available; +domid_t get_initial_domain_id(void); + #endif /* __XEN_DOMAIN_H__ */ From patchwork Fri Dec 6 04:41:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896484 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A7220E7717C for ; Fri, 6 Dec 2024 04:41:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849415.1264073 (Exim 4.92) (envelope-from ) id 1tJQA0-00062t-U6; Fri, 06 Dec 2024 04:41:48 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849415.1264073; Fri, 06 Dec 2024 04:41:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQA0-000608-I8; Fri, 06 Dec 2024 04:41:48 +0000 Received: by outflank-mailman (input) for mailman id 849415; Fri, 06 Dec 2024 04:41:45 +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 1tJQ9w-0004Kb-Vd for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:44 +0000 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 61bf3ac9-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:39 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 6B989A43EF8; Fri, 6 Dec 2024 04:39:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 059B1C4CEEC; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0BA2E77171; Fri, 6 Dec 2024 04:41:37 +0000 (UTC) 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: 61bf3ac9-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460098; bh=+PxKx+9Bd/NEReVQwLv8HwHoaFwOF8+i20hqmE7xSXQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Nj6XLkuQmLp/uNXjB+dsck6DBJ29uP2b4H0jd7JyvqHnpdXwzzPGJwZz763k3n2K6 vy15uHNlEWnIvngW4gA7kpIkR/o0nMhomWd9N4qTGW9zrFGiSewvc5SS//R1Z/So7J zpfTk/+m2gKC5dpiJ2vke+LWmqXtmf7LhOQdETNRLCPUoKxuV7nopiInEqPzQhCLFI 9U37FnA+WaAj7sfDO8TBa1xojmEqEA22aW1xWcFQ5mllJPxI6dMQQ1+98PKocXtvHX R8UbVM511Ui+2dBoGD2FDFQPsvDDRG0DYmWqjmW89S0DxHpyNcLtE+kM/v0j1yZrGl 6TTsyQhh5v9Bw== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:41 -0800 Subject: [PATCH v2 11/35] xen/domain: enable max_init_domid for all architectures MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-11-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=4201; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=8SSnD1Rvlg1COWggZ+OR+NWe7LtZUd10G0Zzgq+sluI=; b=bpAwdXM1HckuHe2z460ut11GP/zeb2Seuz4iMoUD0qKiSQ2aJi9gKWeH+xAYirZL5R2XB7tFP S+AaQcyn37ZA9gVrx6KR2HNyCi7SiNrHbwLipUFQcKHQeVhT1n3aPXS X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Move max_init_domid to a public API and enable for all architectures. That is pre-requisite change for console focus switch logic cleanup. max_init_domid is updated in domain_create(). Signed-off-by: Denis Mukhin --- xen/arch/arm/include/asm/setup.h | 2 -- xen/arch/arm/setup.c | 2 -- xen/arch/ppc/include/asm/setup.h | 2 -- xen/arch/riscv/include/asm/setup.h | 2 -- xen/arch/x86/include/asm/setup.h | 2 -- xen/common/domain.c | 9 +++++++++ xen/include/xen/domain.h | 2 ++ 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h index 64c227d171fc7b92e5b62d9fd42e5662871bd12b..d4e1670cd69cdd4475b2a5eb316d2c0601090ed7 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -19,8 +19,6 @@ struct map_range_data struct rangeset *irq_ranges; }; -extern domid_t max_init_domid; - void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len); size_t estimate_efi_size(unsigned int mem_nr_banks); diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 2e27af4560a504bf57daef572d4a768bd886145b..cb218fe3eb36f2cdda47cfa092fa99ee1ca4a14c 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -58,8 +58,6 @@ struct cpuinfo_arm __read_mostly system_cpuinfo; bool __read_mostly acpi_disabled; #endif -domid_t __read_mostly max_init_domid; - static __used void init_done(void) { int rc; diff --git a/xen/arch/ppc/include/asm/setup.h b/xen/arch/ppc/include/asm/setup.h index e4f64879b68ca5aac24bd9544255143e6ef693f3..956fa6985adb23375bd41d3e5d34d9d5f0712bd5 100644 --- a/xen/arch/ppc/include/asm/setup.h +++ b/xen/arch/ppc/include/asm/setup.h @@ -1,6 +1,4 @@ #ifndef __ASM_PPC_SETUP_H__ #define __ASM_PPC_SETUP_H__ -#define max_init_domid (0) - #endif /* __ASM_PPC_SETUP_H__ */ diff --git a/xen/arch/riscv/include/asm/setup.h b/xen/arch/riscv/include/asm/setup.h index 844a2f0ef1d762b3a9bc90b61a336a23f1693cc9..978cad71d3df484e80ba19acc0e37b9278e941f0 100644 --- a/xen/arch/riscv/include/asm/setup.h +++ b/xen/arch/riscv/include/asm/setup.h @@ -3,8 +3,6 @@ #ifndef ASM__RISCV__SETUP_H #define ASM__RISCV__SETUP_H -#define max_init_domid (0) - void setup_mm(void); #endif /* ASM__RISCV__SETUP_H */ diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/setup.h index 5c2391a8684b66efdf4b092409ed33935db6b40c..296348655b9d146c73acc305cc9edd5fd46f7d47 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -69,6 +69,4 @@ extern bool opt_dom0_verbose; extern bool opt_dom0_cpuid_faulting; extern bool opt_dom0_msr_relaxed; -#define max_init_domid (0) - #endif diff --git a/xen/common/domain.c b/xen/common/domain.c index 2f67aa06ed50e69c27cedc8d7f6eb0b469fe81cd..9e57dd4122a726e2fb42efe9c029e775202be0e6 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -65,6 +65,9 @@ DEFINE_RCU_READ_LOCK(domlist_read_lock); static struct domain *domain_hash[DOMAIN_HASH_SIZE]; struct domain *domain_list; +/* Last known non-system domain ID. */ +domid_t __read_mostly max_init_domid; + /* * Insert a domain into the domlist/hash. This allows the domain to be looked * up by domid, and therefore to be the subject of hypercalls/etc. @@ -815,6 +818,12 @@ struct domain *domain_create(domid_t domid, memcpy(d->handle, config->handle, sizeof(d->handle)); + /* + * Housekeeping for physical console forwarding to the domain. + */ + if ( !is_system_domain(d) && max_init_domid < domid ) + max_init_domid = domid; + return d; fail: diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 601ef431cf621af44c867400499b73b845eb137a..6102826a929ff7aad58a4bc40974815071a97446 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -171,6 +171,8 @@ extern bool vmtrace_available; extern bool vpmu_is_available; +extern domid_t max_init_domid; + domid_t get_initial_domain_id(void); #endif /* __XEN_DOMAIN_H__ */ From patchwork Fri Dec 6 04:41:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896486 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CE4B8E77180 for ; Fri, 6 Dec 2024 04:41:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849416.1264080 (Exim 4.92) (envelope-from ) id 1tJQA1-0006Dm-T7; Fri, 06 Dec 2024 04:41:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849416.1264080; Fri, 06 Dec 2024 04:41:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQA1-0006Bs-Bc; Fri, 06 Dec 2024 04:41:49 +0000 Received: by outflank-mailman (input) for mailman id 849416; Fri, 06 Dec 2024 04:41:45 +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 1tJQ9x-0004Ka-Ly for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:45 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [2604:1380:4641:c500::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 63086e56-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:41 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9DE2C5C730C; Fri, 6 Dec 2024 04:40:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 11DC6C4CEDE; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B848E77173; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) 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: 63086e56-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460098; bh=+LyhLMcPTctK8lq8DYz5tUJcWDqBCiRHMGxFmxItyZs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=HBz+lNxRiLiqkCAG1Sbj8epCgg/Cp6fOqh1OfYZMGXzeLm7CsM/uW+4eYuDwjeZ+u ntKEVy2vfBbN6qjG2zrmR6GM33QU91X8oz5uPJRiikGJXNR5AasNHw5k2s0x4zicuq IiJpAbnv0oGEg5G6EP7+7RajPRXWFcQLPRbi/o+xSST7a1QZZrI4GTp9/oLUIpXBfs cXGfBfvnz8bXfzejW4Bv30qLL9A+2bLEvlzW6pmcoETpfVr2X0rPE3yvanWbarC0+0 3uQZKhDRvXJjLrGsW8ytGUUQ+FzF1vHqBJWBNyXyumxGxqXgD9+r4t+xN9c4pjgot0 8/mX2URhGIHnA== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:42 -0800 Subject: [PATCH v2 12/35] xen/console: move vpl011-related code to vpl011 emulator MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-12-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=3432; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=4e0NUECCqgXdJR10Lb5Vlh9vQMFlpd/8G3QTPhFXMng=; b=KocrOyWBiCRdnAEiMCLW1htC7QinL+Mg1NhUgbiDAge7ljxpdEUkZHKjGaPRBPpqIuYyd94qh VtPCr7iMtAuCevzRbRS6SKJouJY7MRd2FPh0+9iI/OWzujWexOb2SBA X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Xen console driver has vpl011-related logic which shall belong vpl011 emulator code. Move vpl011-related to vpl011.c. Signed-off-by: Denis Mukhin --- xen/arch/arm/include/asm/vpl011.h | 2 +- xen/arch/arm/vpl011.c | 15 +++++++++++---- xen/drivers/char/console.c | 4 +--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/include/asm/vpl011.h b/xen/arch/arm/include/asm/vpl011.h index c09abcd7a9b3356d0809743517934adae00087f5..cc838682815c0d049ba33d3bf9966a64b2e527dd 100644 --- a/xen/arch/arm/include/asm/vpl011.h +++ b/xen/arch/arm/include/asm/vpl011.h @@ -69,7 +69,7 @@ struct vpl011_init_info { int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info); void domain_vpl011_deinit(struct domain *d); -void vpl011_rx_char_xen(struct domain *d, char c); +int vpl011_rx_char_xen(struct domain *d, char c); #else static inline int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info) diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c index 8ade6f2588b8bbcc58fb0f9edc324502a1992ce7..fe36fe2bd1529a4114884580ded6d6fa55a22f0e 100644 --- a/xen/arch/arm/vpl011.c +++ b/xen/arch/arm/vpl011.c @@ -567,16 +567,21 @@ static void vpl011_data_avail(struct domain *d, /* * vpl011_rx_char_xen adds a char to a domain's vpl011 receive buffer. - * It is only used when the vpl011 backend is in Xen. */ -void vpl011_rx_char_xen(struct domain *d, char c) +int vpl011_rx_char_xen(struct domain *d, char c) { unsigned long flags; struct vpl011 *vpl011 = &d->arch.vpl011; struct vpl011_xen_backend *intf = vpl011->backend.xen; XENCONS_RING_IDX in_cons, in_prod, in_fifo_level; - ASSERT(!vpl011->backend_in_domain); + /* Forward input iff the vpl011 backend is in Xen. */ + if ( vpl011->backend_in_domain ) + return -ENODEV; + + if ( intf == NULL ) + return -ENODEV; + VPL011_LOCK(d, flags); in_cons = intf->in_cons; @@ -584,7 +589,7 @@ void vpl011_rx_char_xen(struct domain *d, char c) if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) == sizeof(intf->in) ) { VPL011_UNLOCK(d, flags); - return; + return -ENOSPC; } intf->in[xencons_mask(in_prod, sizeof(intf->in))] = c; @@ -596,6 +601,8 @@ void vpl011_rx_char_xen(struct domain *d, char c) vpl011_data_avail(d, in_fifo_level, sizeof(intf->in), 0, SBSA_UART_FIFO_SIZE); VPL011_UNLOCK(d, flags); + + return 0; } static void vpl011_notification(struct vcpu *v, unsigned int port) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index bb56953bab681a13da8d41431aba4632f1919df9..0af4b551801356f242f1770b3826608136d65653 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -559,9 +559,7 @@ static void __serial_rx(char c) * domain, without a full PV ring to Dom0 (in that case input * comes from the PV ring), then send the character to it. */ - if ( d != NULL && - !d->arch.vpl011.backend_in_domain && - d->arch.vpl011.backend.xen != NULL ) + if ( d != NULL ) vpl011_rx_char_xen(d, c); else printk("Cannot send chars to Dom%d: no UART available\n", From patchwork Fri Dec 6 04:41:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C6A84E77173 for ; Fri, 6 Dec 2024 04:42:07 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849427.1264161 (Exim 4.92) (envelope-from ) id 1tJQAE-0000Nf-0h; Fri, 06 Dec 2024 04:42:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849427.1264161; Fri, 06 Dec 2024 04:42:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQAC-0000FC-G9; Fri, 06 Dec 2024 04:42:00 +0000 Received: by outflank-mailman (input) for mailman id 849427; Fri, 06 Dec 2024 04:41:50 +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 1tJQA2-0004Kb-0D for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:50 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 631bd654-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:42 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A45025C730F; Fri, 6 Dec 2024 04:40:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 29627C4CED2; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D715E77171; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) 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: 631bd654-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460098; bh=ta4eTkD9D4OUBDs5UKjXmM1SaNyKboC1ozVSiJGJ9fk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=BDbPVXF39OLBkCaf44ChkLhfEnQh5AA+aAdEPGz42TrorphDQ5B9IysAgtboJ8JpO LarM+rfzESVampW03fvqLyj2Q7M81cs7XOohi+JDio2oKLKApsINaz/ymZOjFR2D9h NHF/6csdv/BH73wIOyXxxkQglBOdBJY+UekbpuouGyNilrPqmDk003hjOAciPjm1sq jKKfbPdpjsg8m1r+fl1MXQQglbTfw4GVB7rWEpj5AZ4HFAyUU2WdJYULjiynVXgInB 0oNwIyaC8YV2YHIqvnHs7V+xoFmIUG/zdGmoNyZkAp1LBxnP58CVJsT5+RByVr3bCe AKGQGvCv5u1NA== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:43 -0800 Subject: [PATCH v2 13/35] xen/console: rename console_input_domain MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-13-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=2162; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=TjvkwSY30h8BpopVytXRbdfBD9IC9WbY4nf7jp2MPFs=; b=zeaE1xdzcz1rmGEWkbbULiMYNpdF8vIKM2kxIXRGbDkvs9GB3XLoGOpOKjhPDnOFynaL6G94y BDNF2sVTre6A39d5KuhX2puYeT9E2Bn+u1uXzBcSjf+s9GgIpAmb6ZQ X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin console_input_domain() takes an RCU lock to protect domain structure. That implies call to rcu_unlock_domain() after use. Rename console_input_domain() to rcu_lock_domain_console_owner() to highlight the need of calling rcu_unlock_domain(). Signed-off-by: Denis Mukhin --- xen/arch/arm/vpl011.c | 2 +- xen/drivers/char/console.c | 2 +- xen/include/xen/console.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c index fe36fe2bd1529a4114884580ded6d6fa55a22f0e..4d682e98553303b4a12f5cd7e5e67ab096cd7cc2 100644 --- a/xen/arch/arm/vpl011.c +++ b/xen/arch/arm/vpl011.c @@ -78,7 +78,7 @@ static void vpl011_write_data_xen(struct domain *d, uint8_t data) unsigned long flags; struct vpl011 *vpl011 = &d->arch.vpl011; struct vpl011_xen_backend *intf = vpl011->backend.xen; - struct domain *input = console_input_domain(); + struct domain *input = rcu_lock_domain_console_owner(); VPL011_LOCK(d, flags); diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 0af4b551801356f242f1770b3826608136d65653..01fcbd5581d11f8f4f2b23592255b5c744430a3e 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -477,7 +477,7 @@ static unsigned int __read_mostly console_rx = 0; #ifdef CONFIG_SBSA_VUART_CONSOLE /* Make sure to rcu_unlock_domain after use */ -struct domain *console_input_domain(void) +struct domain *rcu_lock_domain_console_owner(void) { if ( console_rx == 0 ) return NULL; diff --git a/xen/include/xen/console.h b/xen/include/xen/console.h index 6dfbade3ece36352c74f1124305da945b210f2a7..0e211e44d9703c804e18f52c9743916f8d2a9d4e 100644 --- a/xen/include/xen/console.h +++ b/xen/include/xen/console.h @@ -31,7 +31,7 @@ void console_end_sync(void); void console_start_log_everything(void); void console_end_log_everything(void); -struct domain *console_input_domain(void); +struct domain *rcu_lock_domain_console_owner(void); /* * Steal output from the console. Returns +ve identifier, else -ve error. From patchwork Fri Dec 6 04:41:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896494 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 55087E77179 for ; Fri, 6 Dec 2024 04:42:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849425.1264143 (Exim 4.92) (envelope-from ) id 1tJQA9-00083J-Qd; Fri, 06 Dec 2024 04:41:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849425.1264143; Fri, 06 Dec 2024 04:41:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQA8-0007z2-R4; Fri, 06 Dec 2024 04:41:56 +0000 Received: by outflank-mailman (input) for mailman id 849425; Fri, 06 Dec 2024 04:41:49 +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 1tJQA1-0004Kb-07 for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:49 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 630748e6-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:41 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9F06E5C730D; Fri, 6 Dec 2024 04:40:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 3FE89C4CEE4; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3203AE77175; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) 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: 630748e6-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460098; bh=Cap5cSdXQnJhIWZIJycGmw66XTO7q8HjNlh67Jy7JB4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=slEVXgrcxRMdts8sPlpZiuEnq6nMd1CJXo5dkrY+iH95kxfsnlS15QRK3taaMDw/s dPCF6+DfrrCLhxwuD3D6XopmRXmgdFB/iSP+TzFCBg/sedGESnVGWnRASO5Fso76EK NaSmqdwiVn9s2mRCzADjsbRv80BHc4iZOWzINZfusKq7300RwgQ1Zfs7+THoMEVH4P ZRd8LzFIdF59o69nF+1xazOq9dTsU8h6fUQWzOUi3rwun1X+sutRdo6TD2lWqVUHw6 Dt7Z0eHhaqMvCRyxJ3+rENlf7l3fqcrkeFnYH/8wEXAjcLZT7BjIEydTOwZgDfSl+W MElWGA+tKeDFQ== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:44 -0800 Subject: [PATCH v2 14/35] xen/console: rename switch_serial_input() to console_find_owner() MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-14-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=1478; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=kkv+AJB+iT69SEANPtdQ4jOx6o8Fe+p28DiGHObsMCE=; b=gRXgx+DD5GIcVMPVQK7C1jj92QDW/kIDm/IOc/pZCgabGTEox1asRi6IgoPghVmZ7TWS8niFN n4qeqreO2lEBoEOFAlckvn2W2tk/QOfgi/PUKW8+0xqTiyq+lSP5ZG8 X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Updated the name to highlight the logic of selection the physical console owner: existing code does not switch only serial console, it also switches video console and debugging console (debug I/O port and console hypercall). Signed-off-by: Denis Mukhin --- xen/drivers/char/console.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 01fcbd5581d11f8f4f2b23592255b5c744430a3e..f8a7db385c9525cabc69ceb1a84d73f57863aa45 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -485,7 +485,7 @@ struct domain *rcu_lock_domain_console_owner(void) } #endif -static void switch_serial_input(void) +static void console_find_owner(void) { unsigned int next_rx = console_rx; @@ -588,7 +588,7 @@ static void cf_check serial_rx(char c) /* We eat CTRL- in groups of 3 to switch console input. */ if ( ++switch_code_count == 3 ) { - switch_serial_input(); + console_find_owner(); switch_code_count = 0; } return; @@ -1128,7 +1128,7 @@ void __init console_endboot(void) "toggle host/guest log level adjustment", 0); /* Serial input is directed to DOM0 by default. */ - switch_serial_input(); + console_find_owner(); } int __init console_has(const char *device) From patchwork Fri Dec 6 04:41:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896491 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C2AE1E7717D for ; Fri, 6 Dec 2024 04:42:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849423.1264134 (Exim 4.92) (envelope-from ) id 1tJQA8-0007m1-9D; Fri, 06 Dec 2024 04:41:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849423.1264134; Fri, 06 Dec 2024 04:41:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQA7-0007hl-GP; Fri, 06 Dec 2024 04:41:55 +0000 Received: by outflank-mailman (input) for mailman id 849423; Fri, 06 Dec 2024 04:41:49 +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 1tJQA0-0004Ka-Mb for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:48 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 631ce79d-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:42 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B68855C7311; Fri, 6 Dec 2024 04:40:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 51702C4CEE1; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 469A7E77171; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) 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: 631ce79d-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460098; bh=owjhPqMN/sfHwDFdAwELQ23W67gacGzY3DCmgAbUG18=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=DLTBKB4oxMWdcE1LnVcKmfZjfrKJIOFEgEJ1YU6TUpJ3qeYzBimAOcHSF5Y0zuJk3 cvauLBWrtXW/9TNGZwEg8SHr14QqSa1+q+jRj6tt4Gexg+KYBDCYxxnuvsRCi54Nm3 MNKzuFfuXxm57lkeHvO72G3bm8U6dD5vh3n3klUHX/2R913vGc/KkcC6Z8JMiLveQr hflxbWwGj9pwzj3JZhpxZNFh2Nw30U2zleCYzIatOYhuN8D5Ux+qKwJPJeiAWawYiG cR3ux1HHjGZBMVbYyukJS1P44BHpt1Y/yobwsJx9+MGA573+zrf0FRX5L+gfc3GTYH AgjQzBjBJzH6Q== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:45 -0800 Subject: [PATCH v2 15/35] xen/console: rename console_rx to console_owner MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-15-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=3503; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=adx3ttDq9DGxs5v/iNqFG/t0SkuLKBWjA23PcHLO1+c=; b=U0p0Hzrt1FgB0xBL5A9gFP0Y7Mk23wTztAC/UqxMEAxRrYxGJSk3Xqom8dczkyZN2c2Nxokon RNRJP3sESjoB+bT52kOM2zEVS1JjKi7wpMFA62krW9kIMHww0XCdO41 X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Preparation for the follow on change to switch console_owner to domid_t address space. Signed-off-by: Denis Mukhin --- xen/drivers/char/console.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index f8a7db385c9525cabc69ceb1a84d73f57863aa45..86bf899ada8f8221ffc77bcffb1f58777a22198e 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -467,11 +467,11 @@ static void cf_check dump_console_ring_key(unsigned char key) */ #define switch_code (opt_conswitch[0]-'a'+1) /* - * console_rx=0 => input to xen - * console_rx=1 => input to dom0 (or the sole shim domain) - * console_rx=N => input to dom(N-1) + * console_owner=0 => input to xen + * console_owner=1 => input to dom0 (or the sole shim domain) + * console_owner=N => input to dom(N-1) */ -static unsigned int __read_mostly console_rx = 0; +static unsigned int __read_mostly console_owner = 0; #define max_console_rx (max_init_domid + 1) @@ -479,15 +479,15 @@ static unsigned int __read_mostly console_rx = 0; /* Make sure to rcu_unlock_domain after use */ struct domain *rcu_lock_domain_console_owner(void) { - if ( console_rx == 0 ) + if ( console_owner == 0 ) return NULL; - return rcu_lock_domain_by_id(console_rx - 1); + return rcu_lock_domain_by_id(console_owner - 1); } #endif static void console_find_owner(void) { - unsigned int next_rx = console_rx; + unsigned int next_rx = console_owner; /* * Rotate among Xen, dom0 and boot-time created domUs while skipping @@ -500,7 +500,7 @@ static void console_find_owner(void) if ( next_rx++ >= max_console_rx ) { - console_rx = 0; + console_owner = 0; printk("*** Serial input to Xen"); break; } @@ -515,7 +515,7 @@ static void console_find_owner(void) if ( d ) { rcu_unlock_domain(d); - console_rx = next_rx; + console_owner = next_rx; printk("*** Serial input to DOM%u", domid); break; } @@ -529,7 +529,7 @@ static void console_find_owner(void) static void __serial_rx(char c) { - switch ( console_rx ) + switch ( console_owner ) { case 0: return handle_keypress(c, false); @@ -552,7 +552,7 @@ static void __serial_rx(char c) #ifdef CONFIG_SBSA_VUART_CONSOLE default: { - struct domain *d = rcu_lock_domain_by_id(console_rx - 1); + struct domain *d = rcu_lock_domain_by_id(console_owner - 1); /* * If we have a properly initialized vpl011 console for the @@ -563,7 +563,7 @@ static void __serial_rx(char c) vpl011_rx_char_xen(d, c); else printk("Cannot send chars to Dom%d: no UART available\n", - console_rx - 1); + console_owner - 1); if ( d != NULL ) rcu_unlock_domain(d); @@ -1116,7 +1116,7 @@ void __init console_endboot(void) * a useful 'how to switch' message. */ if ( opt_conswitch[1] == 'x' ) - console_rx = max_console_rx; + console_owner = max_console_rx; register_keyhandler('w', dump_console_ring_key, "synchronously dump console ring buffer (dmesg)", 0); From patchwork Fri Dec 6 04:41:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 887A1E77173 for ; Fri, 6 Dec 2024 04:41:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849418.1264100 (Exim 4.92) (envelope-from ) id 1tJQA3-0006ib-N0; Fri, 06 Dec 2024 04:41:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849418.1264100; Fri, 06 Dec 2024 04:41:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQA3-0006fj-4Q; Fri, 06 Dec 2024 04:41:51 +0000 Received: by outflank-mailman (input) for mailman id 849418; Fri, 06 Dec 2024 04:41:46 +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 1tJQ9y-0004Ka-MH for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:46 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 631e1280-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:42 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C776E5C7313; Fri, 6 Dec 2024 04:40:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 680C5C4CEE2; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C123E77175; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) 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: 631e1280-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460098; bh=xTYc/Qlg0H7wze8ET4iZ+jZPU60Pxe70nfmD2bNhJJc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=HmxMoZEM1burY3Rn3ELAcCBBQCqV6gh5CTS8conK3YXZJBM2SuvqT3BYQwzx/imP4 JdbAbm3TTRVp7cNBAehwNLOXcvG0i9FhvdJ8cwPYl6+xvu+KEgJspDo5jCcw9+DqGA +xPtoAINRl2RVfHtHfFVSK5+YcKjaOszAlf4chNs2TaAONwcn7C9zM3amQtuu+5xs2 KpbAmhuhPVNdt/wUoJljwjkzp7jY3r6YEdyMsDlE9yJS2opANb2Y81Y32je1VzD3XN W1NnfFb5NBfCyyjCqeRtYIJ7vQGZGxxTIvcXj90RNxabz0NSpflhPq5+uTd1vgJ9KF S6eZvc8UU2JNg== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:46 -0800 Subject: [PATCH v2 16/35] xen/console: introduce printk_common() MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-16-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=2804; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=0ZbhB6X3j//rZlvA+RHGboOQv/T4QXzBiywEl761Zm0=; b=mvzE8dnFdKifjiI0dNonuR4BBXjCK1QgfdIVHGd90YVxQ4pyP2joNBy5YkM/E0s0jgY0pCc59 ZutJT2tuuA5B0gthGeK0qfNuZBTsquHOQi7NQWwUpYzKUjR3VI2XKEp X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Introduce new printk() variant for convenient printouts which skip '(XEN)' prefix on xen console. This is needed for the case when physical console is owned by a domain w/ in-hypervisor UART emulation enabled. Signed-off-by: Denis Mukhin --- automation/eclair_analysis/ECLAIR/deviations.ecl | 2 +- xen/drivers/char/console.c | 8 ++++++++ xen/include/xen/lib.h | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl index 2f58f292036e3561118ce9664a92756b1b938739..c59d075262e9e6618ea2a2d27611a537ded3a776 100644 --- a/automation/eclair_analysis/ECLAIR/deviations.ecl +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl @@ -522,7 +522,7 @@ safe." -config=MC3R1.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(^.*printf\\(.*\\)$)))"} -config=MC3R1.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(name(panic)&&kind(function))))"} -config=MC3R1.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(name(elf_call_log_callback)&&kind(function))))"} --config=MC3R1.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(name(vprintk_common)&&kind(function))))"} +-config=MC3R1.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(name(^v?printk_common)&&kind(function))))"} -config=MC3R1.R17.1,macros+={hide , "^va_(arg|start|copy|end)$"} -doc_end diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 86bf899ada8f8221ffc77bcffb1f58777a22198e..f034ce5aab3f3bf59b0df9fa583ee9ce32dbf665 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -968,6 +968,14 @@ void printk(const char *fmt, ...) va_end(args); } +void printk_common(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintk_common("", fmt, args); + va_end(args); +} + void guest_printk(const struct domain *d, const char *fmt, ...) { va_list args; diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h index 81b722ea3e801e9089aaf8758249feb3a758c4f7..8a7ff2e8af9089796ff28ef8d01c00e9845782ca 100644 --- a/xen/include/xen/lib.h +++ b/xen/include/xen/lib.h @@ -61,6 +61,9 @@ debugtrace_printk(const char *fmt, ...) {} extern void printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2), cold)); +extern void printk_common(const char *fmt, ...) + __attribute__ ((format (printf, 1, 2))); + #define printk_once(fmt, args...) \ ({ \ static bool __read_mostly once_; \ From patchwork Fri Dec 6 04:41:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896499 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7AC27E77173 for ; Fri, 6 Dec 2024 04:50:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849559.1264214 (Exim 4.92) (envelope-from ) id 1tJQIn-0000PH-Pa; Fri, 06 Dec 2024 04:50:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849559.1264214; Fri, 06 Dec 2024 04:50:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQIn-0000PA-Me; Fri, 06 Dec 2024 04:50:53 +0000 Received: by outflank-mailman (input) for mailman id 849559; Fri, 06 Dec 2024 04:50:53 +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 1tJQA3-0004Kb-0L for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:51 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 631cddf8-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:42 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D8A8B5C7314; Fri, 6 Dec 2024 04:40:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 7917CC4CEE3; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70AFAE77173; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) 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: 631cddf8-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460098; bh=VfxhkDTfiR4LTXzGz0uTAKeAy5NNBjyHiibYeZqaqmE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=fNb4aYvZhcL1WRoi5y/2Vn2DQM91di4kthUq+ulgmgme60LJZfKOqyq6i0c5XaTRP sqNSIxqti4kqnSD8+DvL9iRMxXL9k0WBX0YeM7Q31UlUcu//vHnZeuIABS9jZrnpN3 enxv9dFpzZ1MPRbjy6Dn8w1djRfaFSRTL0BIaH28UIeLw30USI7NA/aTm3yAdj1b2v ceH8jWb2K5lu2qrt2YD626y+3/vfWRgO0CgYzWOI/p0d9XZA1pJhyMkUujCK+EK1TH QLwMiwLaumBD/v2r1Zt2XsFdviHVNPnU5icOOh+wO8vGKBk09W3BmEc+0E6NiUlYJI NB+Ftmx2yopqA== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:47 -0800 Subject: [PATCH v2 17/35] xen/console: introduce consoled_is_enabled() MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-17-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=4454; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=xhuHq6Qjuj4L9zlqilD/J1w4YyMosaifg1eUidT/6sY=; b=M3vrUCaT7Fshofkz23ivWXpzsFNrw5I6pGc14oCE9mPf6+CxOMss7QO9J5jIdUoJl7errU366 uw7W0G+g9R3Cll7yHkk1J6d3Myf566U/qHlna4OTq3D3KwwW1iMVJlC X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin There are few places which check pv_shim console under CONFIG_PV_SHIM in xen console driver. Instead of #ifdef-ing, use new consoled_is_enabled() to customize the logic. Header file now can be included w/o CONFIG_X86. Signature of consoled_guest_{rx,tx} has changed to account for follow-on console switch logic cleanup. Signed-off-by: Denis Mukhin --- xen/drivers/char/console.c | 10 +++------- xen/drivers/char/consoled.c | 18 ++++++++++++++---- xen/include/xen/consoled.h | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index f034ce5aab3f3bf59b0df9fa583ee9ce32dbf665..60c055396b697869b04b9132b0dcfa832fabe932 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -33,9 +33,9 @@ #include #include #include +#include #ifdef CONFIG_X86 -#include #include #endif #ifdef CONFIG_SBSA_VUART_CONSOLE @@ -505,11 +505,9 @@ static void console_find_owner(void) break; } -#ifdef CONFIG_PV_SHIM - if ( next_rx == 1 ) + if ( consoled_is_enabled() && next_rx == 1 ) domid = get_initial_domain_id(); else -#endif domid = next_rx - 1; d = rcu_lock_domain_by_id(domid); if ( d ) @@ -573,10 +571,8 @@ static void __serial_rx(char c) #endif } -#ifdef CONFIG_X86 - if ( pv_shim && pv_console ) + if ( consoled_is_enabled() ) consoled_guest_tx(c); -#endif } static void cf_check serial_rx(char c) diff --git a/xen/drivers/char/consoled.c b/xen/drivers/char/consoled.c index b415b632cecc0a80e161b701d7b70ba4f3cc5fb8..d6624e7697f56e1a1959b0efa5dca104f34af002 100644 --- a/xen/drivers/char/consoled.c +++ b/xen/drivers/char/consoled.c @@ -43,13 +43,13 @@ struct xencons_interface *consoled_get_ring_addr(void) static char buf[BUF_SZ + 1]; /* Receives characters from a domain's PV console */ -void consoled_guest_rx(void) +int consoled_guest_rx(void) { size_t idx = 0; XENCONS_RING_IDX cons, prod; if ( !cons_ring ) - return; + return 0; spin_lock(&rx_lock); @@ -91,15 +91,17 @@ void consoled_guest_rx(void) out: spin_unlock(&rx_lock); + + return 0; } /* Sends a character into a domain's PV console */ -void consoled_guest_tx(char c) +int consoled_guest_tx(char c) { XENCONS_RING_IDX cons, prod; if ( !cons_ring ) - return; + return 0; cons = ACCESS_ONCE(cons_ring->in_cons); prod = cons_ring->in_prod; @@ -118,6 +120,7 @@ void consoled_guest_tx(char c) cons_ring->in[MASK_XENCONS_IDX(prod++, cons_ring->in)] = c; + /* Write to the ring before updating the pointer */ smp_wmb(); ACCESS_ONCE(cons_ring->in_prod) = prod; @@ -125,6 +128,13 @@ void consoled_guest_tx(char c) notify: /* Always notify the guest: prevents receive path from getting stuck. */ pv_shim_inject_evtchn(pv_console_evtchn()); + + return 0; +} + +bool consoled_is_enabled(void) +{ + return pv_shim && pv_console; } /* diff --git a/xen/include/xen/consoled.h b/xen/include/xen/consoled.h index bd7ab6329ee8a7c466484021247241ded8ed03c7..696677fa5a3be458a0ec93360e08376c3471f95b 100644 --- a/xen/include/xen/consoled.h +++ b/xen/include/xen/consoled.h @@ -3,10 +3,41 @@ #include +#if defined(CONFIG_PV_SHIM) + void consoled_set_ring_addr(struct xencons_interface *ring); struct xencons_interface *consoled_get_ring_addr(void); -void consoled_guest_rx(void); -void consoled_guest_tx(char c); +int consoled_guest_rx(void); +int consoled_guest_tx(char c); +bool consoled_is_enabled(void); + +#else + +static inline void consoled_set_ring_addr(struct xencons_interface *ring) +{ +} + +static inline struct xencons_interface *consoled_get_ring_addr(void) +{ + return NULL; +} + +static inline int consoled_guest_rx(void) +{ + return 0; +} + +static inline int consoled_guest_tx(char c) +{ + return 0; +} + +static inline bool consoled_is_enabled(void) +{ + return false; +} + +#endif /* #if defined(CONFIG_PV_SHIM) */ #endif /* __XEN_CONSOLED_H__ */ /* From patchwork Fri Dec 6 04:41:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896496 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C94ADE7717B for ; Fri, 6 Dec 2024 04:42:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849426.1264150 (Exim 4.92) (envelope-from ) id 1tJQAB-0008Oa-OF; Fri, 06 Dec 2024 04:41:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849426.1264150; Fri, 06 Dec 2024 04:41:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQAA-0008LS-Jx; Fri, 06 Dec 2024 04:41:58 +0000 Received: by outflank-mailman (input) for mailman id 849426; Fri, 06 Dec 2024 04:41:49 +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 1tJQA1-0004Ka-Mg for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:49 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 634e9c37-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:42 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E84FD5C7316; Fri, 6 Dec 2024 04:40:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 88145C4CED1; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E850E77171; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) 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: 634e9c37-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460098; bh=1+CfSEkR8zxLHnRjqs6FthJiLe4CA0nTnQb0fq6KDB8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=mOcVJpk4N5JHbTIyQQM8RLgj5RcdtbYqIFONH8W+JhIioNg9ggVz6vQn60b1I24H+ zJQzrY1JeyR8kb7iDNydGZZZyXM0zrZo4Z/v7FCa/YLOtHLtmN+74nG6wgrsLKZoKL YOWUr/TWWSxcLbTCoE/zctSUS+zkxY8bQ1bGEkGNwfdPKVnaZsukpxcd5+RBRUJJ+G G6eTtn/+DTVdbxcMbhcAz28RcFptGq/kgILDn+UleKb5teBht70HcGRbKTrzZyHEv2 y1tGL2n/9Gzv0kzSHHUVNIVEfiK1ZcOqTXr6VYEWlLgZO3MDLyFj+iseYCtMHwql6I xIkYJL4STxTQw== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:48 -0800 Subject: [PATCH v2 18/35] xen/console: introduce use of 'is_console' flag MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-18-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=4575; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=c1qncLIbvdXkIva3csVS48o24QoMrU3zNKu5KbZwS0s=; b=WG1ksIYw4EgMLqSvIv9tHZhu+lH3WcqfWVayi+nfHijfuS+xnIvMui9g5p5iudJvKLVyMnVUq PSoDBtHWfQ7CsaFONJoLb62ddxjajRWzEKEVzmeJCrzkAq7eNAreWBp X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin The code now inspects d->is_console flag to decide whether the console focus should move to the domain w/ console after administrator presses . Console owner domain switch logic updated accordingly. Signed-off-by: Denis Mukhin --- xen/arch/arm/dom0less-build.c | 2 +- xen/arch/arm/domain.c | 1 + xen/arch/arm/domctl.c | 1 + xen/arch/x86/pv/shim.c | 2 ++ xen/common/domain.c | 2 ++ xen/drivers/char/console.c | 14 ++++++++++---- 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index de64ee930fdfe9a1c2842761275641485f69f675..32b5e8e16a28ae9a4951c8b7815638e69b66406a 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -833,6 +833,7 @@ static int __init construct_domU(struct domain *d, return rc; d->arch.emulation_flags |= ARM_EMU_VUART; + d->is_console = true; } rc = prepare_dtb_domU(d, &kinfo); @@ -1015,7 +1016,6 @@ void __init create_domUs(void) panic("Error creating domain %s (rc = %ld)\n", dt_node_name(node), PTR_ERR(d)); - d->is_console = true; dt_device_set_used_by(node, d->domain_id); rc = construct_domU(d, node); diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 02f9d59b38b4b7f6f73d97c421c9948c90e681d5..c52d6e932a9a71b620ecefacc1e884338858e3ea 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -781,6 +781,7 @@ int arch_domain_create(struct domain *d, goto fail; d->arch.emulation_flags |= ARM_EMU_VUART; + d->is_console = true; } if ( (rc = domain_vpci_init(d)) != 0 ) diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c index f80d34bf5f3d323a15db7f032073be52ea1009ae..81b5caf17c4e0badb2eefa90b1522c107f844d06 100644 --- a/xen/arch/arm/domctl.c +++ b/xen/arch/arm/domctl.c @@ -46,6 +46,7 @@ static int handle_vuart_init(struct domain *d, { vuart_op->evtchn = info.evtchn; d->arch.emulation_flags |= ARM_EMU_VUART; + d->is_console = true; } return rc; diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c index 17cb30620290c76cf42251f70cfa4199c0e165d1..a55c1d2a1e616f8979677a198eb9caabc3afc6bf 100644 --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -238,6 +238,8 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start, * guest from depleting the shim memory pool. */ d->max_pages = domain_tot_pages(d); + + d->is_console = true; } static void write_start_info(struct domain *d) diff --git a/xen/common/domain.c b/xen/common/domain.c index 9e57dd4122a726e2fb42efe9c029e775202be0e6..aab546c0a8535e4f007cbbc9c5c552bcf66b5807 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -682,6 +682,8 @@ struct domain *domain_create(domid_t domid, old_hwdom = hardware_domain; hardware_domain = d; + + d->is_console = true; } TRACE_TIME(TRC_DOM0_DOM_ADD, d->domain_id); diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 60c055396b697869b04b9132b0dcfa832fabe932..8cbac54c66044ae8581e486a782102b75c8bfaa9 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -1,8 +1,8 @@ /****************************************************************************** * console.c - * + * * Emergency console I/O for Xen and the domain-0 guest OS. - * + * * Copyright (c) 2002-2004, K A Fraser. * * Added printf_ratelimit @@ -509,14 +509,20 @@ static void console_find_owner(void) domid = get_initial_domain_id(); else domid = next_rx - 1; + d = rcu_lock_domain_by_id(domid); - if ( d ) + if ( d == NULL ) + continue; + + if ( d->is_console ) { rcu_unlock_domain(d); console_owner = next_rx; printk("*** Serial input to DOM%u", domid); break; } + + rcu_unlock_domain(d); } if ( switch_code ) @@ -814,7 +820,7 @@ static int printk_prefix_check(char *p, char **pp) return ((atomic_read(&print_everything) != 0) || (loglvl < lower_thresh) || ((loglvl < upper_thresh) && printk_ratelimit())); -} +} static int cf_check parse_console_timestamps(const char *s) { From patchwork Fri Dec 6 04:41:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896506 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 04D82E77173 for ; Fri, 6 Dec 2024 04:56:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849686.1264285 (Exim 4.92) (envelope-from ) id 1tJQOa-0005Xd-27; Fri, 06 Dec 2024 04:56:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849686.1264285; Fri, 06 Dec 2024 04:56:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQOZ-0005XW-V0; Fri, 06 Dec 2024 04:56:51 +0000 Received: by outflank-mailman (input) for mailman id 849686; Fri, 06 Dec 2024 04:56:50 +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 1tJQA4-0004Kb-0M for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:52 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [2604:1380:4641:c500::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 634d5860-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:42 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 077005C7318; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 995A9C4CEDE; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FF5CE77173; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) 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: 634d5860-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460098; bh=Msd9ALOQsKWgqYjqZp3vEbU4YxKp+IL/6j5doF/TX4s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=X+rwlw/Zhai565ag9BYuM8ARm2DmW+qeIP0rEQDoOGMhV8nJZiXDotnvEi2++uIOv tIZVZeOY8vKJou4RWDXs6BDXUHTYW/wiaDpDWvqEhJtJ+tcbs5dl0Hn/SxL1DMXWx6 mT9SrdjkqUkGBqZtgwS5Lw5L5MaFD5MQrqvzgInx43ChGbWJzE0Qemtll4RsmutM9g fuPkDIIyCU5D9dh+XvlrNsFgSzL8yN71Xt6F5GUUURgqUT18KBmJdLY3cLMsyo7F6Y QRWBJ7c4h+zrWvJXpzuthPGUaGfrc1nCNpPPOSdTmkil9QBGNbrA+0JuQTtBs1qp09 FQfBt7I9O/AGw== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:49 -0800 Subject: [PATCH v2 19/35] xen/console: introduce console_set_owner() MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-19-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=6105; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=LaoLtTtPVB803Wx66ywoNWCuGefL+9P7BcXWkOi4Ttw=; b=qIUuqjar9jBz7vlbvZO91eK5QZyrPGkyZdxoOW+bK/PhH1tCuhvcar4R2tTKQ6B0C7F6lxM93 WMCmcpor8byDDi3SZubIYvLxdlI1nk8JsNjv/6WTA/rYizZqV4c2rlQ X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin console_set_owner() is introduced for setting the new console owner. Switches console owner to domain ID vs range of integer numbers mapped to domain IDs. This a public API to console driver, will be used in the follow on code change. Signed-off-by: Denis Mukhin --- xen/drivers/char/console.c | 122 ++++++++++++++++++++++++++------------------- xen/include/xen/console.h | 1 + 2 files changed, 71 insertions(+), 52 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 8cbac54c66044ae8581e486a782102b75c8bfaa9..52cf64dbf6fd18d599cb88835d03501a23b3e3c4 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -463,82 +463,100 @@ static void cf_check dump_console_ring_key(unsigned char key) /* * CTRL- changes input direction, rotating among Xen, Dom0, - * and the DomUs started from Xen at boot. + * and the DomUs. */ #define switch_code (opt_conswitch[0]-'a'+1) + /* - * console_owner=0 => input to xen - * console_owner=1 => input to dom0 (or the sole shim domain) - * console_owner=N => input to dom(N-1) + * Current console owner domain ID: either Xen or domain w/ d->is_console == + * true. + * + * Initialized in console_endboot(). */ -static unsigned int __read_mostly console_owner = 0; +static domid_t __read_mostly console_owner; -#define max_console_rx (max_init_domid + 1) +static struct domain *rcu_lock_domain_console_by_id(domid_t domid) +{ + struct domain *d; + + d = rcu_lock_domain_by_id(domid); + + if ( d == NULL ) + return NULL; + + if ( d->is_console ) + return d; + + rcu_unlock_domain(d); + + return NULL; +} -#ifdef CONFIG_SBSA_VUART_CONSOLE /* Make sure to rcu_unlock_domain after use */ struct domain *rcu_lock_domain_console_owner(void) { - if ( console_owner == 0 ) - return NULL; - return rcu_lock_domain_by_id(console_owner - 1); + return rcu_lock_domain_console_by_id(console_owner); } -#endif -static void console_find_owner(void) +static bool console_owner_possible(domid_t domid) { - unsigned int next_rx = console_owner; - - /* - * Rotate among Xen, dom0 and boot-time created domUs while skipping - * switching serial input to non existing domains. - */ - for ( ; ; ) - { - domid_t domid; - struct domain *d; - - if ( next_rx++ >= max_console_rx ) - { - console_owner = 0; - printk("*** Serial input to Xen"); - break; - } - - if ( consoled_is_enabled() && next_rx == 1 ) - domid = get_initial_domain_id(); - else - domid = next_rx - 1; - - d = rcu_lock_domain_by_id(domid); - if ( d == NULL ) - continue; - - if ( d->is_console ) - { - rcu_unlock_domain(d); - console_owner = next_rx; - printk("*** Serial input to DOM%u", domid); - break; - } + struct domain *d; + d = rcu_lock_domain_console_by_id(domid); + if ( d != NULL ) rcu_unlock_domain(d); - } + + return d != NULL; +} + +int console_set_owner(domid_t domid) +{ + if ( domid == DOMID_XEN ) + printk("*** Serial input to Xen"); + else if ( console_owner_possible(domid) ) + printk("*** Serial input to DOM%u", domid); + else + return -ENOENT; + + console_owner = domid; if ( switch_code ) printk(" (type 'CTRL-%c' three times to switch input)", opt_conswitch[0]); printk("\n"); + + return 0; +} + +/* + * Switch console input focus. + * Rotates input focus among Xen, dom0 and boot-time created domUs while + * skipping switching serial input to non existing domains. + */ +static void console_find_owner(void) +{ + domid_t i, n = max_init_domid + 1; + + if ( console_owner == DOMID_XEN ) + i = get_initial_domain_id(); + else + i = console_owner + 1; + + for ( ; i < n; i++ ) + if ( !console_set_owner(i) ) + break; + if ( i == n ) + console_set_owner(DOMID_XEN); } static void __serial_rx(char c) { switch ( console_owner ) { - case 0: + case DOMID_XEN: return handle_keypress(c, false); - case 1: + case 0: /* * Deliver input to the hardware domain buffer, unless it is * already full. @@ -556,7 +574,7 @@ static void __serial_rx(char c) #ifdef CONFIG_SBSA_VUART_CONSOLE default: { - struct domain *d = rcu_lock_domain_by_id(console_owner - 1); + struct domain *d = rcu_lock_domain_by_id(console_owner); /* * If we have a properly initialized vpl011 console for the @@ -567,7 +585,7 @@ static void __serial_rx(char c) vpl011_rx_char_xen(d, c); else printk("Cannot send chars to Dom%d: no UART available\n", - console_owner - 1); + console_owner); if ( d != NULL ) rcu_unlock_domain(d); @@ -1126,7 +1144,7 @@ void __init console_endboot(void) * a useful 'how to switch' message. */ if ( opt_conswitch[1] == 'x' ) - console_owner = max_console_rx; + console_owner = DOMID_XEN; register_keyhandler('w', dump_console_ring_key, "synchronously dump console ring buffer (dmesg)", 0); diff --git a/xen/include/xen/console.h b/xen/include/xen/console.h index 0e211e44d9703c804e18f52c9743916f8d2a9d4e..57c482cfbf2da15b011e64841ea086e779f4588d 100644 --- a/xen/include/xen/console.h +++ b/xen/include/xen/console.h @@ -32,6 +32,7 @@ void console_start_log_everything(void); void console_end_log_everything(void); struct domain *rcu_lock_domain_console_owner(void); +int console_set_owner(domid_t); /* * Steal output from the console. Returns +ve identifier, else -ve error. From patchwork Fri Dec 6 04:41:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896478 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9DEB9C3DA4A for ; Fri, 6 Dec 2024 04:41:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849420.1264115 (Exim 4.92) (envelope-from ) id 1tJQA5-0007IH-QD; Fri, 06 Dec 2024 04:41:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849420.1264115; Fri, 06 Dec 2024 04:41:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQA5-0007DH-Gg; Fri, 06 Dec 2024 04:41:53 +0000 Received: by outflank-mailman (input) for mailman id 849420; Fri, 06 Dec 2024 04:41:47 +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 1tJQ9z-0004Ka-MQ for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:47 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [2604:1380:4641:c500::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 63b0a2cb-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:42 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 118C75C731A; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id A5D68C4CEE1; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D9D6E77179; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) 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: 63b0a2cb-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460098; bh=70k9tJWzxtakueDep8Z1r6BQFS566Fm/qs8rAVna/Is=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=c3NdRxrqCvEV62tN4hsqcZTPtfE4RgPlSdoCGonfz9cV69ojSBT7UTIyUqG8hMLmd bB8Uc1ysYXJ/7jzaDCATOfCzpx9ro8LPrB5HyMMFDbrdeI0Aw6sZETaWukcjpJfpIO ZLBOiRdyT2bpKNpDgjsIWLnd2Nmoi0z4yR02dCqEFeuUbQ9HoDfOj4T48frmIAOiS5 2CChhNXhld9o1KwZMY8NEH3Mb0hpKUfF6HzIpeviE99HAO5kB8of9BL0dIV8XZHgpZ oOLyCiOgwHWjB9SYKnvkagRo92j4V3nfzrX00ocJ4aetS2wwm36ebvUHy7sCv6YyVk 5CIGZwm0Goyfw== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:50 -0800 Subject: [PATCH v2 20/35] xen/console: introduce console_owner_domid() MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-20-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=1498; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=B93paIiJy8o1DGD2n2g3KcZoYn4UUAYMMgdZEki+Vh4=; b=Knkc/GPlePCDp77YoynQwfl3vAq4MXPN4bGfSacAecxhgdGewN2VzhLvq78O/rqeOAPhPSSP+ d4gtAVUmJSEDCqv/TzQSACQbYlZC+3mE3ziOkjv6lNWXlNd0dODNmWy X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin console_owner_domid() is introduced to obtain the "console owner" domain ID. The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix. Signed-off-by: Denis Mukhin Reviewed-by: Jason Andryuk --- xen/drivers/char/console.c | 5 +++++ xen/include/xen/console.h | 1 + 2 files changed, 6 insertions(+) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 52cf64dbf6fd18d599cb88835d03501a23b3e3c4..a8ab5c2bcb98e4cadf9ad2c9ad28d297977d0557 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -498,6 +498,11 @@ struct domain *rcu_lock_domain_console_owner(void) return rcu_lock_domain_console_by_id(console_owner); } +domid_t console_owner_domid(void) +{ + return console_owner; +} + static bool console_owner_possible(domid_t domid) { struct domain *d; diff --git a/xen/include/xen/console.h b/xen/include/xen/console.h index 57c482cfbf2da15b011e64841ea086e779f4588d..83be5794aff6630beaad46f910fcc0fc6d833808 100644 --- a/xen/include/xen/console.h +++ b/xen/include/xen/console.h @@ -33,6 +33,7 @@ void console_end_log_everything(void); struct domain *rcu_lock_domain_console_owner(void); int console_set_owner(domid_t); +domid_t console_owner_domid(void); /* * Steal output from the console. Returns +ve identifier, else -ve error. From patchwork Fri Dec 6 04:41:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896512 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 90AB7E7717B for ; Fri, 6 Dec 2024 05:01:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849774.1264344 (Exim 4.92) (envelope-from ) id 1tJQT6-0002ct-PN; Fri, 06 Dec 2024 05:01:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849774.1264344; Fri, 06 Dec 2024 05:01:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQT6-0002cg-Lq; Fri, 06 Dec 2024 05:01:32 +0000 Received: by outflank-mailman (input) for mailman id 849774; Fri, 06 Dec 2024 05:01:31 +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 1tJQA5-0004Ka-N8 for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:53 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 63c4dfa4-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:43 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 21D635C731C; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id B770CC4CEE4; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADBAEE77175; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) 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: 63c4dfa4-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460098; bh=xN3Qk4AnkavJDz1+2oRzOsxhatlUANXuldhRbnVqaL0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=WuYwP5N6FRVi49Tvc8z9O/76ioaUpi/FZQBJuMRGDB+GTX2VceyVOCu8rPyGBR9BJ Oc6LrY1JRMML+ctUVgOXz6zrZlPrbcvalDD+qBZGcAGzG/2luW3je+hPqXh2k02o2z YQ7HuB/3Ww2fsvyjPNmOm++JScVRUe0EUm5VJoRK7WZVH45B66YCLescgZHWO+B0ph f1aA8/e1LbT9z1wYmvG0kem2XXv9tpqFZ8J0KYmh8KtFUav8gHDOvgTkvtjsuMaduG 5BlvCSCLrHlqbO+6whey6fmCI1ci/YwN9wpp6ZFAzGacJHjCscL0md3noT+4DXQVNC fmeyoSd8P6+lQ== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:51 -0800 Subject: [PATCH v2 21/35] xen/console: introduce console_init_owner() MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-21-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=1949; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=9IHMF1BdeViUoT1r1xwy88EM2J39hJxCdMpf6FUj+oc=; b=rkPuVSjKM6PdcjQpqYx04yf5XSLLo6WwLxCVOm3Xp526geyD7FoALVxOn/SqrCa9cjSfLb+QZ qW8+QGL4+VvD3kA/ow2AsW8esC9XvQRMDoI/h0TfmZ1MW76KHXfU+fc X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin console_init_owner() is introduced for selecting the boot-time console owner. Signed-off-by: Denis Mukhin Reviewed-by: Jason Andryuk --- xen/drivers/char/console.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index a8ab5c2bcb98e4cadf9ad2c9ad28d297977d0557..6261bdb5a2ac1075bc89fa408c0fd6cfef380ae6 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -554,6 +554,22 @@ static void console_find_owner(void) console_set_owner(DOMID_XEN); } +static void console_init_owner(void) +{ + domid_t domid; + + /* + * If user specifies so, we fool the switch routine to redirect input + * straight back to Xen. + */ + if ( opt_conswitch[1] == 'x' ) + domid = DOMID_XEN; + else + domid = get_initial_domain_id(); + + console_set_owner(domid); +} + static void __serial_rx(char c) { switch ( console_owner ) @@ -1143,14 +1159,6 @@ void __init console_endboot(void) video_endboot(); - /* - * If user specifies so, we fool the switch routine to redirect input - * straight back to Xen. I use this convoluted method so we still print - * a useful 'how to switch' message. - */ - if ( opt_conswitch[1] == 'x' ) - console_owner = DOMID_XEN; - register_keyhandler('w', dump_console_ring_key, "synchronously dump console ring buffer (dmesg)", 0); register_irq_keyhandler('+', &do_inc_thresh, @@ -1160,8 +1168,7 @@ void __init console_endboot(void) register_irq_keyhandler('G', &do_toggle_guest, "toggle host/guest log level adjustment", 0); - /* Serial input is directed to DOM0 by default. */ - console_find_owner(); + console_init_owner(); } int __init console_has(const char *device) From patchwork Fri Dec 6 04:41:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896500 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F9D1E77173 for ; Fri, 6 Dec 2024 04:51:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849574.1264224 (Exim 4.92) (envelope-from ) id 1tJQJD-00011K-11; Fri, 06 Dec 2024 04:51:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849574.1264224; Fri, 06 Dec 2024 04:51: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 1tJQJC-00011D-Uf; Fri, 06 Dec 2024 04:51:18 +0000 Received: by outflank-mailman (input) for mailman id 849574; Fri, 06 Dec 2024 04:51:17 +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 1tJQA2-0004Ka-Mj for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:50 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [2604:1380:4641:c500::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 64042d93-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:42 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 2B98C5C731E; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id C1AD2C4CEE3; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC688E77173; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) 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: 64042d93-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460098; bh=veV7CIvzm41wMp2I++KuzZXz6Dndb+ahoqqMyVD1SYk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=hZTS+FIs6hRZT6n7ePbupewCgCGWvHLzGBsxXoqKjFHNtPVV+uUthUW166T4EKCwp oa36bOKHyxxHG0qkF4ahxl10NOheu6W/wN0XwKFEeMnWYVYNKQuDpSrqRtUUYTMYk3 c45M3cThzdQwXBgFxK6Zt6d1S9yaZKZmnHErA+ltwvuKPajEokq8ROZGaRbxlZObfR ysqQwqGZQueyFq8ptU/PZvjNlyWeVKFT7uxNSXWVw3990flDly05RCiD4pJT2PlBEP Ala+FDE+cTe4Wk8qK8lsd8a6xjCZd69FD5fyEgruUZdd+gk5zmxUf/5BkecXJX6bE7 bQjFS8KDGB5yA== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:52 -0800 Subject: [PATCH v2 22/35] xen/console: introduce handle_keypress_in_domain() MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-22-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=3261; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=4Oy6tSy4ntedYhToxhGSrQwpwAn7T/tf6/puha/ackI=; b=SIjDO2ws3eUPEyBeLQ5QQZasuvP/vMSYzru4/T8IBkGlLwzyl1Bg1uoR7rFhT+sbGwXgUo04+ zxn9LrrwYdHAnc0oTPGSzkubS8ZnaOVnYA38M7BnDrd3OcReHl/I/5H X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin With introduction of NS8250 emulator for x86, the logic of switching console focus gets more convoluted: HVM domain w/ NS8205 must be able to receive the physical console input for guest VM debugging. Also, existing code does not honor `hardware_dom=` xen command line parameter (hardware domain ID does _not_ necessarily starts from 0). Introduce handle_keypress_in_domain() to account for all scenarios of console input forwarding. Signed-off-by: Denis Mukhin --- xen/drivers/char/console.c | 72 +++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 6261bdb5a2ac1075bc89fa408c0fd6cfef380ae6..ce3639a4cdcda00ea63e3bf119bc3b242cbfdf6a 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -570,14 +570,16 @@ static void console_init_owner(void) console_set_owner(domid); } -static void __serial_rx(char c) +static void handle_keypress_in_domain(struct domain *d, char c) { - switch ( console_owner ) - { - case DOMID_XEN: - return handle_keypress(c, false); + int rc = 0; - case 0: + /* + * Deliver input to the hardware domain buffer. + * NB: must be the first check: hardware domain may have emulated UART. + */ + if ( d == hardware_domain ) + { /* * Deliver input to the hardware domain buffer, unless it is * already full. @@ -590,34 +592,44 @@ static void __serial_rx(char c) * getting stuck. */ send_global_virq(VIRQ_CONSOLE); - break; - -#ifdef CONFIG_SBSA_VUART_CONSOLE - default: - { - struct domain *d = rcu_lock_domain_by_id(console_owner); - - /* - * If we have a properly initialized vpl011 console for the - * domain, without a full PV ring to Dom0 (in that case input - * comes from the PV ring), then send the character to it. - */ - if ( d != NULL ) - vpl011_rx_char_xen(d, c); - else - printk("Cannot send chars to Dom%d: no UART available\n", - console_owner); - - if ( d != NULL ) - rcu_unlock_domain(d); - - break; } + /* + * Deliver input to the emulated UART. + */ + else if ( domain_has_vuart(d) ) + { +#if defined(CONFIG_SBSA_VUART_CONSOLE) + rc = vpl011_rx_char_xen(d, c); #endif } - + /* + * Deliver input to the PV shim console. + */ if ( consoled_is_enabled() ) - consoled_guest_tx(c); + rc = consoled_guest_tx(c); + + if ( rc && rc != -ENODEV ) + printk(KERN_WARNING "console input domain %d: not ready: %d\n", + d->domain_id, rc); +} + +static void __serial_rx(char c) +{ + struct domain *d; + + if ( console_owner == DOMID_XEN ) + { + handle_keypress(c, false); + return; + } + + d = rcu_lock_domain_console_owner(); + if ( d == NULL ) + return; + + handle_keypress_in_domain(d, c); + + rcu_unlock_domain(d); } static void cf_check serial_rx(char c) From patchwork Fri Dec 6 04:41:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896511 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5CCF7E77179 for ; Fri, 6 Dec 2024 05:01:35 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849771.1264335 (Exim 4.92) (envelope-from ) id 1tJQT4-0002MQ-IW; Fri, 06 Dec 2024 05:01:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849771.1264335; Fri, 06 Dec 2024 05:01:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQT4-0002MJ-Fg; Fri, 06 Dec 2024 05:01:30 +0000 Received: by outflank-mailman (input) for mailman id 849771; Fri, 06 Dec 2024 05:01:28 +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 1tJQA8-0004Ka-No for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:56 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 64187365-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:43 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 3C87F5C7320; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id D3109C4CEE0; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCB59E77171; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) 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: 64187365-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460098; bh=eiE+Vk1+xwNQSS5lGvaUqRJncjb6mebSOM3N939URVI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=d7BCDKwQXwZ4cbD1bFWhjDN/m+kXVWns99wYk96kr3EEL6V5TOfihPPg1zdjHjzYE hbhg3UGCriGtvZwt73RW5evUKX2XjkeYiDqjSa/hWTbaza3FSVSlasA/bLG4ECCjuR 3C71xULHuxVorDFC9FXMO9uOOpM6Msregplpkrb71Kd9Nus2tuNTqYwGJmq6ZN6n9s N6tfJBP8EvviPMtZ0KcOpzCVI6F73bO3nHt3c2tH/jVHmCMD+A4rAjTZ+nvbT5VHxt XhxI6AQayVJ5sIuSPZsArLR72nEYNXrHvpPYAepN2BrXFBJmh+6eiRau/op/7QioEa 9ZzR5RMXS6d3A== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:53 -0800 Subject: [PATCH v2 23/35] xen/console: introduce console_write() MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-23-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=5090; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=IJndR90ln3ebR9JBLgcF8uZuUsxgXYKVX60Wdeeyfgg=; b=jHyeiWGUT3FC9wqdvmDyFZNzJI9ClfZ3Imp+FXv2XyaFHnvRcCAdBiVl5YgFppU5q80Nh4ylX 0lCDMsThybKD8ezbX7OiCuZe8c8k5/af+wQnUOUAs2dL7Iq58CX25YI X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin PV Linux kernel uses HYPERVISOR_console_io hypercall for early console which ends up being handled by Xen's console driver's guest_console_write(). guest_console_write() duplicates the code from __putstr(), elimitate code duplication. Signed-off-by: Denis Mukhin --- xen/drivers/char/console.c | 97 +++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index ce3639a4cdcda00ea63e3bf119bc3b242cbfdf6a..115967d179998cba4a81578caba09db4e4aca7f7 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -63,6 +63,8 @@ static const char __initconst warning_sync_console[] = "However it can introduce SIGNIFICANT latencies and affect\n" "timekeeping. It is NOT recommended for production use!\n"; +/* Flag: use conring for early console; switches to opt_console_to_ring */ +static bool __read_mostly use_conring = true; /* console_to_ring: send guest (incl. dom 0) console data to console ring. */ static bool __read_mostly opt_console_to_ring; boolean_param("console_to_ring", opt_console_to_ring); @@ -661,6 +663,16 @@ static void cf_check notify_dom0_con_ring(void *unused) static DECLARE_SOFTIRQ_TASKLET(notify_dom0_con_ring_tasklet, notify_dom0_con_ring, NULL); +static bool console_locks_busted; + +static void conring_write(const char *str, size_t len) +{ + conring_puts(str, len); + + if ( !console_locks_busted ) + tasklet_schedule(¬ify_dom0_con_ring_tasklet); +} + #ifdef CONFIG_X86 static inline void xen_console_write_debug_port(const char *buf, size_t len) { @@ -669,8 +681,44 @@ static inline void xen_console_write_debug_port(const char *buf, size_t len) : "=&S" (tmp), "=&c" (tmp) : "0" (buf), "1" (len), "d" (XEN_HVM_DEBUGCONS_IOPORT) ); } + +static void xen_console_write(const char *str, size_t len) +{ + if ( xen_guest ) + xen_hypercall_console_write(str, len); + else + xen_console_write_debug_port(str, len); +} +#else +static inline void xen_console_write(const char *str, size_t len) +{ +} #endif +/* + * Write characters to console. + * + * That will handle all possible scenarios working w/ console + * - serial console; + * - video output; + * - __HYPERVISOR_console_io hypercall (x86 only); + * - debug I/O port (x86 only); + * - forward to Xen event channel. + */ +static void console_write(const char *str, size_t len) +{ + ASSERT(rspin_is_locked(&console_lock)); + + console_serial_puts(str, len); + video_puts(str, len); + + if ( opt_console_xen ) + xen_console_write(str, len); + + if ( use_conring ) + conring_write(str, len); +} + static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, unsigned int count) { @@ -691,28 +739,8 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, if ( is_hardware_domain(cd) ) { - /* Use direct console output as it could be interactive */ nrspin_lock_irq(&console_lock); - - console_serial_puts(kbuf, kcount); - video_puts(kbuf, kcount); - -#ifdef CONFIG_X86 - if ( opt_console_xen ) - { - if ( xen_guest ) - xen_hypercall_console_write(kbuf, kcount); - else - xen_console_write_debug_port(kbuf, kcount); - } -#endif - - if ( opt_console_to_ring ) - { - conring_puts(kbuf, kcount); - tasklet_schedule(¬ify_dom0_con_ring_tasklet); - } - + console_write(kbuf, kcount); nrspin_unlock_irq(&console_lock); } else @@ -813,31 +841,9 @@ long do_console_io( * ***************************************************** */ -static bool console_locks_busted; - static void __putstr(const char *str) { - size_t len = strlen(str); - - ASSERT(rspin_is_locked(&console_lock)); - - console_serial_puts(str, len); - video_puts(str, len); - -#ifdef CONFIG_X86 - if ( opt_console_xen ) - { - if ( xen_guest ) - xen_hypercall_console_write(str, len); - else - xen_console_write_debug_port(str, len); - } -#endif - - conring_puts(str, len); - - if ( !console_locks_busted ) - tasklet_schedule(¬ify_dom0_con_ring_tasklet); + console_write(str, strlen(str)); } static int printk_prefix_check(char *p, char **pp) @@ -1171,6 +1177,9 @@ void __init console_endboot(void) video_endboot(); + use_conring = opt_console_to_ring; + smp_wmb(); + register_keyhandler('w', dump_console_ring_key, "synchronously dump console ring buffer (dmesg)", 0); register_irq_keyhandler('+', &do_inc_thresh, From patchwork Fri Dec 6 04:41:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896510 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 76C25E77173 for ; Fri, 6 Dec 2024 05:01:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849758.1264325 (Exim 4.92) (envelope-from ) id 1tJQSi-0001iZ-BM; Fri, 06 Dec 2024 05:01:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849758.1264325; Fri, 06 Dec 2024 05:01:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQSi-0001iS-8a; Fri, 06 Dec 2024 05:01:08 +0000 Received: by outflank-mailman (input) for mailman id 849758; Fri, 06 Dec 2024 05:01:06 +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 1tJQA7-0004Kb-0S for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:55 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 642d15e5-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:43 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 505A75C7323; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id E50A9C4CEDE; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBE78E77175; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) 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: 642d15e5-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460098; bh=PJJ4npH36unNSzjXcb8NI2vArWEkfURXL6bFFuUiDHo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=UQgkSZtWVa9FG9t1D5mOZW5z072Osw8G8GmdO1+7fn17cWhT0Ro8xPOW/k8vF45No kA21roJuxVeE0nzz7aI/hcDSWdDh5fd1KR36560FtLwOLm0BfIbgarlaI3I7dXFkAy ue39WmPRawJ1/n9YG9L3vT1WBEYrNBiINIbnRUt7kTpYEOI4Cz3zIH0I+uG3HwCSlX lCpXFcN+KXgYunteT3BKGARDEuxesjKuQWhCgdicE3PMsZahaoisGbUJMt1QAvFc2y mNaU3ZSiqJCiPoo6Wq/ToTGYZaEtn4mr3CWdaDnLfMS4bDoldla6Lhi4cbsOAUskja nhYA9JkPvmNFg== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:54 -0800 Subject: [PATCH v2 24/35] xen/console: introduce hwdom_crashconsole= MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-24-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=3897; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=1SE1nPGu4xeTH/OTKpOlxTlLd/mo9Wc6622Zz4Y1AHc=; b=Ojfyv76A9s+nHItTnUu5XXzmcReLwQ/cS7xcueyxc3sbROAgSJngYgjiuIlonbN9oIe8CBGJs YSZYIJCFA4+CNyG8V/SJfCQkjRyHkBMEHk16OIe2bCfcQi3csn2vS0U X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin The new command line switch `hwdom_crashconsole=BOOL` allows to switch serial console input focus to xen for machine state inspection using keyhandler mechanism after the hardware domain crashes. The new command line switch is aliased via `dom0=...,crashconsole` knob. Such functionality can be useful while debugging dom0 bringup. Signed-off-by: Denis Mukhin --- docs/misc/xen-command-line.pandoc | 5 +++++ xen/arch/x86/dom0_build.c | 2 ++ xen/common/domain.c | 14 +++++++++++++- xen/include/xen/domain.h | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc index 293dbc1a957ba6e668fd4d55d58e84f643822126..fb77d7dca1ea517f79d6713aa6909422f31e7724 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -806,6 +806,7 @@ Specify the bit width of the DMA heap. ### dom0 = List of [ pv | pvh, shadow=, verbose=, + crashconsole=, cpuid-faulting=, msr-relaxed= ] (x86) = List of [ sve= ] (Arm64) @@ -839,6 +840,10 @@ Controls for how dom0 is constructed on x86 systems. information during the dom0 build. It defaults to the compile time choice of `CONFIG_VERBOSE_DEBUG`. +* The `crashconsole` boolean instructs Xen to drop into emergency console + in case of dom0 crash. May be useful for dom0 bringup on a custom + hardware. + * The `cpuid-faulting` boolean is an interim option, is only applicable to PV dom0, and defaults to true. diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index e8f5bf5447bc47a6daa3d95787106a4c11e80d31..706aeec0ecbb565a415edbfb33ca2fd72967c560 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -286,6 +286,8 @@ int __init parse_arch_dom0_param(const char *s, const char *e) opt_dom0_cpuid_faulting = val; else if ( (val = parse_boolean("msr-relaxed", s, e)) >= 0 ) opt_dom0_msr_relaxed = val; + else if ( (val = parse_boolean("crashconsole", s, e)) >= 0 ) + opt_hwdom_crashconsole = !!val; else return -EINVAL; diff --git a/xen/common/domain.c b/xen/common/domain.c index aab546c0a8535e4f007cbbc9c5c552bcf66b5807..4fe69f294158dda7b2e0b9d98d49c34e04131cb8 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -56,6 +56,13 @@ unsigned int xen_processor_pmbits = XEN_PROCESSOR_PM_PX; bool opt_dom0_vcpus_pin; boolean_param("dom0_vcpus_pin", opt_dom0_vcpus_pin); +/* + * Hardware domain crash handler: if true, do not halt machine, but switch to + * Xen console for debugging. + */ +bool opt_hwdom_crashconsole; +boolean_param("hwdom_crashconsole", opt_hwdom_crashconsole); + /* Protect updates/reads (resp.) of domain_list and domain_hash. */ DEFINE_SPINLOCK(domlist_update_lock); DEFINE_RCU_READ_LOCK(domlist_read_lock); @@ -1138,7 +1145,12 @@ int domain_shutdown(struct domain *d, u8 reason) reason = d->shutdown_code; if ( is_hardware_domain(d) ) - hwdom_shutdown(reason); + { + if ( opt_hwdom_crashconsole ) + console_set_owner(DOMID_XEN); + else + hwdom_shutdown(reason); + } if ( d->is_shutting_down ) { diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 6102826a929ff7aad58a4bc40974815071a97446..e0c52af878b69e28e2d19957d0d3a8234860ecba 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -150,6 +150,7 @@ extern unsigned int xen_processor_pmbits; extern bool opt_dom0_vcpus_pin; extern cpumask_t dom0_cpus; extern bool dom0_affinity_relaxed; +extern bool opt_hwdom_crashconsole; /* vnuma topology per domain. */ struct vnuma_info { From patchwork Fri Dec 6 04:41:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0379BE77173 for ; Fri, 6 Dec 2024 04:52:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849610.1264256 (Exim 4.92) (envelope-from ) id 1tJQJy-0002v1-Vw; Fri, 06 Dec 2024 04:52:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849610.1264256; Fri, 06 Dec 2024 04:52:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQJy-0002uu-RP; Fri, 06 Dec 2024 04:52:06 +0000 Received: by outflank-mailman (input) for mailman id 849610; Fri, 06 Dec 2024 04:52:05 +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 1tJQA3-0004Ka-Mn for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:51 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 641a6002-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:42 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 5D95B5C7324; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id F1783C4CEDD; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA12DE77171; Fri, 6 Dec 2024 04:41:38 +0000 (UTC) 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: 641a6002-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460099; bh=pEJQg723yWljjn985dh3Vj78Rpiz9AzjJ9MOG9LwSPs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=lUCcZ3dxSny9GcrhYt/E5TKfIMvzI+VBNAYrTffh2f1GwtL3InyVq1nZXnp/uq8gy utDYxNt2R4iOLZd6qsqs0dGU/U5XKv3gXJn4GMcV7NsTsOce4ydHqc8XRUDpAYZCcK fTU6xWBZ8z19gPFHFgNrNokWKvhsNdyTTY8ZZ+awT6s3ISU5FbhzWIXizkcEmsrW13 mRdXivbAsFGjdjRo2R+G+RrGBsLyD/2MbKP1dCYV45bQ9ysIzald0l+GOT19f4v0mg MYI+I/JmZfrsIOLjJ/dP9wi+6dfBlOsKk+T3RsOQ5RhXSyXqF1Cj4mdiHiSxmk8NOZ KWkNAMg0yJCMQ== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:55 -0800 Subject: [PATCH v2 25/35] xen/console: simplify console owner switch hint MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-25-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=881; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=8rbmvBVON7AxnVLWZe4TyiZNfaP+ce1iMVhidiuAaeA=; b=ngSX/Bjan55Yf6HbhjCcVyH1MRrm+rX6fCLNvoL2CELYqurZ5AMRgsHmNbAjVstU/zeZv2WRK t2fk6SQ9SZpC3ILMTDGon5ON0+OcpvIJPkVFDh3uiDU0ZPaGM8EUHGk X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Update the hint w/ the combination of keys to press to switch physical console to the next owner. Signed-off-by: Denis Mukhin --- xen/drivers/char/console.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 115967d179998cba4a81578caba09db4e4aca7f7..d22fb4a253af26f9b51d91bd408e1dbf4bb5a7c1 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -528,8 +528,8 @@ int console_set_owner(domid_t domid) console_owner = domid; if ( switch_code ) - printk(" (type 'CTRL-%c' three times to switch input)", - opt_conswitch[0]); + printk(" (type 'CTRL-%c%c%c' to switch input)", + opt_conswitch[0], opt_conswitch[0], opt_conswitch[0]); printk("\n"); return 0; From patchwork Fri Dec 6 04:41:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896504 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7FE43E77173 for ; Fri, 6 Dec 2024 04:52:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849623.1264265 (Exim 4.92) (envelope-from ) id 1tJQKH-0003UN-5L; Fri, 06 Dec 2024 04:52:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849623.1264265; Fri, 06 Dec 2024 04:52:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQKH-0003UG-1w; Fri, 06 Dec 2024 04:52:25 +0000 Received: by outflank-mailman (input) for mailman id 849623; Fri, 06 Dec 2024 04:52:24 +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 1tJQA4-0004Ka-N5 for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:52 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [2604:1380:4641:c500::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 64216c89-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:42 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 689D45C7326; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 09FA7C4CED2; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01DF2E77179; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) 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: 64216c89-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460099; bh=Im1Mvwd2pdpjWUGPxHVuvCi077+oaVpTSYKTKajHUUQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=YnIAFC1KOQscV16csADO8+1kFmxcwMoJQGjTMUDHNQJA23KSOad09CfF759yRqc49 hsY/hyXNoiVl7Uzd14gJ3vZGUG7YafwoZV2TsBPjoBqt+SXV9R4eSt7j2rsTAGwiu0 hVDelKN3R5paZ1L5BG/0aFmN1a1bqHxgZxsv9X7qhD7bbA0JHlHGfXmgMAG/OgzMmj JphKEkeoyNNffgAqf8QyEoBXsKqH0hnAqIw7nEzsD8W9JAWbHl3wZk9RRbHu8g/n2d rXBRCRn2YjwGgAGLqohLgjndBKXM9qGD19XGDqi8LKv9Hl4MIURbW/9fXzuGK8sSou 6YkgOd2+gctoA== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:56 -0800 Subject: [PATCH v2 26/35] xen/console: make console buffer size configurable MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-26-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460094; l=2270; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=c1A6Ce5BfoKvn4U6L7fgV9aDcO1E8jTShGZsUzA9o1w=; b=6nQIusazz8SZIdcS2FjkD73AGOVR3RZCfFt69UsZdbDOMeBLkjG7wc5tSw9FTJxQCypBclp6S qYSAqfv4s5xAyrHNjlKYKwaWHsnUW3YUkTF6v6RS2oc0+KOumBnFyY1 X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Add new CONRING_LOG_SHIFT Kconfig parameter to specify the boot console buffer size as a power of 2. Bump default size to 32 KiB. Link: https://gitlab.com/xen-project/xen/-/issues/185 Signed-off-by: Denis Mukhin --- xen/drivers/char/Kconfig | 23 +++++++++++++++++++++++ xen/drivers/char/console.c | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/xen/drivers/char/Kconfig b/xen/drivers/char/Kconfig index e6e12bb4139717f9319031f51f5d20155d2caee2..3bc892fc38d8cdeb3c76ea44d747f712a8d0d372 100644 --- a/xen/drivers/char/Kconfig +++ b/xen/drivers/char/Kconfig @@ -96,6 +96,29 @@ config SERIAL_TX_BUFSIZE Default value is 32768 (32KiB). +config CONRING_LOG_SHIFT + int "Console buffer size" + range 14 25 + default 15 + help + Select the boot console buffer size as a power of 2. + Run-time console buffer size is the same as the boot console size, + unless enforced via 'conring_size=' boot parameter. + + Examples: + 25 => 32 MiB + 24 => 16 MiB + 23 => 8 MiB + 22 => 4 MiB + 21 => 2 MiB + 20 => 1 MiB + 19 => 512 KiB + 18 => 256 KiB + 17 => 128 KiB + 16 => 64 KiB + 15 => 32 KiB + 14 => 16 KiB + 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 d22fb4a253af26f9b51d91bd408e1dbf4bb5a7c1..581ee22b85302a54db5b9d5d28e8b2d689d31403 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -104,11 +104,11 @@ static int cf_check parse_console_timestamps(const char *s); custom_runtime_param("console_timestamps", parse_console_timestamps, con_timestamp_mode_upd); -/* conring_size: allows a large console ring than default (16kB). */ +/* conring_size: allows a large console ring than default (32 KiB). */ static uint32_t __initdata opt_conring_size; size_param("conring_size", opt_conring_size); -#define _CONRING_SIZE 16384 +#define _CONRING_SIZE (1U << CONFIG_CONRING_LOG_SHIFT) #define CONRING_IDX_MASK(i) ((i)&(conring_size-1)) static char __initdata _conring[_CONRING_SIZE]; static char *__read_mostly conring = _conring; From patchwork Fri Dec 6 04:41:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896508 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ABF6EE77173 for ; Fri, 6 Dec 2024 04:59:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849724.1264305 (Exim 4.92) (envelope-from ) id 1tJQQc-00075O-Ka; Fri, 06 Dec 2024 04:58:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849724.1264305; Fri, 06 Dec 2024 04:58:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQQc-00075H-HQ; Fri, 06 Dec 2024 04:58:58 +0000 Received: by outflank-mailman (input) for mailman id 849724; Fri, 06 Dec 2024 04:58:57 +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 1tJQA8-0004Kb-0Y for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:56 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 64345bc6-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:43 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 753495C7328; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 1675AC4CEE4; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EA64E77173; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) 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: 64345bc6-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460099; bh=pfeozTwM0lG3guW16R9YEzvHJZviJlXoXV1tkNollME=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=f6gF7PdCGex8zQ5mnanBXlfimZN+yyf9wVHGpLH0v6ONU5aF1nyYf9uODenzHMjZg o7TVTyUr8MFFtqHsow6MDgvfsSCOEz9yXNXR4dOtTCuxIAZbKan3DSLU2yquYO7qp8 uY9B1aNpIuM2d8MvvF8szQdybnNboU4qdnHckcUhTtBFkU7RpNYDNDrEGd4DKh0TFS 98HivOcZfVQBNf2kz83KBaurJrL0Im3fLndLTxxr/PO4vTfPWk84Cvixwi4y3PH4My GB7dHoXVLHiCIkByOrbVTRlPToks8znvhQwux0BcsAlLqSbrNYF+01+J3FrNbLUrRT I22VL57Iv98zg== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:57 -0800 Subject: [PATCH v2 27/35] xen/console: flush console ring to physical console MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-27-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460095; l=3110; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=9P4Y8stZ3v9veFAxdHp9EFeTfuXrbjGeXMl4yBrDrRM=; b=LcDAXG+yR65ns4PDQ7+Ep0c/twONKtCO6FP3OyvFTTqVtifqgbIkwSkeCUfa9psmIj3lFPPnM 83h3+UYJFZ4D7QPLSxSZewJhQFIyiw2yPpSDbEylErgaWgtM7WS39IF X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Messages printed before the serial and VGA consoles are initialized end up in the internal console buffer (conring). Flush contents of conring to all external consoles after external consoles are fully initialied. Link: https://gitlab.com/xen-project/xen/-/issues/184 Signed-off-by: Denis Mukhin --- xen/drivers/char/console.c | 54 +++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 581ee22b85302a54db5b9d5d28e8b2d689d31403..a26daee9c4c4b1134d0ae3d105ffdb656340b6df 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -426,23 +426,35 @@ void console_serial_puts(const char *s, size_t nr) pv_console_puts(s, nr); } -static void cf_check dump_console_ring_key(unsigned char key) +/* + * Write characters to physical console(s). + * That covers: + * - serial console; + * - video output. + */ +static void console_puts(const char *str, size_t len) +{ + ASSERT(rspin_is_locked(&console_lock)); + + console_serial_puts(str, len); + video_puts(str, len); +} + +/* + * Flush contents of the conring to the physical console devices. + */ +static int console_flush(void) { uint32_t idx, len, sofar, c; unsigned int order; char *buf; - printk("'%c' pressed -> dumping console ring buffer (dmesg)\n", key); - - /* create a buffer in which we'll copy the ring in the correct - order and NUL terminate */ order = get_order_from_bytes(conring_size + 1); buf = alloc_xenheap_pages(order, 0); if ( buf == NULL ) - { - printk("unable to allocate memory!\n"); - return; - } + return -ENOMEM; + + nrspin_lock_irq(&console_lock); c = conringc; sofar = 0; @@ -457,10 +469,23 @@ static void cf_check dump_console_ring_key(unsigned char key) c += len; } - console_serial_puts(buf, sofar); - video_puts(buf, sofar); + console_puts(buf, sofar); + + nrspin_unlock_irq(&console_lock); free_xenheap_pages(buf, order); + + return 0; +} + +static void cf_check dump_console_ring_key(unsigned char key) +{ + int rc; + + printk("'%c' pressed -> dumping console ring buffer (dmesg)\n", key); + rc = console_flush(); + if ( rc ) + printk("failed to dump console ring buffer: %d\n", rc); } /* @@ -707,10 +732,7 @@ static inline void xen_console_write(const char *str, size_t len) */ static void console_write(const char *str, size_t len) { - ASSERT(rspin_is_locked(&console_lock)); - - console_serial_puts(str, len); - video_puts(str, len); + console_puts(str, len); if ( opt_console_xen ) xen_console_write(str, len); @@ -1177,6 +1199,8 @@ void __init console_endboot(void) video_endboot(); + /* NB: send conring contents to all enabled physical consoles, if any */ + console_flush(); use_conring = opt_console_to_ring; smp_wmb(); From patchwork Fri Dec 6 04:41:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896509 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CF438E77173 for ; Fri, 6 Dec 2024 05:00:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849736.1264315 (Exim 4.92) (envelope-from ) id 1tJQRZ-0007sZ-UH; Fri, 06 Dec 2024 04:59:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849736.1264315; Fri, 06 Dec 2024 04:59:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQRZ-0007sS-Ra; Fri, 06 Dec 2024 04:59:57 +0000 Received: by outflank-mailman (input) for mailman id 849736; Fri, 06 Dec 2024 04:59:56 +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 1tJQA6-0004Ka-NM for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:54 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 642fa7da-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:43 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 8411F5C732A; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 25C16C4CEE0; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DE67E77175; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) 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: 642fa7da-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460099; bh=tqpmdL8JNRiLSamzy9ROf/yJ/66J2svyAG5pfiQILB0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=u7P9mgJdpIjUCR4UTz9a57NXTHwJcB5aeeBrK0LU7Nov965LEsoBe1GBVhjVO3QQZ W0SvFy5A84Aj2H5qY5gPmEeXd3tCpjZc7TsXw3UnXUcX1htfK98vbtvrmCyfPpCOwQ EqZnHIb39dZc2WW8OTP6pkjnestLt6EXqx62a8t0QZ38di3jKlWrRiGJJt7/fNhUrl kTw2HUnIIjiUezrcjUDkyyl7bPM0FeCx3XdlC/dcbicKbiw9+tSCxw8+1oiEWNSUdq zR6UZuQZHfdI3MuFIrdANp4QHQv1nNe/+H+fDOHUO0Pw9PM/3cb6xbOTNfLwmBDjBJ N+4Z/BvgzJ8Mw== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:58 -0800 Subject: [PATCH v2 28/35] xen/8250-uart: add missing definitions MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-28-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460095; l=7150; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=tIDl7kdtapSdiWgcLjWmQ7v8zbW9hmc48ULvT599z7A=; b=kPzosi8ho+ByeLwfCWEeVFseo8sJZ+0pQO4SEJq2xAHq/cop5Z9wnnfTJ7hX4VXH2kuye0ajT y1zxyalUV4kBc0xBvVDO5M7y3G4JHEggAouSPKUNF5FfZUP436ueI3j X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Added missing definitions needed for NS8250 UART emulator. Signed-off-by: Denis Mukhin --- xen/include/xen/8250-uart.h | 81 +++++++++++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 21 deletions(-) diff --git a/xen/include/xen/8250-uart.h b/xen/include/xen/8250-uart.h index d13352940c13c50bac17d4cdf2f3bf584380776a..4a69b2b225140efda287bdf96fa0caa4aa70074f 100644 --- a/xen/include/xen/8250-uart.h +++ b/xen/include/xen/8250-uart.h @@ -32,16 +32,22 @@ #define UART_MCR 0x04 /* Modem control */ #define UART_LSR 0x05 /* line status */ #define UART_MSR 0x06 /* Modem status */ +#define UART_SCR 0x07 /* Scratch pad */ #define UART_USR 0x1f /* Status register (DW) */ #define UART_DLL 0x00 /* divisor latch (ls) (DLAB=1) */ #define UART_DLM 0x01 /* divisor latch (ms) (DLAB=1) */ #define UART_XR_EFR 0x09 /* Enhanced function register (Exar) */ +/* ns8250 emulator: range of emulated registers [0..UART_MAX-1] */ +#define UART_MAX (UART_SCR + 1) + /* Interrupt Enable Register */ #define UART_IER_ERDAI 0x01 /* rx data recv'd */ #define UART_IER_ETHREI 0x02 /* tx reg. empty */ #define UART_IER_ELSI 0x04 /* rx line status */ #define UART_IER_EMSI 0x08 /* MODEM status */ +#define UART_IER_MASK \ + (UART_IER_ERDAI | UART_IER_ETHREI | UART_IER_ELSI | UART_IER_EMSI) /* Interrupt Identification Register */ #define UART_IIR_NOINT 0x01 /* no interrupt pending */ @@ -51,12 +57,21 @@ #define UART_IIR_THR 0x02 /* - tx reg. empty */ #define UART_IIR_MSI 0x00 /* - MODEM status */ #define UART_IIR_BSY 0x07 /* - busy detect (DW) */ +#define UART_IIR_FE0 BIT(6, U) /* FIFO enable #0 */ +#define UART_IIR_FE1 BIT(7, U) /* FIFO enable #1 */ +#define UART_IIR_FE_MASK (UART_IIR_FE0 | UART_IIR_FE1) /* FIFO Control Register */ -#define UART_FCR_ENABLE 0x01 /* enable FIFO */ -#define UART_FCR_CLRX 0x02 /* clear Rx FIFO */ -#define UART_FCR_CLTX 0x04 /* clear Tx FIFO */ -#define UART_FCR_DMA 0x10 /* enter DMA mode */ +#define UART_FCR_ENABLE BIT(0, U) /* enable FIFO */ +#define UART_FCR_CLRX BIT(1, U) /* clear Rx FIFO */ +#define UART_FCR_CLTX BIT(2, U) /* clear Tx FIFO */ +#define UART_FCR_DMA BIT(3, U) /* enter DMA mode */ +#define UART_FCR_RESERVED0 BIT(4, U) /* reserved; always 0 */ +#define UART_FCR_RESERVED1 BIT(5, U) /* reserved; always 0 */ +#define UART_FCR_RTB0 BIT(6, U) /* receiver trigger bit #0 */ +#define UART_FCR_RTB1 BIT(7, U) /* receiver trigger bit #1 */ +#define UART_FCR_TRG_MASK (UART_FCR_RTB0 | UART_FCR_RTB1) + #define UART_FCR_TRG1 0x00 /* Rx FIFO trig lev 1 */ #define UART_FCR_TRG4 0x40 /* Rx FIFO trig lev 4 */ #define UART_FCR_TRG8 0x80 /* Rx FIFO trig lev 8 */ @@ -64,17 +79,17 @@ /* * Note: The FIFO trigger levels are chip specific: - * RX:76 = 00 01 10 11 TX:54 = 00 01 10 11 - * PC16550D: 1 4 8 14 xx xx xx xx - * TI16C550A: 1 4 8 14 xx xx xx xx - * TI16C550C: 1 4 8 14 xx xx xx xx - * ST16C550: 1 4 8 14 xx xx xx xx - * ST16C650: 8 16 24 28 16 8 24 30 PORT_16650V2 - * NS16C552: 1 4 8 14 xx xx xx xx - * ST16C654: 8 16 56 60 8 16 32 56 PORT_16654 - * TI16C750: 1 16 32 56 xx xx xx xx PORT_16750 - * TI16C752: 8 16 56 60 8 16 32 56 - * Tegra: 1 4 8 14 16 8 4 1 PORT_TEGRA + * RX:76 = 00 01 10 11 TX:54 = 00 01 10 11 + * PC16550D: 1 4 8 14 xx xx xx xx + * TI16C550A: 1 4 8 14 xx xx xx xx + * TI16C550C: 1 4 8 14 xx xx xx xx + * ST16C550: 1 4 8 14 xx xx xx xx + * ST16C650: 8 16 24 28 16 8 24 30 PORT_16650V2 + * NS16C552: 1 4 8 14 xx xx xx xx + * ST16C654: 8 16 56 60 8 16 32 56 PORT_16654 + * TI16C750: 1 16 32 56 xx xx xx xx PORT_16750 + * TI16C752: 8 16 56 60 8 16 32 56 + * Tegra: 1 4 8 14 16 8 4 1 PORT_TEGRA */ #define UART_FCR_R_TRIG_00 0x00 #define UART_FCR_R_TRIG_01 0x40 @@ -96,11 +111,31 @@ #define UART_LCR_CONF_MODE_B 0xBF /* Configuration mode B */ /* Modem Control Register */ -#define UART_MCR_DTR 0x01 /* Data Terminal Ready */ -#define UART_MCR_RTS 0x02 /* Request to Send */ -#define UART_MCR_OUT2 0x08 /* OUT2: interrupt mask */ -#define UART_MCR_LOOP 0x10 /* Enable loopback test mode */ -#define UART_MCR_TCRTLR 0x40 /* Access TCR/TLR (TI16C752, EFR[4]=1) */ +#define UART_MCR_DTR BIT(0, U) /* Data Terminal Ready */ +#define UART_MCR_RTS BIT(1, U) /* Request to Send */ +#define UART_MCR_OUT1 BIT(2, U) /* OUT1: interrupt mask */ +#define UART_MCR_OUT2 BIT(3, U) /* OUT2: interrupt mask */ +#define UART_MCR_LOOP BIT(4, U) /* Enable loopback test mode */ +#define UART_MCR_RESERVED0 BIT(5, U) /* Reserved #0 */ +#define UART_MCR_RESERVED1 BIT(6, U) /* Reserved #1 */ +#define UART_MCR_TCRTLR BIT(6, U) /* Access TCR/TLR (TI16C752, EFR[4]=1) */ +#define UART_MCR_RESERVED2 BIT(7, U) /* Reserved #2 */ +#define UART_MCR_MASK \ + (UART_MCR_DTR | UART_MCR_RTS | \ + UART_MCR_OUT1 | UART_MCR_OUT2 | \ + UART_MCR_LOOP) + +/* Modem Status Register */ +#define UART_MSR_DCTS BIT(0, U) /* Change in CTS */ +#define UART_MSR_DDSR BIT(1, U) /* Change in DSR */ +#define UART_MSR_TERI BIT(2, U) /* Change in RI */ +#define UART_MSR_DDCD BIT(3, U) /* Change in CTS */ +#define UART_MSR_CTS BIT(4, U) +#define UART_MSR_DSR BIT(5, U) +#define UART_MSR_RI BIT(6, U) +#define UART_MSR_DCD BIT(7, U) +#define UART_MSR_DELTA \ + (UART_MSR_DCTS | UART_MSR_DDSR | UART_MSR_TERI | UART_MSR_DDCD) /* Line Status Register */ #define UART_LSR_DR 0x01 /* Data ready */ @@ -111,6 +146,7 @@ #define UART_LSR_THRE 0x20 /* Xmit hold reg empty */ #define UART_LSR_TEMT 0x40 /* Xmitter empty */ #define UART_LSR_ERR 0x80 /* Error */ +#define UART_LSR_MASK (UART_LSR_OE | UART_LSR_BI) /* These parity settings can be ORed directly into the LCR. */ #define UART_PARITY_NONE (0<<3) @@ -119,7 +155,10 @@ #define UART_PARITY_MARK (5<<3) #define UART_PARITY_SPACE (7<<3) -/* Frequency of external clock source. This definition assumes PC platform. */ +/* + * Frequency of external UART clock source. + * Same as IBM PC master input clock frequency. + */ #define UART_CLOCK_HZ 1843200 /* Bits in Exar specific UART_XR_EFR register */ From patchwork Fri Dec 6 04:41:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 25BE3E77173 for ; Fri, 6 Dec 2024 04:51:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849577.1264234 (Exim 4.92) (envelope-from ) id 1tJQJH-0001Ji-7E; Fri, 06 Dec 2024 04:51:23 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849577.1264234; Fri, 06 Dec 2024 04:51:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQJH-0001Jb-4a; Fri, 06 Dec 2024 04:51:23 +0000 Received: by outflank-mailman (input) for mailman id 849577; Fri, 06 Dec 2024 04:51:21 +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 1tJQA9-0004Kb-0W for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:57 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 644269c0-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:43 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 960CC5C732D; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 35F63C4CEDE; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C274E77173; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) 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: 644269c0-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460099; bh=3rV9SQVk/30C/uR+xCoEerXgtGQ+GY3Qffyqy2vy1lU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=k64HvH+qF2M9KGqEwnq44eOJ05uQEed2KEIqeWYUDnIzhT6RGz0czXFjlzNDO+VAZ 2KCrkwM762rqoIHcLKWZe9gcDm7751+ICxtL7b321CluCXK2EGsJXADEhQ+bUNZuQB 9ElKBIDS71X3NjP0UEtIWWaMHcR50mMLJkEQNAJA/Jrlgc51W4+CN/1DrWxo/E8/VF S6BHFzIiHxRupv3chXQ/ByJEtfrM/YejfB43HundwFN9HJqklvtErhA+4bK28DkaDx MzN/ENlfTD6af7HLWj/plxliEtPAzkLiuk5tVL7f9RYQGWfAlizuZpgqlhQctB30fW j/Tq701j5qasw== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:41:59 -0800 Subject: [PATCH v2 29/35] x86/hvm: add HVM-specific Kconfig MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-29-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460095; l=5119; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=xth/C4RssnpHF5d1BFSmQSRG1c+DKNwkoUPEyi1j9F4=; b=Vf271mgRaklsri59ELziwyPLixUZV+ZRBALCEceomO950VfpmFBMRC/F1MZNNjtkP1V+Xe9Qe TZw4tEu3tp+D99eMcCUirUGz0xbPwVr/dkhKp/It6nMJui7zC8PG38U X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Add separate menu for configuring HVM build-time settings. That will help organizing HVM-specific options under a separate menu. Signed-off-by: Denis Mukhin --- xen/arch/x86/Kconfig | 66 +++--------------------------------------------- xen/arch/x86/hvm/Kconfig | 63 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 63 deletions(-) diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 9cdd04721afa1916c7edd8fdf7d606858c73ce88..5afee9a9f9bafa3c760b06b8601fad4cad3b7191 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -107,42 +107,9 @@ config PV_LINEAR_PT If unsure, say Y. -config HVM - bool "HVM support" - depends on !PV_SHIM_EXCLUSIVE - default !PV_SHIM - select COMPAT - select IOREQ_SERVER - select MEM_ACCESS_ALWAYS_ON - help - Interfaces to support HVM domains. HVM domains require hardware - virtualisation extensions (e.g. Intel VT-x, AMD SVM), but can boot - guests which have no specific Xen knowledge. - - This option is needed if you want to run HVM or PVH domains. - - If unsure, say Y. - -config AMD_SVM - bool "AMD-V" if EXPERT - depends on HVM - default y - help - Enables virtual machine extensions on platforms that implement the - AMD Virtualization Technology (AMD-V). - If your system includes a processor with AMD-V support, say Y. - If in doubt, say Y. - -config INTEL_VMX - bool "Intel VT-x" if EXPERT - depends on HVM - default y - select ARCH_VCPU_IOREQ_COMPLETION - help - Enables virtual machine extensions on platforms that implement the - Intel Virtualization Technology (Intel VT-x). - If your system includes a processor with Intel VT-x support, say Y. - If in doubt, say Y. +menu "HVM Support" +source "arch/x86/hvm/Kconfig" +endmenu config XEN_SHSTK bool "Supervisor Shadow Stacks" @@ -201,25 +168,6 @@ config BIGMEM If unsure, say N. -config HVM_FEP - bool "HVM Forced Emulation Prefix support (UNSUPPORTED)" if UNSUPPORTED - default DEBUG - depends on HVM - help - - Compiles in a feature that allows HVM guest to arbitrarily - exercise the instruction emulator. - - This feature can only be enabled during boot time with - appropriate hypervisor command line option. Please read - hypervisor command line documentation before trying to use - this feature. - - This is strictly for testing purposes, and not appropriate - for use in production. - - If unsure, say N. - config TBOOT bool "Xen tboot support (UNSUPPORTED)" depends on INTEL && UNSUPPORTED @@ -348,14 +296,6 @@ config HYPERV_GUEST endif -config MEM_PAGING - bool "Xen memory paging support (UNSUPPORTED)" if UNSUPPORTED - depends on HVM - -config MEM_SHARING - bool "Xen memory sharing support (UNSUPPORTED)" if UNSUPPORTED - depends on HVM - config REQUIRE_NX bool "Require NX (No eXecute) support" help diff --git a/xen/arch/x86/hvm/Kconfig b/xen/arch/x86/hvm/Kconfig new file mode 100644 index 0000000000000000000000000000000000000000..361bb6572e633f3cf0fc972a3b391e8341c33361 --- /dev/null +++ b/xen/arch/x86/hvm/Kconfig @@ -0,0 +1,63 @@ +config HVM + bool "HVM support" + depends on !PV_SHIM_EXCLUSIVE + default !PV_SHIM + select COMPAT + select IOREQ_SERVER + select MEM_ACCESS_ALWAYS_ON + help + Interfaces to support HVM domains. HVM domains require hardware + virtualisation extensions (e.g. Intel VT-x, AMD SVM), but can boot + guests which have no specific Xen knowledge. + + This option is needed if you want to run HVM or PVH domains. + + If unsure, say Y. + +config AMD_SVM + bool "AMD-V" if EXPERT + depends on HVM + default y + help + Enables virtual machine extensions on platforms that implement the + AMD Virtualization Technology (AMD-V). + If your system includes a processor with AMD-V support, say Y. + If in doubt, say Y. + +config INTEL_VMX + bool "Intel VT-x" if EXPERT + depends on HVM + default y + select ARCH_VCPU_IOREQ_COMPLETION + help + Enables virtual machine extensions on platforms that implement the + Intel Virtualization Technology (Intel VT-x). + If your system includes a processor with Intel VT-x support, say Y. + If in doubt, say Y. + +config MEM_PAGING + bool "Xen memory paging support (UNSUPPORTED)" if UNSUPPORTED + depends on HVM + +config MEM_SHARING + bool "Xen memory sharing support (UNSUPPORTED)" if UNSUPPORTED + depends on HVM + +config HVM_FEP + bool "HVM Forced Emulation Prefix support (UNSUPPORTED)" if UNSUPPORTED + default DEBUG + depends on HVM + help + + Compiles in a feature that allows HVM guest to arbitrarily + exercise the instruction emulator. + + This feature can only be enabled during boot time with + appropriate hypervisor command line option. Please read + hypervisor command line documentation before trying to use + this feature. + + This is strictly for testing purposes, and not appropriate + for use in production. + + If unsure, say N. From patchwork Fri Dec 6 04:42:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CD7A9E77179 for ; Fri, 6 Dec 2024 04:57:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849691.1264295 (Exim 4.92) (envelope-from ) id 1tJQOi-0005qx-8p; Fri, 06 Dec 2024 04:57:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849691.1264295; Fri, 06 Dec 2024 04:57:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQOi-0005qo-5g; Fri, 06 Dec 2024 04:57:00 +0000 Received: by outflank-mailman (input) for mailman id 849691; Fri, 06 Dec 2024 04:56:59 +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 1tJQA7-0004Ka-Nh for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:55 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 644bfbde-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:43 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A52EF5C732E; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 474BEC4CEDD; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F6D9E77175; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) 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: 644bfbde-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460099; bh=WDr/PwUo7NPVqK8vVCu/sN3ApYHaNVXqHBFVutTjEsg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=g9qa65XgT5Ti4I/dt0zAvh88VVZ8gYPwjf1RlnWBD6k0hqV7efZ2HqXdNt1syG6Gs Uzio9wCFBAMxJSwgLQ633VtFVqKBKw5sdipxVH4KpcjxT6bgmioK9u/cPVyOFt1axG 0+L8CcziOT19Rf4F37f8A3yxU49YxRNdKfn2EbGCHtn00nEDiUPFWcp02do6FsDUu8 w0/Pmv8IbSkCJCmvFBJF0gXjinqNcIt4+0yLnkwokU9vYCkurq6yGDxPlLfV+Oas6X KM7DVGtHII2LbcdmOKDJ2VkdUHASud+eWqsDXQtwK2s2dbo/gmA/sGH/2Ez7FKoU3O SW53fiVi2h/yQ== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:42:00 -0800 Subject: [PATCH v2 30/35] x86/hvm: add helpers for raising guest IRQs MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-30-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460095; l=1876; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=7BbjWtYddozrVOKtAkZI0QGQoqm6ofyyNdgxey+37YU=; b=uhL0RGFLhulzxy34cTyyqujnBOZL+ZBS9SzwALgDFSK48UaqsfdXhwT9z9YUX31hMSipGTyQr NaKRK096AcJApdMQnckrIdCUs36HPCgT/O+UwoSDG/wyfSUkq8syezC X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Added convenience wrappers for asserting/de-asserting interrupts in the hardware emulation code. That will be used for PCI-based NS8250 emulator. Signed-off-by: Denis Mukhin --- xen/arch/x86/hvm/irq.c | 24 ++++++++++++++++++++++++ xen/arch/x86/include/asm/hvm/irq.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/xen/arch/x86/hvm/irq.c b/xen/arch/x86/hvm/irq.c index 1eab44defca4c82ec35769617c66c380cc07d1b6..9e3a50d21dcf281c1015116094e47795c51ed5d0 100644 --- a/xen/arch/x86/hvm/irq.c +++ b/xen/arch/x86/hvm/irq.c @@ -242,6 +242,30 @@ void hvm_isa_irq_deassert( spin_unlock(&d->arch.hvm.irq_lock); } +void hvm_irq_raise(struct domain *d, unsigned int irq) +{ + if ( irq < NR_ISAIRQS ) + { + hvm_isa_irq_assert(d, irq, NULL); + } + else + { + hvm_gsi_assert(d, irq); + } +} + +void hvm_irq_lower(struct domain *d, unsigned int irq) +{ + if ( irq < NR_ISAIRQS ) + { + hvm_isa_irq_deassert(d, irq); + } + else + { + hvm_gsi_deassert(d, irq); + } +} + static void hvm_set_callback_irq_level(struct vcpu *v) { struct domain *d = v->domain; diff --git a/xen/arch/x86/include/asm/hvm/irq.h b/xen/arch/x86/include/asm/hvm/irq.h index 87e89993a44f48f366fa84e851688f383cb562d4..27bb9f64171c1b8aac2cf119699e60c91e727177 100644 --- a/xen/arch/x86/include/asm/hvm/irq.h +++ b/xen/arch/x86/include/asm/hvm/irq.h @@ -210,6 +210,9 @@ void hvm_maybe_deassert_evtchn_irq(void); void hvm_assert_evtchn_irq(struct vcpu *v); void hvm_set_callback_via(struct domain *d, uint64_t via); +void hvm_irq_raise(struct domain *d, unsigned int irq); +void hvm_irq_lower(struct domain *d, unsigned int irq); + struct pirq; bool hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq); From patchwork Fri Dec 6 04:42:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B3F74E77173 for ; Fri, 6 Dec 2024 04:52:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849635.1264275 (Exim 4.92) (envelope-from ) id 1tJQKm-0004J2-Dv; Fri, 06 Dec 2024 04:52:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849635.1264275; Fri, 06 Dec 2024 04:52:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQKm-0004Iv-Ah; Fri, 06 Dec 2024 04:52:56 +0000 Received: by outflank-mailman (input) for mailman id 849635; Fri, 06 Dec 2024 04:52:54 +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 1tJQAA-0004Ka-O2 for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:58 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [2604:1380:4641:c500::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6470a81d-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:44 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BAEF15C72FF; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 5B6CFC4CED2; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52BB3E77173; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) 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: 6470a81d-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460099; bh=7ox8AYuku3MUu+7+JCRRTVFu9hJNAn02RVHVzf791I4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=gIA2SOY1FfFYBYT1Mmn4tWVnGT57WAyk1dcQl+Fw8XfrjJyy9Um+J5ZAvBrPlWslv QzDQZ3gW/E1Ci1SkfDbo+0ggHYViOgCsDZh7dJSrXYhmhqCo1hK4HNGfJhSizGYtL5 a+S00kY3yAJqwRR7N81KJ77s9k2QTTz578/1ds7mi266oCf/DQvW8VfihtgFMRIGjh kIkOTAZxAI9/c9X9HDOiDv2ouuURQEryJYIWyuisFo0fsU1KtfzlzrkAYUfbvg7tb8 gABL97+S6AMlFfIeqlBSXZd6U888fdMFcWA+rXACKuuy7X+YfAG+RtfGNbozuPHS1b alMobDk4jzjBg== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:42:01 -0800 Subject: [PATCH v2 31/35] x86/hvm: introduce NS8250 UART emulator MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-31-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460095; l=30223; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=42CO+kpsKd8aGqw1Wi2RPUjXAFZtPSxxxhuC3C8Cx0s=; b=7jSym1HCgQXK3tY7REAoo34oHbZ8fob7eg2BunF86hE4iqf1r6WP4Bhl5Ef95ykA0IYEOqUXA v32CRfUfgP0DKJanKLEugltnyzw1PzKz2qld3GUsKHDMHu2CnzCfS1C X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Add initial in-hypervisor emulator for NS8250/NS16x50-compatible UARTs under CONFIG_HAS_VUART_NS8250. In parallel domain creation scenario (hyperlaunch), NS8520 emulator helps early guest OS bringup debugging, because it eliminates dependency on the external emulator being operational by the time domains are created. Also, there's no early console facility similar to vpl011 to support x86 guest OS bring up. By default, CONFIG_HAS_VUART_NS8250 enables emulatio of NS8250 at I/O port 0x3f8, IRQ#4 in guest OS. Limitations: - Only x86; - Only Linux guest tested so far; - Only legacy COM{1,2,3,4} resources, no customization; - Only Xen console as a backend, no inter-domain communication (similar to vpl011 on Arm); - Only 8-bit characters; - Baud rate is not emulated; - FIFO-less mode is not emulated properly; - RX FIFO interrupt moderation (FCR) is not emulated properly, TL16C750 has special FCR handling; - No integration w/ VM snapshotting (HVM_REGISTER_SAVE_RESTORE() and friends); - Assumes no ISA-device IRQ sharing; - MMIO-based UART is not supported. Signed-off-by: Denis Mukhin --- xen/arch/x86/hvm/Kconfig | 14 + xen/arch/x86/hvm/Makefile | 1 + xen/arch/x86/hvm/hvm.c | 13 + xen/arch/x86/hvm/vuart_ns8250.c | 886 ++++++++++++++++++++++++++++ xen/arch/x86/include/asm/hvm/domain.h | 5 + xen/arch/x86/include/asm/hvm/vuart_ns8250.h | 75 +++ 6 files changed, 994 insertions(+) diff --git a/xen/arch/x86/hvm/Kconfig b/xen/arch/x86/hvm/Kconfig index 361bb6572e633f3cf0fc972a3b391e8341c33361..af6e698b8be0d82af94b00c0cfdaf9a2bc24b154 100644 --- a/xen/arch/x86/hvm/Kconfig +++ b/xen/arch/x86/hvm/Kconfig @@ -61,3 +61,17 @@ config HVM_FEP for use in production. If unsure, say N. + +config HAS_VUART_NS8250 + bool "NS8250-compatible UART Emulation" + depends on HVM && HAS_IOPORTS + default n + help + In-hypervisor NS8250/NS16x50 UART emulation. + + Only legacy PC I/O ports are emulated. + + This is strictly for testing purposes (early HVM guest console), and not + appropriate for use in production. + + If unsure, say N. diff --git a/xen/arch/x86/hvm/Makefile b/xen/arch/x86/hvm/Makefile index 4c1fa5c6c2bf75d336b39f343241bfced5b91b09..14761435e0694109f815da63289666c0f1cbf0ce 100644 --- a/xen/arch/x86/hvm/Makefile +++ b/xen/arch/x86/hvm/Makefile @@ -29,3 +29,4 @@ obj-y += vm_event.o obj-y += vmsi.o obj-y += vpic.o obj-y += vpt.o +obj-$(CONFIG_HAS_VUART_NS8250) += vuart_ns8250.o diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 493b699c708949b2109c26573a107565543f5d45..db61af7defc5f5da795b7a613fe4d32fbff7d93e 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -679,6 +680,15 @@ int hvm_domain_initialise(struct domain *d, if ( rc != 0 ) goto fail1; + if ( domain_has_vuart(d) ) + { + rc = domain_vuart_init(d); + if ( rc == 0 ) + d->is_console = true; + else if ( rc != -ENODEV ) + goto out_vioapic_deinit; + } + stdvga_init(d); rtc_init(d); @@ -699,6 +709,9 @@ int hvm_domain_initialise(struct domain *d, return 0; fail2: + if ( domain_has_vuart(d) ) + domain_vuart_free(d); + out_vioapic_deinit: vioapic_deinit(d); fail1: if ( is_hardware_domain(d) ) diff --git a/xen/arch/x86/hvm/vuart_ns8250.c b/xen/arch/x86/hvm/vuart_ns8250.c new file mode 100644 index 0000000000000000000000000000000000000000..779dbd80d7be4e070ea9df3ae736ecdc662a527a --- /dev/null +++ b/xen/arch/x86/hvm/vuart_ns8250.c @@ -0,0 +1,886 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * NS8250-compatible UART Emulator. + * + * Limitations: + * - Only x86; + * - Only Linux guest tested so far; + * - Only legacy COM{1,2,3,4} resources, no customization; + * - Only Xen console as a backend, no inter-domain communication (similar to + * vpl011 on Arm); + * - Only 8-bit characters; + * - Baud rate is not emulated; + * - FIFO-less mode is not emulated properly; + * - RX FIFO interrupt moderation (FCR) is not emulated properly, TL16C750 + * has special FCR handling; + * - No integration w/ VM snapshotting (HVM_REGISTER_SAVE_RESTORE() and + * friends); + * - Assumes no ISA-device IRQ sharing; + * - MMIO-based UART is not supported; + * - PCI UART is not supported. + */ + +#define pr_fmt(fmt) "ns8250: " fmt +#define pr_log_level hvm_ns8250_log_level + +/* Development debugging */ +#define NS8250_LOG_LEVEL 0 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* console_input_domid() */ +#include /* max_init_domid */ +#include +#include +#include +#include + +#if !defined(pr_fmt) +#define pr_fmt(fmt) fmt +#endif + +#if !defined(pr_log_level) +#define pr_log_level 0 +#endif + +#define pr_err(fmt, args...) \ + gprintk(KERN_ERR, pr_fmt(fmt), ## args) +#define pr_warn(fmt, args...) \ + if (pr_log_level) gprintk(KERN_WARNING, pr_fmt(fmt), ## args) +#define pr_info(fmt, args...) \ + if (pr_log_level) gprintk(KERN_INFO, pr_fmt(fmt), ## args) +#define pr_debug(fmt, args...) \ + if (pr_log_level) gprintk(KERN_DEBUG, pr_fmt(fmt), ## args) + +/* + * NS8250 emulator state machine logging (development only) + * FIXME: use similar to parse_guest_loglvl() + */ +static unsigned int __read_mostly hvm_ns8250_log_level = NS8250_LOG_LEVEL; +integer_param("hvm.ns8250.log_level", hvm_ns8250_log_level); + +/* + * Default emulated NS8250 resources. + * If not specified, COM1 (I/O port 0x3f8, IRQ#4) is emulated. + * FIXME: follow Linux'es console= syntax or re-use + * ns16550_parse_port_config(). + */ +static char __read_mostly hvm_ns8250_console[64]; +string_param("hvm.ns8250.console", hvm_ns8250_console); + +/* I/O access mask */ +static const uint32_t io_access_mask[] = { + [0] = 0X00000000U, + [1] = 0X000000FFU, + [2] = 0X0000FFFFU, + [4] = 0XFFFFFFFFU, +}; + +/* + * Legacy IBM PC NS8250 resources. + * There are only 4 I/O port ranges, hardcoding all of them here. + */ +static const struct { + const char *name; + const struct resource *res; +} ns8250_x86_legacy_uarts[4] = { + [0] = { + .name = "com1", + .res = (const struct resource[]){ + { .type = IORESOURCE_IO, .addr = 0x3F8, .size = UART_MAX }, + { .type = IORESOURCE_IRQ, .addr = 4, .size = 1 }, + { .type = IORESOURCE_UNKNOWN }, + }, + }, + [1] = { + .name = "com2", + .res = (const struct resource[]){ + { .type = IORESOURCE_IO, .addr = 0x2F8, .size = UART_MAX }, + { .type = IORESOURCE_IRQ, .addr = 3, .size = 1 }, + { .type = IORESOURCE_UNKNOWN }, + }, + }, + [2] = { + .name = "com3", + .res = (const struct resource[]){ + { .type = IORESOURCE_IO, .addr = 0x3E8, .size = UART_MAX }, + { .type = IORESOURCE_IRQ, .addr = 4, .size = 1 }, + { .type = IORESOURCE_UNKNOWN }, + }, + }, + [3] = { + .name = "com4", + .res = (const struct resource[]){ + { .type = IORESOURCE_IO, .addr = 0x2E8, .size = UART_MAX }, + { .type = IORESOURCE_IRQ, .addr = 3, .size = 1 }, + { .type = IORESOURCE_UNKNOWN }, + }, + }, +}; + +static bool ns8250_fifo_rx_empty(struct vuart_ns8250 *vdev) +{ + struct xencons_interface *cons = vdev->cons; + + return cons->in_prod == cons->in_cons; +} + +static bool ns8250_fifo_rx_full(struct vuart_ns8250 *vdev) +{ + struct xencons_interface *cons = vdev->cons; + + return cons->in_prod - cons->in_cons == sizeof(cons->in); +} + +static void ns8250_fifo_rx_reset(struct vuart_ns8250 *vdev) +{ + struct xencons_interface *cons = vdev->cons; + + cons->in_cons = cons->in_prod; +} + +static int ns8250_fifo_rx_getchar(struct vuart_ns8250 *vdev) +{ + struct xencons_interface *cons = vdev->cons; + int rc = -1; + + if ( !ns8250_fifo_rx_empty(vdev) ) + { + rc = cons->in[MASK_XENCONS_IDX(cons->in_cons, cons->in)]; + cons->in_cons++; + } + + return rc; +} + +static int ns8250_fifo_rx_putchar(struct vuart_ns8250 *vdev, char c) +{ + struct xencons_interface *cons = vdev->cons; + int rc = 0; + + /* + * FIFO-less 8250/16450 UARTs: newly arrived word overwrites the contents + * of the THR. + */ + if ( ns8250_fifo_rx_full(vdev) ) + { + ns8250_fifo_rx_reset(vdev); + rc = -ENOSPC; + } + + cons->in[MASK_XENCONS_IDX(cons->in_prod, cons->in)] = c; + cons->in_prod++; + + return rc; +} + +/* + * Flush cached output to Xen console. + * Can be called from ns8250_exit(). + */ +static void ns8250_fifo_tx_reset(struct vuart_ns8250 *vdev) +{ + struct xencons_interface *cons = vdev->cons; + + if ( cons->out_prod == 0 ) + return; + + cons->out[cons->out_prod++] = '\0'; + + /* + * NB: do not show domain ID if the domain owning the virtual UART also + * owns Xen input console. + */ + if ( vdev->owner->domain_id == console_owner_domid() ) + printk_common("%s", cons->out); + else + guest_printk(vdev->owner, "%s", cons->out); + + cons->out_prod = 0; +} + +/* + * Send a character to Xen console. + */ +static void ns8250_fifo_tx_putchar(struct vuart_ns8250 *vdev, char ch) +{ + struct xencons_interface *cons = vdev->cons; + + if ( !isconsole(ch) ) + return; + + cons->out[cons->out_prod] = ch; + cons->out_prod++; + + if ( cons->out_prod == ARRAY_SIZE(cons->out) - 1 + || ch == '\n' || ch == '\0' ) + ns8250_fifo_tx_reset(vdev); +} + +static bool cf_check ns8250_iir_check_lsi(struct vuart_ns8250 *vdev) +{ + return !!( vdev->regs[UART_LSR] & UART_LSR_MASK ); +} + +static bool cf_check ns8250_iir_check_rda(struct vuart_ns8250 *vdev) +{ + return !ns8250_fifo_rx_empty(vdev); +} + +static bool cf_check ns8250_iir_check_thr(struct vuart_ns8250 *vdev) +{ + return !!( vdev->flags & NS8250_IRQ_THRE_PENDING ); +} + +static bool cf_check ns8250_iir_check_msi(struct vuart_ns8250 *vdev) +{ + return !!( vdev->regs[UART_MSR] & UART_MSR_DELTA ); +} + +/* + * Interrupt identity reasons by priority. + * NB: highest priority are at lower indexes. + */ +static const struct { + uint8_t ier_mask; + uint8_t iir_mask; + bool (*iir_check)(struct vuart_ns8250 *vdev); +} iir_by_prio[] = { + [0] = { UART_IER_ELSI, UART_IIR_LSI, ns8250_iir_check_lsi }, + [1] = { UART_IER_ERDAI, UART_IIR_RDA, ns8250_iir_check_rda }, + [2] = { UART_IER_ETHREI, UART_IIR_THR, ns8250_iir_check_thr }, + [3] = { UART_IER_EMSI, UART_IIR_MSI, ns8250_iir_check_msi }, +}; + +/* + * Define the interrupt identity reason. + * NB: NS8250 always reports high priority events first. + */ +static uint8_t ns8250_irq_reason(struct vuart_ns8250 *vdev) +{ + int i; + + ASSERT( spin_is_locked(&vdev->lock) ); + for ( i = 0; i < ARRAY_SIZE(iir_by_prio); i++ ) + { + if ( (vdev->regs[UART_IER] & iir_by_prio[i].ier_mask) + && iir_by_prio[i].iir_check(vdev) ) + return iir_by_prio[i].iir_mask; + } + + return UART_IIR_NOINT; +} + +/* + * Assert virtual NS8250 interrupt line. + */ +static void ns8250_irq_assert(struct vuart_ns8250 *vdev) +{ + uint8_t iir; + + iir = ns8250_irq_reason(vdev); + if (iir & UART_IIR_NOINT) + hvm_irq_lower(vdev->owner, vdev->irq); + else + hvm_irq_raise(vdev->owner, vdev->irq); + + pr_debug("IRQ#%d %x %s\n", vdev->irq, iir, + !!(iir & UART_IIR_NOINT) ? "lower" : "raise"); +} + +/* + * Emulate 8-bit write access to NS8250 register. + */ +static int ns8250_io_write8( + struct vuart_ns8250 *vdev, uint32_t reg, uint8_t *data) +{ + uint8_t val; + int rc = 0; + + val = *data; + + switch ( reg ) + { + /* DLAB=0 */ + case UART_THR: + if ( vdev->regs[UART_MCR] & UART_MCR_LOOP ) + { + ns8250_fifo_rx_putchar(vdev, val); + vdev->regs[UART_LSR] |= UART_LSR_OE; + } + else + ns8250_fifo_tx_putchar(vdev, val); + + vdev->flags |= NS8250_IRQ_THRE_PENDING; + + break; + + case UART_IER: + if ( val & vdev->regs[UART_IER] & UART_IER_ETHREI ) + vdev->flags |= NS8250_IRQ_THRE_PENDING; + + vdev->regs[UART_IER] = val & UART_IER_MASK; + + break; + + case UART_FCR: /* WO */ + if ( val & UART_FCR_CLRX ) + ns8250_fifo_rx_reset(vdev); + + if ( val & UART_FCR_CLTX ) + ns8250_fifo_tx_reset(vdev); + + if ( !(val & UART_FCR_ENABLE) ) + val = 0; + + vdev->regs[UART_FCR] = val & (UART_FCR_ENABLE | + UART_FCR_DMA | + UART_FCR_TRG_MASK); + + break; + + case UART_LCR: + vdev->regs[UART_LCR] = val; + break; + + case UART_MCR: { + uint8_t msr_curr, msr_next, msr_delta; + + msr_curr = vdev->regs[UART_MSR]; + msr_next = 0; + msr_delta = 0; + + /* Set modem status */ + if ( val & UART_MCR_LOOP ) + { + if ( val & UART_MCR_DTR ) + msr_next |= UART_MSR_DSR; + if ( val & UART_MCR_RTS ) + msr_next |= UART_MSR_CTS; + if ( val & UART_MCR_OUT1 ) + msr_next |= UART_MSR_RI; + if ( val & UART_MCR_OUT2 ) + msr_next |= UART_MSR_DCD; + } + else + msr_next |= UART_MSR_DCD | UART_MSR_DSR | UART_MSR_CTS; + + /* Calculate changes in modem status */ + if ( (msr_curr & UART_MSR_CTS) ^ (msr_next & UART_MSR_CTS) ) + msr_delta |= UART_MSR_DCTS; + if ( (msr_curr & UART_MCR_RTS) ^ (msr_next & UART_MCR_RTS) ) + msr_delta |= UART_MSR_DDSR; + if ( (msr_curr & UART_MSR_RI) & (msr_next & UART_MSR_RI) ) + msr_delta |= UART_MSR_TERI; + if ( (msr_curr & UART_MSR_DCD) ^ (msr_next & UART_MSR_DCD) ) + msr_delta |= UART_MSR_DDCD; + + vdev->regs[UART_MCR] = val & UART_MCR_MASK; + vdev->regs[UART_MSR] = msr_next | msr_delta; + + break; + } + + case UART_LSR: /* RO */ + case UART_MSR: /* RO */ + rc = -EINVAL; + break; + + /* + * NB: Firmware like OVMF rely on SCR presence to initialize the ns8250 + * driver. + */ + case UART_SCR: + vdev->regs[UART_SCR] = val; + break; + + /* DLAB=1 */ + case UART_MAX + UART_DLL: + vdev->dl = (vdev->dl & 0xFF00U) | val; + break; + + case UART_MAX + UART_DLM: + vdev->dl = (val << 8) | (vdev->dl & 0x00FFU); + break; + + default: + rc = -EINVAL; + break; + } + + return rc; +} + +/* + * Emulate 16-bit write access to NS8250 register. + * NB: some guest OSes use outw() to access UART_DLL. + */ +static int ns8250_io_write16( + struct vuart_ns8250 *vdev, uint32_t reg, uint16_t *data) +{ + int rc; + + switch ( reg ) + { + case UART_MAX + UART_DLL: + vdev->dl = *data; + rc = 0; + break; + + default: + rc = -EINVAL; + break; + } + + return rc; +} + +/* + * Emulate write access to NS8250 register. + */ +static int ns8250_io_write( + struct vuart_ns8250 *vdev, uint8_t reg, uint32_t size, uint32_t *data) +{ + int rc = -EINVAL; + + switch ( size ) + { + case 1: + rc = ns8250_io_write8(vdev, reg, (uint8_t *)data); + break; + + case 2: + rc = ns8250_io_write16(vdev, reg, (uint16_t *)data); + break; + + default: + break; + } + + ns8250_irq_assert(vdev); + + return rc; +} + +/* + * Emulate 8-bit read access to NS8250 register. + */ +static int ns8250_io_read8( + struct vuart_ns8250 *vdev, uint32_t reg, uint8_t *data) +{ + int rc = 0; + uint8_t val; + + switch ( reg ) + { + /* DLAB=0 */ + case UART_RBR: + val = (uint8_t)ns8250_fifo_rx_getchar(vdev); + /* NB: do not forget to clear overrun condition */ + vdev->regs[UART_LSR] &= ~UART_LSR_OE; + break; + + case UART_IER: /* RO */ + val = vdev->regs[UART_IER]; + break; + + case UART_IIR: + val = ns8250_irq_reason(vdev); + if ( val & UART_IIR_THR ) + vdev->flags &= ~NS8250_IRQ_THRE_PENDING; + + if ( vdev->regs[UART_FCR] & UART_FCR_ENABLE ) + val |= UART_IIR_FE_MASK; + + break; + + case UART_LCR: + val = vdev->regs[UART_LCR]; + break; + + case UART_MCR: + val = vdev->regs[UART_MCR]; + break; + + case UART_LSR: + val = vdev->regs[UART_LSR] | UART_LSR_THRE | UART_LSR_TEMT; + if ( ns8250_fifo_rx_empty(vdev) ) + val &= ~UART_LSR_DR; + else + val |= UART_LSR_DR; + + vdev->regs[UART_LSR] = val & ~UART_LSR_MASK; + + break; + + case UART_MSR: + val = vdev->regs[UART_MSR]; + vdev->regs[UART_MSR] &= ~UART_MSR_DELTA; + break; + + case UART_SCR: + val = vdev->regs[UART_SCR]; + break; + + /* DLAB=1 */ + case UART_MAX + UART_DLL: + val = vdev->dl & 0xFFU; + break; + + case UART_MAX + UART_DLM: + val = vdev->dl >> 8; + break; + + default: + val = (uint8_t)io_access_mask[1]; + rc = -EINVAL; + break; + } + + *data = val; + + return rc; +} + +/* + * Emulate 16-bit read access to NS8250 register. + */ +static int ns8250_io_read16( + struct vuart_ns8250 *vdev, uint32_t reg, uint16_t *data) +{ + uint16_t val; + int rc; + + switch ( reg ) + { + case UART_MAX + UART_DLL: + val = vdev->dl; + rc = 0; + break; + + default: + val = (uint16_t)io_access_mask[2]; + rc = -EINVAL; + break; + } + + *data = val; + + return rc; +} + +/* + * Emulate read access to NS8250 register. + */ +static int ns8250_io_read( + struct vuart_ns8250 *vdev, uint8_t reg, uint32_t size, uint32_t *data) +{ + int rc; + + switch ( size ) + { + case 1: + rc = ns8250_io_read8(vdev, reg, (uint8_t *)data); + break; + + case 2: + rc = ns8250_io_read16(vdev, reg, (uint16_t *)data); + break; + + default: + *data = io_access_mask[size]; + rc = -EINVAL; + break; + } + + ns8250_irq_assert(vdev); + + return rc; +} + +static const char *ns8250_regname( + const struct vuart_ns8250 *vdev, uint32_t reg, int dir) +{ + static const char *reg_names[UART_MAX + 2][2] = { + /* register W R */ + [UART_RBR] = { "THR", "RBR" }, + [UART_IER] = { "IER", "IER" }, + [UART_IIR] = { "FCR", "IIR" }, + [UART_LCR] = { "LCR", "LCR" }, + [UART_MCR] = { "MCR", "MCR" }, + [UART_LSR] = { "LSR", "LSR" }, + [UART_MSR] = { "MSR", "MSR" }, + [UART_SCR] = { "SCR", "SCR" }, + [UART_MAX + UART_DLL] = { "DLL", "DLL" }, + [UART_MAX + UART_DLM] = { "DLM", "DLM" }, + }; + + return reg_names[reg][dir]; +} + +/* + * Emulate I/O access to NS8250 register. + */ +static int cf_check ns8250_io_handle( + int dir, unsigned int addr, unsigned int size, uint32_t *data) +{ +#define op(dir) (((dir) == IOREQ_WRITE) ? 'W' : 'R') + struct domain *d = rcu_lock_current_domain(); + struct vuart_ns8250 *vdev = &d->arch.hvm.vuart; + uint32_t offset, reg; + int rc; + + spin_lock(&vdev->lock); + + BUG_ON( vdev->owner != d ); + + if ( !(vdev->flags & NS8250_READY) ) + { + pr_err("%c io 0x%04x %d 0x%08"PRIx32": propagate to external I/O emulator\n", + op(dir), addr, size, *data); + rc = X86EMUL_UNHANDLEABLE; + goto out; + } + + reg = addr - vdev->io_addr; + BUG_ON( reg >= UART_MAX ); + if ( reg % size != 0 ) + { + pr_err("%c 0x%04x %d 0x%08"PRIx32": unaligned access\n", + op(dir), addr, size, *data & io_access_mask[size]); + rc = X86EMUL_OKAY; + goto out; + } + + /* Redirect access to divisor latch registers */ + if ( !!(vdev->regs[UART_LCR] & UART_LCR_DLAB) + && (reg == UART_DLL || reg == UART_DLM) ) + offset = UART_MAX + reg; + else + offset = reg; + + if ( dir == IOREQ_WRITE ) + { + pr_debug("%c 0x%04x %d 0x%08"PRIx32" %s[0x%02"PRIx32"]\n", + op(dir), addr, size, + *data & io_access_mask[size], + ns8250_regname(vdev, offset, dir), reg); + rc = ns8250_io_write(vdev, offset, size, data); + } + else + { + rc = ns8250_io_read(vdev, offset, size, data); + pr_debug("%c 0x%04x %d 0x%08"PRIx32" %s[0x%02"PRIx32"]\n", + op(dir), addr, size, + *data & io_access_mask[size], + ns8250_regname(vdev, offset, dir), reg); + } + if ( rc ) + pr_err("%c 0x%04x %d 0x%08"PRIx32": unsupported access\n", + op(dir), addr, size, *data & io_access_mask[size]); + rc = X86EMUL_OKAY; + +out: + spin_unlock(&vdev->lock); + + return rc; +#undef op +} + +/* + * Parse virtual NS8250 configuration. + * hvm.ns8250.console=[com1|com2|com3|com4] + */ +static const struct resource *ns8250_parse(void) +{ + int i; + + for ( i = 0; i < ARRAY_SIZE(ns8250_x86_legacy_uarts); i++ ) + if ( !strcasecmp(hvm_ns8250_console, ns8250_x86_legacy_uarts[i].name) ) + return ns8250_x86_legacy_uarts[i].res; + + return ns8250_x86_legacy_uarts[0].res; +} + +/* + * Claim virtual NS8250 resources to domain. + */ +static int ns8250_claim( + struct vuart_ns8250 *vdev, const struct resource *r, struct domain *d) +{ + unsigned long size; + unsigned long start; + unsigned long end; + + vdev->irq = NO_IRQ; + vdev->io_addr = IORESOURCE_UNKNOWN; + vdev->io_size = IORESOURCE_UNKNOWN; + + foreach_resource(r) + { + if ( r->type & IORESOURCE_IO ) + { + size = r->size; + start = r->addr; + end = r->addr + r->size - 1; + + if ( !ioports_access_permitted(d, start, end) ) + ioports_permit_access(d, start, end); + + register_portio_handler(d, start, size, ns8250_io_handle); + + /* Used to assert I/O port handler */ + vdev->io_addr = start; + vdev->io_size = size; + } + else if ( r->type & IORESOURCE_IRQ ) + /* "Claim" virtual IRQ; assumes no ISA-device IRQ sharing */ + vdev->irq = r->addr; + else + return -EINVAL; + } + + if ( vdev->irq == NO_IRQ + || vdev->io_addr == IORESOURCE_UNKNOWN + || vdev->io_size == IORESOURCE_UNKNOWN ) + return -ENODEV; + + return 0; +} + +/* + * Unclaim virtual NS8250 resources. + */ +static void ns8250_unclaim(struct vuart_ns8250 *vdev, struct domain *d) +{ + unsigned long size = vdev->io_size; + unsigned long start = vdev->io_addr; + unsigned long end = start + size - 1; + + if ( ioports_access_permitted(d, start, end) ) + ioports_deny_access(d, start, size); +} + +static int ns8250_init(struct domain *d, const struct resource *r) +{ + struct vuart_ns8250 *vdev = &d->arch.hvm.vuart; + struct xencons_interface *cons; + int rc; + + cons = _xzalloc(sizeof(*vdev->cons), sizeof(void *)); + if ( cons == NULL ) + return -ENOMEM; + + rc = ns8250_claim(vdev, r, d); + if ( rc ) + { + xfree(cons); + return rc; + } + + spin_lock_init(&vdev->lock); + hvm_irq_lower(d, vdev->irq); + + vdev->dl = (UART_CLOCK_HZ / 115200) >> 4; /* Report 115200 baud rate */ + vdev->cons = cons; + vdev->owner = d; + vdev->flags = NS8250_READY | NS8250_IRQ_THRE_PENDING; + + return 0; +} + +static void ns8250_exit(struct domain *d) +{ + struct vuart_ns8250 *vdev = &d->arch.hvm.vuart; + + spin_lock(&vdev->lock); + + if ( !(vdev->flags & NS8250_READY) ) + goto out; + + ns8250_unclaim(vdev, d); + ns8250_fifo_tx_reset(vdev); + xfree(vdev->cons); + + vdev->cons = NULL; + vdev->owner = NULL; + vdev->flags = 0; + +out: + spin_unlock(&vdev->lock); +} + +int vuart_putchar(struct vuart_ns8250 *vdev, char ch) +{ + int rc; + + spin_lock(&vdev->lock); + + if ( !(vdev->flags & NS8250_READY) ) + { + rc = -ENODEV; + goto out; + } + + /* Echo the user input on the console */ + printk("%c", ch); + + /* + * Device is in loopback mode; do nothing. + */ + if ( vdev->regs[UART_MCR] & UART_MCR_LOOP ) + { + rc = -EBUSY; + goto out; + } + + rc = ns8250_fifo_rx_putchar(vdev, ch); + if ( rc == -ENOSPC ) + vdev->regs[UART_LSR] |= UART_LSR_OE | UART_LSR_DR; + else + /* NB: UART_LSR_DR is also set when UART_LSR is accessed. */ + vdev->regs[UART_LSR] |= UART_LSR_DR; + + /* FIXME: check FCR when to fire an interrupt */ + ns8250_irq_assert(vdev); + +out: + spin_unlock(&vdev->lock); + + return rc; +} + +int domain_vuart_init(struct domain *d) +{ + struct vuart_ns8250 *vdev = &d->arch.hvm.vuart; + const struct resource *r; + + memset(vdev, 0, sizeof(*vdev)); + + r = ns8250_parse(); + if ( r != NULL ) + return ns8250_init(d, r); + + return -ENODEV; +} + +void domain_vuart_free(struct domain *d) +{ + ns8250_exit(d); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/include/asm/hvm/domain.h b/xen/arch/x86/include/asm/hvm/domain.h index 333501d5f2ac01676646b9b277b551f06d43c3a5..d4ce25896259fc9763477e88d56bacbe4f78af5b 100644 --- a/xen/arch/x86/include/asm/hvm/domain.h +++ b/xen/arch/x86/include/asm/hvm/domain.h @@ -16,6 +16,7 @@ #include #include #include +#include #ifdef CONFIG_MEM_SHARING struct mem_sharing_domain @@ -73,6 +74,10 @@ struct hvm_domain { struct hvm_vioapic **vioapic; unsigned int nr_vioapics; +#if defined(CONFIG_HAS_VUART_NS8250) + struct vuart_ns8250 vuart; +#endif + /* * hvm_hw_pmtimer is a publicly-visible name. We will defer renaming * it to the more appropriate hvm_hw_acpi until the expected diff --git a/xen/arch/x86/include/asm/hvm/vuart_ns8250.h b/xen/arch/x86/include/asm/hvm/vuart_ns8250.h new file mode 100644 index 0000000000000000000000000000000000000000..e1013751f955441a9089ea38c96c4605a7f4cb75 --- /dev/null +++ b/xen/arch/x86/include/asm/hvm/vuart_ns8250.h @@ -0,0 +1,75 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * NS8250-compatible UART Emulator. + */ +#if !defined(HVM__VUART_NS8250_H) +#define HVM__VUART_NS8250_H + +#include +#include +#include /* xencons_interface */ + +/* + * NS8250 emulator operational flags. + */ +enum { + /* Emulator is ready */ + NS8250_READY = BIT(0, U), + /* Trigger re-delivery of THRE interrupt */ + NS8250_IRQ_THRE_PENDING = BIT(1, U), +}; + +/* + * Virtual NS8250 device state. + */ +struct vuart_ns8250 { + uint16_t dl; /* Divisor Latch */ + uint8_t regs[UART_MAX]; /* Registers */ + uint32_t flags; /* Virtual device flags */ + uint64_t io_addr; /* Guest I/O region base address */ + uint64_t io_size; /* Guest I/O region size */ + int irq; /* Guest IRQ# */ + struct xencons_interface *cons; /* Emulated RX/TX FIFOs */ + struct domain *owner; /* Owner domain */ + spinlock_t lock; /* Protection */ +}; + +#if defined(CONFIG_HAS_VUART_NS8250) + +int vuart_putchar(struct vuart_ns8250 *vdev, char ch); + +/* + * Match the names w/ arch/arm/vuart.h + * FIXME: move to common vuart.h + */ +int domain_vuart_init(struct domain *d); +void domain_vuart_free(struct domain *d); + +#else + +static inline int vuart_putchar(struct vuart_ns8250 *vdev, char ch) +{ + return -1; +} + +static inline int domain_vuart_init(struct domain *d) +{ + return -ENODEV; +} + +static inline void domain_vuart_free(struct domain *d) +{ +} + +#endif /* #if defined(CONFIG_HAS_VUART_NS8250) */ + +#endif /* #if !defined(HVM__VUART_NS8250_H) */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Fri Dec 6 04:42:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896513 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1CF59E77173 for ; Fri, 6 Dec 2024 05:01:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849798.1264355 (Exim 4.92) (envelope-from ) id 1tJQTQ-0003bQ-0r; Fri, 06 Dec 2024 05:01:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849798.1264355; Fri, 06 Dec 2024 05:01:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQTP-0003bJ-Tq; Fri, 06 Dec 2024 05:01:51 +0000 Received: by outflank-mailman (input) for mailman id 849798; Fri, 06 Dec 2024 05:01:50 +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 1tJQA9-0004Ka-No for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:57 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 64608fcb-b38c-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 05:41:44 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C8AC75C72FD; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 6A760C4CEE0; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62D13E77179; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) 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: 64608fcb-b38c-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460099; bh=JVQCV0PI1+svIuRPhSKIXE4RQ76vQm0E6vam6EPtrcY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=W6lEgWydg2RAPebKAr16/tct2cGa72FS3Sam7Hdj1prK15nvWBh/GwfZ1GeWPxh7o b/M9RtuoMe+3OCo21F1efsSdMhKQxJlijnUvu5Uy0OAU9Gnt6jx+Q+jjs4pliIanGg RmCWD3kYhgZREq3GlEwSwSFDmaGNk4WsW2t3XC+CFKcs07uscaRG3/uh/WnpQL25cu 5BCgiNcqlb9vrr4aLImKUG7Pd4CehQqXhcBOZuei/WAymH78qrNNQ9rb1tSL9+W+2Y cLel7bfYxe+/5oNf7+TBJVZ9lN60RnD6b6xvEJ3f5pE5+6XZ5/8Z/5L6l9AKHx+UEp 5q+znPHry/3FQ== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:42:02 -0800 Subject: [PATCH v2 32/35] x86/hvm: add debugging facility to NS8250 UART emulator MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-32-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460095; l=5202; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=fA/jJbL46n/cnt80o0lruMDE2CrX4KhOfstGR8R1g3U=; b=iKpHnHA52J7NwfZnAJaaYuYval44oMyAoTpLRR63oT969Q6ILWC0DwKXqePHb5y1UuvSLSiJD tf8/iPi9W0YBRYqrwgNGNpvlhNKnoHkaE//16iIF3La5S0GB4zMmWcD X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Enable keyhandler mechanism for dumping state of emulated NS8250 on the console. Signed-off-by: Denis Mukhin --- xen/arch/x86/hvm/vuart_ns8250.c | 122 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/xen/arch/x86/hvm/vuart_ns8250.c b/xen/arch/x86/hvm/vuart_ns8250.c index 779dbd80d7be4e070ea9df3ae736ecdc662a527a..c8c75afaf2b2419d1dae999da1d1e400fd367791 100644 --- a/xen/arch/x86/hvm/vuart_ns8250.c +++ b/xen/arch/x86/hvm/vuart_ns8250.c @@ -25,6 +25,7 @@ /* Development debugging */ #define NS8250_LOG_LEVEL 0 +#undef NS8250_DEBUG #include #include @@ -35,6 +36,9 @@ #include #include #include +#if defined(NS8250_DEBUG) +#include +#endif #include /* console_input_domid() */ #include /* max_init_domid */ #include @@ -625,6 +629,121 @@ static const char *ns8250_regname( return reg_names[reg][dir]; } +#if defined(NS8250_DEBUG) +static void ns8250_dump(struct vuart_ns8250 *vdev) +{ + struct xencons_interface *cons = vdev->cons; + uint8_t val; + + printk("I/O port %02"PRIx64" IRQ %d flags %"PRIx32" owner %d\n", + vdev->io_addr, vdev->irq, + vdev->flags, vdev->owner->domain_id); + + printk("RX size %ld in_prod %d in_cons %d used %d\n", + sizeof(cons->in), + cons->in_prod, cons->in_cons, + cons->in_prod - cons->in_cons); + + printk("TX size %ld out_prod %d out_cons %d used %d\n", + sizeof(cons->out), + cons->out_prod, cons->out_cons, + cons->out_prod - cons->out_cons); + + printk("%02x RBR [ %c ] THR [ %c ] DLL %02x DLM %02x\n", + UART_RBR, + cons->in[MASK_XENCONS_IDX(cons->in_prod, cons)], + cons->out[MASK_XENCONS_IDX(cons->out_prod, cons)], + vdev->dl & 0xFFU, vdev->dl >> 8); + + printk("%02"PRIx8" IER %02"PRIx8"\n", UART_IER, vdev->regs[UART_IER]); + + val = (vdev->regs[UART_FCR] & UART_FCR_ENABLE) ? UART_IIR_FE_MASK : 0; + val |= ns8250_irq_reason(vdev); + printk("%02"PRIx8" FCR %02"PRIx8" IIR %02"PRIx8"\n", + UART_FCR, vdev->regs[UART_FCR], val); + + printk("%02"PRIx8" LCR %02"PRIx8"\n", UART_LCR, vdev->regs[UART_LCR]); + printk("%02"PRIx8" MCR %02"PRIx8"\n", UART_MCR, vdev->regs[UART_MCR]); + printk("%02"PRIx8" LSR %02"PRIx8"\n", UART_LSR, vdev->regs[UART_LSR]); + printk("%02"PRIx8" MSR %02"PRIx8"\n", UART_MSR, vdev->regs[UART_MSR]); +} + +static struct domain *rcu_find_first_domain_with_vuart(void) +{ + struct domain *d = NULL; + domid_t i; + + for ( i = 0; i < max_init_domid + 1; i++ ) + { + d = rcu_lock_domain_by_id(i); + if ( d == NULL ) + continue; + + if ( domain_has_vuart(d) ) + break; + + rcu_unlock_domain(d); + } + + return d; +} + +static void cf_check ns8250_keyhandler_show(unsigned char key) +{ + struct vuart_ns8250 *vdev; + struct domain *d; + + d = rcu_find_first_domain_with_vuart(); + if ( d == NULL ) + return; + + printk("'%c' pressed -> dumping virtual NS8250 state (d%d)\n", + key, d->domain_id); + + vdev = &d->arch.hvm.vuart; + spin_lock(&vdev->lock); + ns8250_dump(vdev); + spin_unlock(&vdev->lock); + + rcu_unlock_domain(d); +} + +static void cf_check ns8250_keyhandler_irq(unsigned char key) +{ + struct vuart_ns8250 *vdev; + struct domain *d; + + d = rcu_find_first_domain_with_vuart(); + if ( d == NULL ) + return; + + printk("'%c' pressed -> triggering IRQ on virtual NS8250 (d%d)\n", + key, d->domain_id); + + vdev = &d->arch.hvm.vuart; + spin_lock(&vdev->lock); + ns8250_irq_assert(vdev); + spin_unlock(&vdev->lock); + + rcu_unlock_domain(d); +} + +static void ns8250_keyhandler_init(void) +{ + register_keyhandler('1', ns8250_keyhandler_show, + "dump virtual NS8250 state", 0); + register_keyhandler('2', ns8250_keyhandler_irq, + "trigger IRQ from virtual NS8250", 0); +} +#else +static inline void ns8250_keyhandler_init(void) +{ +} +static inline void ns8250_dump(struct vuart_ns8250 *vdev) +{ +} +#endif /* #if defined(NS8250_DEBUG) */ + /* * Emulate I/O access to NS8250 register. */ @@ -688,6 +807,7 @@ static int cf_check ns8250_io_handle( rc = X86EMUL_OKAY; out: + ns8250_dump(vdev); spin_unlock(&vdev->lock); return rc; @@ -786,6 +906,7 @@ static int ns8250_init(struct domain *d, const struct resource *r) } spin_lock_init(&vdev->lock); + ns8250_keyhandler_init(); hvm_irq_lower(d, vdev->irq); vdev->dl = (UART_CLOCK_HZ / 115200) >> 4; /* Report 115200 baud rate */ @@ -852,6 +973,7 @@ int vuart_putchar(struct vuart_ns8250 *vdev, char ch) ns8250_irq_assert(vdev); out: + ns8250_dump(vdev); spin_unlock(&vdev->lock); return rc; From patchwork Fri Dec 6 04:42:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896502 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 03A75E77173 for ; Fri, 6 Dec 2024 04:51:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849579.1264245 (Exim 4.92) (envelope-from ) id 1tJQJL-0001ea-H5; Fri, 06 Dec 2024 04:51:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849579.1264245; Fri, 06 Dec 2024 04:51:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQJL-0001eL-DB; Fri, 06 Dec 2024 04:51:27 +0000 Received: by outflank-mailman (input) for mailman id 849579; Fri, 06 Dec 2024 04:51:25 +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 1tJQA6-0004Kb-0S for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:54 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 645bba61-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:43 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D40125C7332; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 7635CC4CED1; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EE1EE7717B; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) 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: 645bba61-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460099; bh=YfYCHh0nVVhyUMXcW2poOpCSgAUn/qfDmEJPr0RM4oY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=hLzR8gjhUR9ZFUJQotca4vwtdhYWQR4FQmZw4JZ9FrUQk3G0R+E/fXtA2T4uMxAvX OsCNkp0nm4UcV8js+vw6dyZaYIhRYqsnygSw1jnN7xcFiKOcyIfHyfURenDULiECwS iw62GTjHbFfm20AsCPNiyc+gpyuqC6zwnZ5Zt/C/LLHcapQkpERfhLFdrJM+2uyD6n sLBQFTdNnxReWackH13DdEFWaFllSrF9jBT7mk5HR+49vmESu/256p7BCRow9Laudz IG8GfzlznJNF3H8i0Kqsr8QAeBx0pis+myiRmmsIY2mTGOsgB4vb6NJyUh5yGivzc9 ZY5NF2Kkkr5OA== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:42:03 -0800 Subject: [PATCH v2 33/35] x86/domain: implement domain_has_vuart() MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-33-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460095; l=7401; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=tfiJLSOur1vSXiemSyjr8enIFIEF26fIRGrdEEwbY18=; b=VUVl57v6//L3I+BVOtYyFg49j9VIti9hgqIArW35Tvfb1KnFjpdoyqXsMGsyn7IqjVEgKnwMC PbyvHwuU4uVDf9Jg3XNoX0yzmMarqvvv+SMIcmGTCTCKalKac3WS555 X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Add new emulation flag for virtual UART on x86 and plumb it through the stack. This change enables NS8250 emulator initialization. Signed-off-by: Denis Mukhin --- tools/libs/light/libxl_x86.c | 6 +++++- tools/ocaml/libs/xc/xenctrl.ml | 1 + tools/ocaml/libs/xc/xenctrl.mli | 1 + tools/python/xen/lowlevel/xc/xc.c | 4 +--- xen/arch/x86/domain.c | 8 +++++--- xen/arch/x86/include/asm/domain.h | 7 ++++--- xen/include/public/arch-x86/xen.h | 14 +++++++++++++- 7 files changed, 30 insertions(+), 11 deletions(-) diff --git a/tools/libs/light/libxl_x86.c b/tools/libs/light/libxl_x86.c index a3164a3077fec7e1b81a34074894dc646954a49a..de5f05e18cb0671bb031b101b9a7159eb0fe0178 100644 --- a/tools/libs/light/libxl_x86.c +++ b/tools/libs/light/libxl_x86.c @@ -8,7 +8,11 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, { switch(d_config->c_info.type) { case LIBXL_DOMAIN_TYPE_HVM: - config->arch.emulation_flags = (XEN_X86_EMU_ALL & ~XEN_X86_EMU_VPCI); + config->arch.emulation_flags = XEN_X86_EMU_ALL; + config->arch.emulation_flags &= ~XEN_X86_EMU_VPCI; + /* Virtual UART is selected at Xen build time */ + config->arch.emulation_flags &= ~XEN_X86_EMU_VUART; + if (!libxl_defbool_val(d_config->b_info.u.hvm.pirq)) config->arch.emulation_flags &= ~XEN_X86_EMU_USE_PIRQ; break; diff --git a/tools/ocaml/libs/xc/xenctrl.ml b/tools/ocaml/libs/xc/xenctrl.ml index 2690f9a92316b812ad3d3ff0e1c36823070adb4a..647239b3e55e88b00eb8e9773a5267894cbbae54 100644 --- a/tools/ocaml/libs/xc/xenctrl.ml +++ b/tools/ocaml/libs/xc/xenctrl.ml @@ -47,6 +47,7 @@ type x86_arch_emulation_flags = | X86_EMU_PIT | X86_EMU_USE_PIRQ | X86_EMU_VPCI + | X86_EMU_VUART type x86_arch_misc_flags = | X86_MSR_RELAXED diff --git a/tools/ocaml/libs/xc/xenctrl.mli b/tools/ocaml/libs/xc/xenctrl.mli index febbe1f6ae3f10c5abe45eaa3c06a8a67d9ba268..4f5f64c786e83e8a0c3dd3cdb0460f7095de4a62 100644 --- a/tools/ocaml/libs/xc/xenctrl.mli +++ b/tools/ocaml/libs/xc/xenctrl.mli @@ -41,6 +41,7 @@ type x86_arch_emulation_flags = | X86_EMU_PIT | X86_EMU_USE_PIRQ | X86_EMU_VPCI + | X86_EMU_VUART type x86_arch_misc_flags = | X86_MSR_RELAXED diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c index 9feb12ae2b16e48cb5d0c3c45044ae226f152f2d..e54308956efc7061d58d2166ec9a95bc1dcd1781 100644 --- a/tools/python/xen/lowlevel/xc/xc.c +++ b/tools/python/xen/lowlevel/xc/xc.c @@ -159,9 +159,7 @@ static PyObject *pyxc_domain_create(XcObject *self, #if defined (__i386) || defined(__x86_64__) if ( config.flags & XEN_DOMCTL_CDF_hvm ) - config.arch.emulation_flags = XEN_X86_EMU_ALL & - ~(XEN_X86_EMU_VPCI | - XEN_X86_EMU_USE_PIRQ); + config.arch.emulation_flags = XEN_X86_EMU_HVM_ALLOWABLE; #elif defined (__arm__) || defined(__aarch64__) config.arch.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE; #else diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index c88d422a64544531c1e1058fa484364bb4277d1e..439da7adc92a3a8eb481075bf834da5f9670dd54 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -752,10 +752,10 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) if ( is_hardware_domain(d) && emflags != (X86_EMU_VPCI | X86_EMU_LAPIC | X86_EMU_IOAPIC) ) return false; + + emflags &= ~X86_EMU_VUART; if ( !is_hardware_domain(d) && - /* HVM PIRQ feature is user-selectable. */ - (emflags & ~X86_EMU_USE_PIRQ) != - (X86_EMU_ALL & ~(X86_EMU_VPCI | X86_EMU_USE_PIRQ)) && + xen_emflags_allowable(emflags) != XEN_X86_EMU_HVM_ALLOWABLE && emflags != X86_EMU_LAPIC ) return false; } @@ -806,6 +806,8 @@ int arch_domain_create(struct domain *d, emflags = config->arch.emulation_flags; + if ( IS_ENABLED(CONFIG_HAS_VUART_NS8250) && is_hvm_domain(d) ) + emflags |= XEN_X86_EMU_VUART; if ( is_hardware_domain(d) && is_pv_domain(d) ) emflags |= XEN_X86_EMU_PIT; diff --git a/xen/arch/x86/include/asm/domain.h b/xen/arch/x86/include/asm/domain.h index c1d0d1f47324e8cc678a4c76c43f86820a89e7b3..dacea6e1aad46e9f8710b2202bb81203c5e92807 100644 --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -484,7 +484,8 @@ struct arch_domain #define X86_EMU_VPCI 0 #endif -#define X86_EMU_PIT XEN_X86_EMU_PIT +#define X86_EMU_PIT XEN_X86_EMU_PIT +#define X86_EMU_VUART XEN_X86_EMU_VUART /* This must match XEN_X86_EMU_ALL in xen.h */ #define X86_EMU_ALL (X86_EMU_LAPIC | X86_EMU_HPET | \ @@ -492,7 +493,7 @@ struct arch_domain X86_EMU_IOAPIC | X86_EMU_PIC | \ X86_EMU_VGA | X86_EMU_IOMMU | \ X86_EMU_PIT | X86_EMU_USE_PIRQ | \ - X86_EMU_VPCI) + X86_EMU_VPCI | X86_EMU_VUART) #define has_vlapic(d) (!!((d)->arch.emulation_flags & X86_EMU_LAPIC)) #define has_vhpet(d) (!!((d)->arch.emulation_flags & X86_EMU_HPET)) @@ -507,7 +508,7 @@ struct arch_domain #define has_vpci(d) (!!((d)->arch.emulation_flags & X86_EMU_VPCI)) /* NB: same symbol as in Arm port */ -#define domain_has_vuart(d) false +#define domain_has_vuart(d) (!!((d)->arch.emulation_flags & X86_EMU_VUART)) #define gdt_ldt_pt_idx(v) \ ((v)->vcpu_id >> (PAGETABLE_ORDER - GDT_LDT_VCPU_SHIFT)) diff --git a/xen/include/public/arch-x86/xen.h b/xen/include/public/arch-x86/xen.h index fc2487986642a7694578ab9d2f5f16d09761bff8..e7922e3f9ddc1742a464d228807279839df31e52 100644 --- a/xen/include/public/arch-x86/xen.h +++ b/xen/include/public/arch-x86/xen.h @@ -283,13 +283,25 @@ struct xen_arch_domainconfig { #define XEN_X86_EMU_USE_PIRQ (1U<<_XEN_X86_EMU_USE_PIRQ) #define _XEN_X86_EMU_VPCI 10 #define XEN_X86_EMU_VPCI (1U<<_XEN_X86_EMU_VPCI) +#define _XEN_X86_EMU_VUART 11 +#define XEN_X86_EMU_VUART (1U<<_XEN_X86_EMU_VUART) #define XEN_X86_EMU_ALL (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET | \ XEN_X86_EMU_PM | XEN_X86_EMU_RTC | \ XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC | \ XEN_X86_EMU_VGA | XEN_X86_EMU_IOMMU | \ XEN_X86_EMU_PIT | XEN_X86_EMU_USE_PIRQ |\ - XEN_X86_EMU_VPCI) + XEN_X86_EMU_VPCI | XEN_X86_EMU_VUART) + +/* HVM PIRQ feature is user-selectable (libxl). */ +#define XEN_X86_EMU_HVM_SELECTABLE (XEN_X86_EMU_VPCI | \ + XEN_X86_EMU_USE_PIRQ | \ + XEN_X86_EMU_VUART) + +#define xen_emflags_allowable(x) ((x) & ~XEN_X86_EMU_HVM_SELECTABLE) + +#define XEN_X86_EMU_HVM_ALLOWABLE xen_emflags_allowable(XEN_X86_EMU_ALL) + uint32_t emulation_flags; /* From patchwork Fri Dec 6 04:42:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896498 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 559A6E77179 for ; Fri, 6 Dec 2024 04:50:34 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849541.1264205 (Exim 4.92) (envelope-from ) id 1tJQIN-0008Dq-H8; Fri, 06 Dec 2024 04:50:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849541.1264205; Fri, 06 Dec 2024 04:50:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQIN-0008Dj-EY; Fri, 06 Dec 2024 04:50:27 +0000 Received: by outflank-mailman (input) for mailman id 849541; Fri, 06 Dec 2024 04:50:27 +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 1tJQA5-0004Kb-0S for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:53 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 647d7eaa-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:43 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E48795C7334; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 8338AC4CEDE; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79E78E7717C; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) 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: 647d7eaa-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460099; bh=5gdanZ5e9+ASbcswvlhUW99s0NYH3AklpGAHEKCJ1yA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=l7F4swuxWLy7qWUlFubA5ZMzqX3UhKLqkhKI2ES3SfsXA7oVuy7mPcpmlOZK+Xc3t umwFJM4ukOQnfTR4JnynPnV9gDpo+kYhA76d7PnKd7Q9MOqDOFCjdu/R+hX/7scSWD 02cQ8Zx6irE4HWu+N4cq8Hsec+a9ICFctxj+iKhw7hFbLcQnQ8BC5TyUhj1gs2sSzX DX/l80YRZ6bgzT/qBVI5BOrEitV3dCQapg8+TYOXk520IMr3zMx7U3+EUBh/O3NUJ4 LI5F+P3jqqdf9SIH2mcGp0NKjy0b7baB/Kei8fCoCWR47lmyMz9lKwk43B1KUwx8Fx A14s8d/0EwjUA== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:42:04 -0800 Subject: [PATCH v2 34/35] xen/console: enable console owners w/ emulated NS8250 MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-34-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460095; l=1133; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=m+DZYhBfJNv2KVuFKRvMQy0kCP3iadnxj6rLAihix3M=; b=RacSKnwM5fBYuU8iskMZVZ/uehW76whDkeSjA2tP9mNGpXECzUNwGvJga6wsGA/b5LOBbFu5w EWu5DcHxADFDmrUml9OkGjTT4S3BA2zE90U1GzOO4ch9aJoZcj+SqBz X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Enable console focus for domains w/ virtual NS8250. Code change allows to capture the output from the guest OS now and send it to the physical console device. Signed-off-by: Denis Mukhin --- xen/drivers/char/console.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index a26daee9c4c4b1134d0ae3d105ffdb656340b6df..798dfdf3412a2feef35e72946d6c59bee59a9251 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -41,6 +41,9 @@ #ifdef CONFIG_SBSA_VUART_CONSOLE #include #endif +#if defined(CONFIG_HAS_VUART_NS8250) +#include +#endif /* console: comma-separated list of console outputs. */ static char __initdata opt_console[30] = OPT_CONSOLE_STR; @@ -627,6 +630,8 @@ static void handle_keypress_in_domain(struct domain *d, char c) { #if defined(CONFIG_SBSA_VUART_CONSOLE) rc = vpl011_rx_char_xen(d, c); +#elif defined(CONFIG_HAS_VUART_NS8250) + rc = vuart_putchar(&d->arch.hvm.vuart, c); #endif } /* From patchwork Fri Dec 6 04:42:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13896488 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D8CDEC3ABA0 for ; Fri, 6 Dec 2024 04:41:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.849419.1264107 (Exim 4.92) (envelope-from ) id 1tJQA4-0006xo-K5; Fri, 06 Dec 2024 04:41:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 849419.1264107; Fri, 06 Dec 2024 04:41:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJQA3-0006sO-Ra; Fri, 06 Dec 2024 04:41:51 +0000 Received: by outflank-mailman (input) for mailman id 849419; Fri, 06 Dec 2024 04:41:47 +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 1tJQ9y-0004Kb-WC for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 04:41:47 +0000 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 62e2a800-b38c-11ef-99a3-01e77a169b0f; Fri, 06 Dec 2024 05:41:41 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id C3801A43EE9; Fri, 6 Dec 2024 04:39:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 8FD2BC4CEDD; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 879A7E77179; Fri, 6 Dec 2024 04:41:39 +0000 (UTC) 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: 62e2a800-b38c-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733460099; bh=C4I0w8+5EC1wc6Fr7dK8Qf/iMDwJkx3ZOmN4HyH2Ud0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=qKYFw2l/moSm4D/CiV74R+PyKJbSHn30VRjrCUtepKwzcx8qdNvQpKemQ4AaQtLsv U/E3gB0mr/dPn0WffqoJMTR225fGoZuSl6vnE5nmutU5mKh6pA0lo7eGelK1FArqCu fotwvW5Pt7j809Yw7jNpfbAv1Fhb93HYN8kpKRzkXz2wUTuy+8T3hjPwwPbtXR9xk6 goyoI7XfLDcMy9ha4lpxlN3qZ24JA2sV2o5fhiuzB/j6XyEX+05MQ4/h4lNCXj0bx2 JhWkcEeGcb1BBWOoyn0KPrCzieXX4Ry1IVRP2BFuWdIkXo6tnVSWgInsY2KZC3B3dp 3RHRQnAeaf/Bg== From: Denis Mukhin via B4 Relay Date: Thu, 05 Dec 2024 20:42:05 -0800 Subject: [PATCH v2 35/35] docs/misc: update console documentation MIME-Version: 1.0 Message-Id: <20241205-vuart-ns8250-v1-35-e9aa923127eb@ford.com> References: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> In-Reply-To: <20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733460095; l=5686; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=APQcmog0xQYM3EBoFVE5ETu0ersksioDS4x/FBTt9bk=; b=fcukqs0MtpzP6GXP1AFPeyDh0mwVyYwNrAX1JE4Iad+84acEb8EnzftsWAW+Z/wvNGcrsuDbD /f1msBsXsXIBcTxHGqeGTmkklbg1oCypJQ1P8VwuGv9wF8UtrpSF+ZE X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Minor update related to virtual UART support. Also: s/pv/PV/g s/hvm/HVM/g Signed-off-by: Denis Mukhin --- docs/misc/console.txt | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/docs/misc/console.txt b/docs/misc/console.txt index 4e180f88ba1312d8fcc47d27622ec347d387ce12..7840729b0c95d9c4ea5295f17ce77c04177f48a5 100644 --- a/docs/misc/console.txt +++ b/docs/misc/console.txt @@ -4,11 +4,11 @@ Xen PV Console notes stefano.stabellini@eu.citrix.com -Xen traditionally provided a single pv console to pv guests, storing the +Xen traditionally provided a single PV console to PV guests, storing the relevant information in xenstore under /local/domain/$DOMID/console. -Now many years after the introduction of the pv console we have -multiple pv consoles support for pv and hvm guests; multiple pv +Now many years after the introduction of the PV console we have +multiple PV consoles support for PV and HVM guests; multiple PV console backends (qemu and xenconsoled, see limitations below) and emulated serial cards too. @@ -103,48 +103,50 @@ The supported values are only xenconsoled or ioemu; xenconsoled has several limitations: it can only be used for the first PV or virtual UART console and it can only connect to a pty. -Emulated serials are provided by qemu-dm only to hvm guests; the number -of emulated serials depends on how many "-serial" command line options -are given to qemu. The output of a serial is specified as argument to -the -serial command line option to qemu. Qemu writes the tty name to -xenstore in the following path: +Emulated serials are provided to HVM guests by qemu-dm or in-hypervisor UART +emulator (Xen needs to be re-compiled). + +In qemu-dm case, the number of emulated serials depends on how many "-serial" +command line options are given to qemu. The output of a serial is specified as +argument to the -serial command line option to qemu. Qemu writes the tty name +to xenstore in the following path: /local/domain/$DOMID/serial/$SERIAL_NUM/tty xenconsole is the tool to connect to a PV or virtual UART console or an emulated serial that has a pty as output. Xenconsole takes a domid as -parameter plus an optional console type (pv for PV consoles, vuart for -virtual UART or serial for emulated serials) and console number. +parameter plus an optional console type ('pv' for PV consoles, 'vuart' for +virtual UART or 'serial' for emulated serials) and console number. Depending on the type and console number, xenconsole will look for the tty node in different xenstore paths, as described above. If the user doesn't -specify the console type xenconsole will try to guess: if the guest is a pv -guest it defaults to PV console, if the guest is an hvm guest it defaults to +specify the console type xenconsole will try to guess: if the guest is a PV +guest it defaults to PV console, if the guest is an HVM guest it defaults to emulated serial. -By default xl creates a pv console for hvm guests, plus an emulated +By default xl creates a PV console for HVM guests, plus an emulated serial if the user specified 'serial = "pty"' in the VM config file. -Considering that xenconsole defaults to emulated serials for hvm guests, +Considering that xenconsole defaults to emulated serials for HVM guests, executing xl create -c "domain" causes xenconsole to attach to the emulated serial tty. This is most probably what the user wanted because -currently no bootloaders support xen pv consoles so the only way to +currently no bootloaders support xen PV consoles so the only way to interact with a bootloader like grub over a console is to use the emulated serial. -However the pv console is still easy to use with Linux PV on HVM guests: +However the PV console is still easy to use with Linux PV on HVM guests: the user just need to pass "console=hvc0" to the kernel command line and then execute "xl console -t pv " to connect to it. When using stubdoms the serial cards are still emulated by qemu (this time running in the stubdom), the number of serial cards and where the output goes is still specified using qemu command line options. -The difference is that for each emulated serial card there must be a pv +The difference is that for each emulated serial card there must be a PV console connection between the stubdom and dom0 to export the serial -output from the stubdom to dom0. The pv console backend for stubdom's pv -consoles is always ioemu because multiple pv consoles support is a -requirement in this case, considering that minios has its own pv console -too. In order to simplify the setup when using stubdoms the hvm guest -can only have one pv console with xenstored as backend (the stubdom -could provide pv console backends to the hvm guest but then it would -need another pv console connection for each console backend to export +output from the stubdom to dom0. The PV console backend for stubdom's PV +consoles is always ioemu because multiple PV consoles support is a +requirement in this case, considering that minios has its own PV console +too. In order to simplify the setup when using stubdoms the HVM guest +can only have one PV console with xenstored as backend (the stubdom +could provide PV console backends to the HVM guest but then it would +need another PV console connection for each console backend to export the pty to dom0). The xenconsole program supports a very simple protocol to notify parent about