From patchwork Mon Mar 27 10:09:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= X-Patchwork-Id: 13188992 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 D33AAC761AF for ; Mon, 27 Mar 2023 10:10:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.515118.797694 (Exim 4.92) (envelope-from ) id 1pgjnL-0005Wv-G5; Mon, 27 Mar 2023 10:09:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 515118.797694; Mon, 27 Mar 2023 10:09: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 1pgjnL-0005Wm-D8; Mon, 27 Mar 2023 10:09:43 +0000 Received: by outflank-mailman (input) for mailman id 515118; Mon, 27 Mar 2023 10:09: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 1pgjnK-0005WB-Lc for xen-devel@lists.xenproject.org; Mon, 27 Mar 2023 10:09:42 +0000 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7b41fa93-cc87-11ed-b464-930f4c7d94ae; Mon, 27 Mar 2023 12:09:40 +0200 (CEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 8B0805C00D2; Mon, 27 Mar 2023 06:09:37 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 27 Mar 2023 06:09:37 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 Mar 2023 06:09:36 -0400 (EDT) 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: 7b41fa93-cc87-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1679911777; x=1679998177; bh=1P t6XqRuvA6Th9hcIflc1psbelysDkFYRZ1fYTSdFk8=; b=YV3dOcV6/U9h5icRhn Pcy4iRo2Fazj+YZKFej5iUjPGl8gqo94BIVI3q7ARiSJk/HhgssUNnYvf2viGgJL kGLsTkhM/W9JuMJZssQnQHVmOJ6jvnABj4vY/Z3T7zcxNs1B1sJMnYmiqsrNxxY4 ylDrIobV45aDJEwUQqSsJTV4G+kc+1fQtDiovENZHKQqj3VceoToIxcGhJxbDm7a Vn5xb+PmK+fXBmF08TVRN12wWGdwtSKHWbTNdOOuyQdaiwVMt2LnzNy3IsOXfkLI W3xX4ZXwtgVCBcVNXYQLiePM1JVZosbQA0KOsHKJsIFpcnuyV6lxpo5KFYnFplN/ GsJQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1679911777; x=1679998177; bh=1Pt6XqRuvA6Th9hcIflc1psbelysDkFYRZ1 fYTSdFk8=; b=t3PYdUq9BQ35ZENiGBKpgRXgTk/lQmD9zOvJG1kJCp378ehNWqx hLCjlR6naSgeQh9ApcDqGhXDDkbLlp5PsiS+SG0CLWQESSpdoIliUz2c4ZgvHI1/ nnD66FnUlWr9Uu3pBJ4NaF6quPIzVAGPVmwvGdrREcVkHm3dXZy3mQ/CDqwtkOTs U37iuCGXzfloN9MEoqP/tZsNqioR3erJlKcCrXxMW8Lge7izyesglqrF+VnmC89/ j3SVBrOfHdzF36TsLBI4+jx2OLlXRsSFkDVh3BepunZhKek5nEQDyEWw6BBDstZe +yV8fYat+OVAsOSKf4CMi9qo6P7hiaZuhDg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehvddgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhggtgfgsehtkeertdertdejnecuhfhrohhmpeforghr vghkucforghrtgiihihkohifshhkihdqifpkrhgvtghkihcuoehmrghrmhgrrhgvkhesih hnvhhishhisghlvghthhhinhhgshhlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpefg ueduhefgvdefheehudejheefudevueeghfekhfehleegveduteeuiedugffgffenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmrghrmhgrrhgv khesihhnvhhishhisghlvghthhhinhhgshhlrggsrdgtohhm X-ME-Proxy: Feedback-ID: i1568416f:Fastmail From: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xenproject.org Cc: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH 2/2] drivers/char: Use sub-page ro API to make just xhci dbc cap RO Date: Mon, 27 Mar 2023 12:09:16 +0200 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 ... not the whole page, which may contain other registers too. In fact on Tiger Lake and newer (at least), this page do contain other registers that Linux tries to use. And with share=yes, a domU would use them too. Without this patch, PV dom0 would fail to initialize the controller, while HVM would be killed on EPT violation. Signed-off-by: Marek Marczykowski-Górecki --- xen/drivers/char/xhci-dbc.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/xen/drivers/char/xhci-dbc.c b/xen/drivers/char/xhci-dbc.c index 60b781f87202..df2524b0ca18 100644 --- a/xen/drivers/char/xhci-dbc.c +++ b/xen/drivers/char/xhci-dbc.c @@ -1226,9 +1226,43 @@ static void __init cf_check dbc_uart_init_postirq(struct serial_port *port) uart->dbc.xhc_dbc_offset), PFN_UP((uart->dbc.bar_val & PCI_BASE_ADDRESS_MEM_MASK) + uart->dbc.xhc_dbc_offset + - sizeof(*uart->dbc.dbc_reg)) - 1) ) - printk(XENLOG_INFO + sizeof(*uart->dbc.dbc_reg)) - 1) ) { + printk(XENLOG_WARNING "Error while adding MMIO range of device to mmio_ro_ranges\n"); + } + else + { + unsigned long dbc_regs_start = (uart->dbc.bar_val & + PCI_BASE_ADDRESS_MEM_MASK) + uart->dbc.xhc_dbc_offset; + unsigned long dbc_regs_end = dbc_regs_start + sizeof(*uart->dbc.dbc_reg); + + /* This being smaller than a page simplifies conditions below */ + BUILD_BUG_ON(sizeof(*uart->dbc.dbc_reg) >= PAGE_SIZE - 1); + if ( dbc_regs_start & (PAGE_SIZE - 1) || + PFN_DOWN(dbc_regs_start) == PFN_DOWN(dbc_regs_end) ) + { + if ( subpage_mmio_ro_add( + _mfn(PFN_DOWN(dbc_regs_start)), + dbc_regs_start & (PAGE_SIZE - 1), + PFN_DOWN(dbc_regs_start) == PFN_DOWN(dbc_regs_end) + ? dbc_regs_end & (PAGE_SIZE - 1) + : PAGE_SIZE - 1, + FIX_XHCI_END) ) + printk(XENLOG_WARNING + "Error while adding MMIO range of device to subpage_mmio_ro\n"); + } + if ( dbc_regs_end & (PAGE_SIZE - 1) && + PFN_DOWN(dbc_regs_start) != PFN_DOWN(dbc_regs_end) ) + { + if ( subpage_mmio_ro_add( + _mfn(PFN_DOWN(dbc_regs_end)), + 0, + dbc_regs_end & (PAGE_SIZE - 1), + FIX_XHCI_END + PFN_DOWN(sizeof(*uart->dbc.dbc_reg))) ) + printk(XENLOG_WARNING + "Error while adding MMIO range of device to subpage_mmio_ro\n"); + } + } #endif }