From patchwork Thu Feb 1 17:01:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13541448 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 7F479C4828D for ; Thu, 1 Feb 2024 17:02:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.674566.1049614 (Exim 4.92) (envelope-from ) id 1rVaS8-00076i-8K; Thu, 01 Feb 2024 17:02:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 674566.1049614; Thu, 01 Feb 2024 17:02:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rVaS8-00075f-3y; Thu, 01 Feb 2024 17:02:16 +0000 Received: by outflank-mailman (input) for mailman id 674566; Thu, 01 Feb 2024 17:02:15 +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 1rVaS7-0006n8-1s for xen-devel@lists.xenproject.org; Thu, 01 Feb 2024 17:02:15 +0000 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [2a00:1450:4864:20::52e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a5a8341b-c123-11ee-8a43-1f161083a0e0; Thu, 01 Feb 2024 18:02:14 +0100 (CET) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-55c2cf644f3so1537824a12.1 for ; Thu, 01 Feb 2024 09:02:14 -0800 (PST) Received: from localhost ([213.195.118.74]) by smtp.gmail.com with ESMTPSA id h29-20020a0564020e9d00b0055cfb3f948fsm7002015eda.76.2024.02.01.09.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 09:02:13 -0800 (PST) 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: a5a8341b-c123-11ee-8a43-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1706806933; x=1707411733; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gGkbw6NMRmq84Zwm3toJg408+YkNymy6A8aNzx/GF0M=; b=WOgFGmp4wAlVZe5KSBYm4fBKBfSBdlk357RV5UIFLOIru8f2k4iKop1hFKpyyOsv+m 9eTCf2nQTsmJtMbWPob3emXPsseqQ6Tyo163yfi79jv0fUyS3wXsaiHyRLTMkOknuix6 rwiZdvEC0MCUlF73TCII3pjH6o4OkGBu8gGoM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706806933; x=1707411733; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gGkbw6NMRmq84Zwm3toJg408+YkNymy6A8aNzx/GF0M=; b=cswMIbBaMh+zeqbZqHUXNVTRszQ443nA03LvhFWvvvdrPz+7u5FhMn9ElEF5O7XAhY NsqabZco3oqGMFhoIa6AZIRCFOiEIFGaw9R5ZlF363FYOotD1V+AowWPrYBABhgOx1cX Ynmv/s6cBqr6xeiaHQfYodbzV0oo3+lC1WmqruMjGhtNFlbA61YRdpnWcs6P8sPuzhGJ NCrKUcLu0pNAO8SFQj1U7rveKMimGICvyLGhEIiammNb05MdPw5zdq/oFNzGdlkDMNpY gVGZtX52SSktFTnMZDZoQG7kU7/+Pgn9iePeSiWp4ARmdFF5/Dh2ejC4hxr3cFDb/jFH J9ng== X-Gm-Message-State: AOJu0YwBWlLuUPfCz8KVb01b9ZfVFgLOn4NJ18wED09R4Zsrs+DS+hRs 3mAh+fFmYgXwT7bhvjaC3E+RnGzK2hdMnX7sSgZfUDXKVu57hSgiT2vzHx1C9hLTnb/r2mNRuiE M X-Google-Smtp-Source: AGHT+IGIMAX9xEfzp7fazur889a6R83N+pLnidiTerN578sP+ra2lpf0shXr+EPsnqASXyDum22iXA== X-Received: by 2002:aa7:d5c6:0:b0:55e:dcdf:50b0 with SMTP id d6-20020aa7d5c6000000b0055edcdf50b0mr3590001eds.15.1706806933771; Thu, 01 Feb 2024 09:02:13 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXa7/kBApDrW+9oLGL5JuXgqFjsL7REMMsbCNkqEymxKzmK6rPiWX8gjFOgJ9L8ciruSynzi2zHvP4pAUa5PQrrhSdSTpsLNI5FKIRo7qkN7zxWhxL5+OreNCiZeAN0U91XWHZnH50iqfzKV8M= From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , oxjo@proton.me Subject: [PATCH 1/4] amd-vi: fix IVMD memory type checks Date: Thu, 1 Feb 2024 18:01:56 +0100 Message-ID: <20240201170159.66330-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240201170159.66330-1-roger.pau@citrix.com> References: <20240201170159.66330-1-roger.pau@citrix.com> MIME-Version: 1.0 The current code that parses the IVMD blocks is relaxed with regard to the restriction that such unity regions should always fall into memory ranges marked as reserved in the memory map. However the type checks for the IVMD addresses are inverted, and as a result IVMD ranges falling into RAM areas are accepted. Note that having such ranges in the first place is a firmware bug, as IVMD should always fall into reserved ranges. Fixes: ed6c77ebf0c1 ('AMD/IOMMU: check / convert IVMD ranges for being / to be reserved') Signed-off-by: Roger Pau Monné Tested-by: oxjo Reviewed-by: Jan Beulich --- Cc: oxjo@proton.me --- xen/drivers/passthrough/amd/iommu_acpi.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/xen/drivers/passthrough/amd/iommu_acpi.c b/xen/drivers/passthrough/amd/iommu_acpi.c index 2e3b83014beb..ca70f4f3ae2c 100644 --- a/xen/drivers/passthrough/amd/iommu_acpi.c +++ b/xen/drivers/passthrough/amd/iommu_acpi.c @@ -426,9 +426,14 @@ static int __init parse_ivmd_block(const struct acpi_ivrs_memory *ivmd_block) return -EIO; } - /* Types which won't be handed out are considered good enough. */ - if ( !(type & (RAM_TYPE_RESERVED | RAM_TYPE_ACPI | - RAM_TYPE_UNUSABLE)) ) + /* + * Types which aren't RAM are considered good enough. + * Note that a page being partially RESERVED, ACPI or UNUSABLE will + * force Xen into assuming the whole page as having that type in + * practice. + */ + if ( type & (RAM_TYPE_RESERVED | RAM_TYPE_ACPI | + RAM_TYPE_UNUSABLE) ) continue; AMD_IOMMU_ERROR("IVMD: page at %lx can't be converted\n", addr); From patchwork Thu Feb 1 17:01:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13541451 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 03565C48292 for ; Thu, 1 Feb 2024 17:02:27 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.674567.1049630 (Exim 4.92) (envelope-from ) id 1rVaSB-0007ZD-G6; Thu, 01 Feb 2024 17:02:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 674567.1049630; Thu, 01 Feb 2024 17:02: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 1rVaSB-0007Z0-Cy; Thu, 01 Feb 2024 17:02:19 +0000 Received: by outflank-mailman (input) for mailman id 674567; Thu, 01 Feb 2024 17:02:18 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rVaS9-0007Wp-Vh for xen-devel@lists.xenproject.org; Thu, 01 Feb 2024 17:02:17 +0000 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [2a00:1450:4864:20::636]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a67f37fb-c123-11ee-98f5-efadbce2ee36; Thu, 01 Feb 2024 18:02:15 +0100 (CET) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a354408e6bfso393531766b.1 for ; Thu, 01 Feb 2024 09:02:15 -0800 (PST) Received: from localhost ([213.195.118.74]) by smtp.gmail.com with ESMTPSA id x13-20020aa7dacd000000b0055eb8830906sm5799854eds.85.2024.02.01.09.02.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 09:02:14 -0800 (PST) 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: a67f37fb-c123-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1706806935; x=1707411735; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LaBUruy8bPZuvsCRWTLi8TtvG3+zI8gmjxbPMfpVXBQ=; b=lQiuQocOtK++8BUqK7RASUFT0dAorXBb8lITr9CLEtfmLuXp2/rbXS91qk7twI26SL JIAcGZ05qTqkOMnc96G44qVKFmU6AKFHyje8haxM62B/2DavS9hQVSWRR5UMUiWyUeaU YTf2agBBCDfRsbqh3Z8x7R6BWq1q86pl4nG10= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706806935; x=1707411735; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LaBUruy8bPZuvsCRWTLi8TtvG3+zI8gmjxbPMfpVXBQ=; b=ZeKhbMKzxR5HrtUofWqxSMDR4ChAgQs4BI4K61PcZeQO1Lk2YEyi7oLn393Xi3WwGp TmRL4voIf0gJeoPqoYTxSJeaQhn8N6nkdUXKJDGvYDrtosYYmALkFpm3ZjOCAEhKIVHf rOmiIBeY0r38yHQia+JLApTVtp0yV2ELJAAzfIkJCv3gM0hck3JsCBqemLhZ+CXJN5Vi q9VJzUije0PIfZqGlqSe7lf1fG46QMgfyPYkGDpxVcbJqNhTde8hUlNBTaliog1IY6LH hKvEwVpudXlvXgKk4xkVgkISWVJ+vzCYB6m5CY9iMINYxAqCQiJ7YKagzc67cgJxQ2pJ jn/Q== X-Gm-Message-State: AOJu0YwCteBCGziwDdqJLCCbZQ/ql3230lBfKZiQ8UZCgG1VxeqNOAdQ L+/82K9Xch1H83pI86K+UhIAtX+NpJ7B8HYCMvRNkVtbfGDbHXipUNMQjkfIsGzrBh3ofOIClUf Z X-Google-Smtp-Source: AGHT+IGXtQwRJDikIm3QRBpY+NsFJJ2VzaJ8sihA2KkXMbRjVgXNsY2axsutk7Ypvh3WHZBEw62lBw== X-Received: by 2002:a17:907:20ee:b0:a36:83b6:385a with SMTP id rh14-20020a17090720ee00b00a3683b6385amr4052264ejb.7.1706806934981; Thu, 01 Feb 2024 09:02:14 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXz9y6qNecsuzFbhqWvYu586TWh1h6wyME4CUQvvl+rXnQoYcXO6n+vN0EpxXhLKl8Wiu3E8XwBAwUKxc2D8TZVTyBcQfdIoGy5xyisZNJMxu6cseqarQdNLbEAC101yEK4quN+35e9TF0/CLdY3xHpZRi1M43P From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu , Paul Durrant Subject: [PATCH 2/4] iommu/x86: introduce a generic IVMD/RMRR range validity helper Date: Thu, 1 Feb 2024 18:01:57 +0100 Message-ID: <20240201170159.66330-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240201170159.66330-1-roger.pau@citrix.com> References: <20240201170159.66330-1-roger.pau@citrix.com> MIME-Version: 1.0 IVMD and RMRR ranges are functionally equivalent, and as so could use the same validity checker. Move the IVMD to x86 common IOMMU code and adjust the function to take a pair of [start, end) mfn parameters. So far only the AMD-Vi side is adjusted to use the newly introduced helper, the VT-d side will be adjusted in a further change. No functional change intended. Signed-off-by: Roger Pau Monné --- xen/arch/x86/include/asm/iommu.h | 3 ++ xen/drivers/passthrough/amd/iommu_acpi.c | 38 ++------------------ xen/drivers/passthrough/x86/iommu.c | 46 ++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/xen/arch/x86/include/asm/iommu.h b/xen/arch/x86/include/asm/iommu.h index 15a848ddc329..5c7e37331aad 100644 --- a/xen/arch/x86/include/asm/iommu.h +++ b/xen/arch/x86/include/asm/iommu.h @@ -135,6 +135,9 @@ struct page_info *__must_check iommu_alloc_pgtable(struct domain_iommu *hd, uint64_t contig_mask); void iommu_queue_free_pgtable(struct domain_iommu *hd, struct page_info *pg); +/* Check [start, end) unity map range for correctness. */ +bool iommu_unity_region_ok(mfn_t start, mfn_t end); + #endif /* !__ARCH_X86_IOMMU_H__ */ /* * Local variables: diff --git a/xen/drivers/passthrough/amd/iommu_acpi.c b/xen/drivers/passthrough/amd/iommu_acpi.c index ca70f4f3ae2c..40468dbbccf3 100644 --- a/xen/drivers/passthrough/amd/iommu_acpi.c +++ b/xen/drivers/passthrough/amd/iommu_acpi.c @@ -405,41 +405,9 @@ static int __init parse_ivmd_block(const struct acpi_ivrs_memory *ivmd_block) return 0; } - if ( !e820_all_mapped(base, limit + PAGE_SIZE, E820_RESERVED) ) - { - paddr_t addr; - - AMD_IOMMU_WARN("IVMD: [%lx,%lx) is not (entirely) in reserved memory\n", - base, limit + PAGE_SIZE); - - for ( addr = base; addr <= limit; addr += PAGE_SIZE ) - { - unsigned int type = page_get_ram_type(maddr_to_mfn(addr)); - - if ( type == RAM_TYPE_UNKNOWN ) - { - if ( e820_add_range(addr, addr + PAGE_SIZE, - E820_RESERVED) ) - continue; - AMD_IOMMU_ERROR("IVMD: page at %lx couldn't be reserved\n", - addr); - return -EIO; - } - - /* - * Types which aren't RAM are considered good enough. - * Note that a page being partially RESERVED, ACPI or UNUSABLE will - * force Xen into assuming the whole page as having that type in - * practice. - */ - if ( type & (RAM_TYPE_RESERVED | RAM_TYPE_ACPI | - RAM_TYPE_UNUSABLE) ) - continue; - - AMD_IOMMU_ERROR("IVMD: page at %lx can't be converted\n", addr); - return -EIO; - } - } + if ( !iommu_unity_region_ok(maddr_to_mfn(base), + maddr_to_mfn(limit + PAGE_SIZE)) ) + return -EIO; if ( ivmd_block->header.flags & ACPI_IVMD_EXCLUSION_RANGE ) exclusion = true; diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/x86/iommu.c index c90755ff58fa..63d4cb898218 100644 --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -792,6 +792,52 @@ static int __init cf_check adjust_irq_affinities(void) } __initcall(adjust_irq_affinities); +bool __init iommu_unity_region_ok(mfn_t start, mfn_t end) +{ + mfn_t addr; + + if ( e820_all_mapped(mfn_to_maddr(start), mfn_to_maddr(end), + E820_RESERVED) ) + return true; + + printk(XENLOG_WARNING "IOMMU: [%#" PRI_mfn " ,%#" PRI_mfn + ") is not (entirely) in reserved memory\n", + mfn_x(start), mfn_x(end)); + + for ( addr = start; !mfn_eq(addr, end); mfn_add(addr, 1) ) + { + unsigned int type = page_get_ram_type(addr); + + if ( type == RAM_TYPE_UNKNOWN ) + { + if ( e820_add_range(mfn_to_maddr(addr), + mfn_to_maddr(addr) + PAGE_SIZE, E820_RESERVED) ) + continue; + printk(XENLOG_WARNING + "IOMMU: page at %#" PRI_mfn " couldn't be reserved\n", + mfn_x(addr)); + return false; + } + + /* + * Types which aren't RAM are considered good enough. + * Note that a page being partially RESERVED, ACPI or UNUSABLE will + * force Xen into assuming the whole page as having that type in + * practice. + */ + if ( type & (RAM_TYPE_RESERVED | RAM_TYPE_ACPI | + RAM_TYPE_UNUSABLE) ) + continue; + + printk(XENLOG_WARNING + "IOMMU: page at %#" PRI_mfn " can't be converted\n", + mfn_x(addr)); + return false; + } + + return true; +} + /* * Local variables: * mode: C From patchwork Thu Feb 1 17:01:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13541450 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 BA7BFC4828F for ; Thu, 1 Feb 2024 17:02:27 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.674568.1049635 (Exim 4.92) (envelope-from ) id 1rVaSB-0007c3-Rb; Thu, 01 Feb 2024 17:02:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 674568.1049635; Thu, 01 Feb 2024 17:02: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 1rVaSB-0007bP-N9; Thu, 01 Feb 2024 17:02:19 +0000 Received: by outflank-mailman (input) for mailman id 674568; Thu, 01 Feb 2024 17:02:18 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rVaSA-0007Wp-Lm for xen-devel@lists.xenproject.org; Thu, 01 Feb 2024 17:02:18 +0000 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [2a00:1450:4864:20::62f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a74d3c51-c123-11ee-98f5-efadbce2ee36; Thu, 01 Feb 2024 18:02:17 +0100 (CET) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a357cba4a32so159191166b.2 for ; Thu, 01 Feb 2024 09:02:17 -0800 (PST) Received: from localhost ([213.195.118.74]) by smtp.gmail.com with ESMTPSA id hw20-20020a170907a0d400b00a2b1a20e662sm7368698ejc.34.2024.02.01.09.02.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 09:02:15 -0800 (PST) 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: a74d3c51-c123-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1706806936; x=1707411736; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UloEpPKCM7G82luLru9QjRBa08XW6aQ69k/jBsglyGw=; b=rNbPd2z6k1d03ehIATXiBtiO+aDVtXpX4K5tQpGZmtFiq/LY33nsoVcRmKD21l4l8u RVHSWcClSRMdpzVLEl6yRSzyEahGvdjJMgPsEz4JJ0T7vk8igobml+QAm7bA/JVeCLmP UW19WIipZPnMk4+PmfysralqiLq5u9Xgz+YGE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706806936; x=1707411736; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UloEpPKCM7G82luLru9QjRBa08XW6aQ69k/jBsglyGw=; b=JdNWZsxBO+Ii5htEvhm/g9K3ti/lNh1/TeEFyDtlp/c76VXQNsVdvFcHF1682yz9Fy 0ytg4qj5QH2e9W530nE/pgjgswHrsxeFc6lup7r1ByKTFXK1aOfbLQbOJVahm9S+Rdvh 9ZCSbQn0LSrwk2Ys2zvHFFZM2q43S5Aej4bpWuVLQnOabtEABrixhQVKmEk21Ex3KMqz vKw/VwCuoktGVD2erjnMQHnHf6d0Y5HF8s9jpe5t1nVubAa7rHr/g+diz5KTOlYQ472Z U8MUPADt7tS9WUOCob0qsZHrD2o9BnzgePXOehC68OExvNdYZuBgbsCIeMV1g8Y4RPC+ b/dQ== X-Gm-Message-State: AOJu0Yx2UVHkzkWxaD7J+dNFsoc99iu9nfVxYTtKr+L+52B0XM+L29Tt bGdN7btVXhuun3TX/xHGZJzUlr8/N7Fseh3X+2ELZXWNc6aLIVdjUOzYg7kxmzxZUUGeMLQniIm w X-Google-Smtp-Source: AGHT+IE1ioEOtkHXIsPlEbxeCQ5KNW6gZONtNKo7ovJn0q0tGWZV/t+8E8s+EtazaGjUEAvRtXy5GA== X-Received: by 2002:a17:906:3515:b0:a36:2dc:1903 with SMTP id r21-20020a170906351500b00a3602dc1903mr2272370eja.68.1706806936197; Thu, 01 Feb 2024 09:02:16 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXRcHbpgIR2NyN9m6tWAgLtB7nbJPyYIh6UIkvdWkRs8hEq9Bn5Xp1NNCrN4gxyPsb4MxHHLpBB+H/4soWBdQS6v6r3gQ== From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Kevin Tian Subject: [PATCH 3/4] iommu/vt-d: switch to common RMRR checker Date: Thu, 1 Feb 2024 18:01:58 +0100 Message-ID: <20240201170159.66330-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240201170159.66330-1-roger.pau@citrix.com> References: <20240201170159.66330-1-roger.pau@citrix.com> MIME-Version: 1.0 Use the newly introduced generic unity map checker. Also drop the message recommending the usage of iommu_inclusive_mapping: the ranges would end up being mapped anyway even if some of the checks above failed, regardless of whether iommu_inclusive_mapping is set. Signed-off-by: Roger Pau Monné --- xen/drivers/passthrough/vtd/dmar.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/xen/drivers/passthrough/vtd/dmar.c b/xen/drivers/passthrough/vtd/dmar.c index 07772f178fe6..005b42706a34 100644 --- a/xen/drivers/passthrough/vtd/dmar.c +++ b/xen/drivers/passthrough/vtd/dmar.c @@ -642,17 +642,9 @@ acpi_parse_one_rmrr(struct acpi_dmar_header *header) return -EEXIST; } - /* This check is here simply to detect when RMRR values are - * not properly represented in the system memory map and - * inform the user - */ - if ( !e820_all_mapped(base_addr, end_addr + 1, E820_RESERVED) && - !e820_all_mapped(base_addr, end_addr + 1, E820_NVS) && - !e820_all_mapped(base_addr, end_addr + 1, E820_ACPI) ) - printk(XENLOG_WARNING VTDPREFIX - " RMRR [%"PRIx64",%"PRIx64"] not in reserved memory;" - " need \"iommu_inclusive_mapping=1\"?\n", - base_addr, end_addr); + if ( !iommu_unity_region_ok(maddr_to_mfn(base_addr), + maddr_to_mfn(end_addr + PAGE_SIZE)) ) + return -EIO; rmrru = xzalloc(struct acpi_rmrr_unit); if ( !rmrru ) From patchwork Thu Feb 1 17:01:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13541452 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 95493C48286 for ; Thu, 1 Feb 2024 17:02:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.674569.1049641 (Exim 4.92) (envelope-from ) id 1rVaSC-0007iL-98; Thu, 01 Feb 2024 17:02:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 674569.1049641; Thu, 01 Feb 2024 17:02:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rVaSC-0007gf-1Q; Thu, 01 Feb 2024 17:02:20 +0000 Received: by outflank-mailman (input) for mailman id 674569; Thu, 01 Feb 2024 17:02:18 +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 1rVaSA-0006n8-Nk for xen-devel@lists.xenproject.org; Thu, 01 Feb 2024 17:02:18 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a7ed1163-c123-11ee-8a43-1f161083a0e0; Thu, 01 Feb 2024 18:02:18 +0100 (CET) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a359e6fde44so123351766b.3 for ; Thu, 01 Feb 2024 09:02:18 -0800 (PST) Received: from localhost ([213.195.118.74]) by smtp.gmail.com with ESMTPSA id cu10-20020a170906ba8a00b00a36a94ecf9dsm1031214ejd.175.2024.02.01.09.02.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 09:02:17 -0800 (PST) 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: a7ed1163-c123-11ee-8a43-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1706806937; x=1707411737; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MrhtNQnEdn9vrYvKxplKdOmWw8AltePzlQHZOnCcYkE=; b=TREy726yqQyCNCvxbN4sQq49dv4v/hR85PC4SXyzmDbx1h2mFnLOECrsNCDdiUhhmA Ld82CPHRMEHkuQ/KXqx5wHuWO34L8VdvELZYW0kE0uU5eC+zvBcj6O7HEv3RUcfyTen0 ygEamOCONVXjYDzw4zJVfMpKvC/jhgpXEzVOg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706806937; x=1707411737; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MrhtNQnEdn9vrYvKxplKdOmWw8AltePzlQHZOnCcYkE=; b=NOdHIKklLmsUQEAdrffdW3Np4z0Z5HI7AW1xc5EDJ4Cotu+Nc3BNl7K4xOL8gxmRK2 gZtkq7C8N19sVf5PSJjnb88oHGSczinMOQGIj9IffGuJliVhnx16Jh6ATP5LX0adNyzA d9rmYZDMc+ao+eCpcGIiFO4N6FYeUw4gcCI/iwbochqGOBKQoIBfRbCUlzGHbKkw6hBE rXZVhDxTQhGtSaXgw1VjV1pR+xd6TzT+QuFnBXTJoz7/+NUCN7KkwxfucYk0FhY6asps 7C8gDHVwW9I6nJnOka95DYwDov6w+qo9SSeRp74Oe0lqLhefqlAQ6i4pVaaAK7dWlJxU MQiA== X-Gm-Message-State: AOJu0YxMKqYGTxHH1nPvzYQQxcwu3tFp3CEmaxX4VSrwQ9voInO55Sc+ 7VXj4NBEd9ENXor97/Jz67XFmxKP9BlApqhM88vfIOPZwAoe6RffUfNH6Tw2h46zk1YKwhGqMHz Z X-Google-Smtp-Source: AGHT+IGc7i6430H4QaIi3+LxQD/GqTuUYou2Jbiu1ErGblVAr8z1YC/aUC4MxNi18CobbC4sV1WzTA== X-Received: by 2002:a17:906:5f96:b0:a35:b7e6:1c44 with SMTP id a22-20020a1709065f9600b00a35b7e61c44mr4170204eju.75.1706806937437; Thu, 01 Feb 2024 09:02:17 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWf11yDgkYofRYjl5BKyx2LV56+rtBBpdJEdCgo5EHCP2ZvruGsNYEccw5XEHxjhlu/nPxBONNJtNXsvcabLciBZDfjnbZ8t8I6raIVlOXf From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Paul Durrant Subject: [PATCH 4/4] iommu/x86: make unity range checking more strict Date: Thu, 1 Feb 2024 18:01:59 +0100 Message-ID: <20240201170159.66330-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240201170159.66330-1-roger.pau@citrix.com> References: <20240201170159.66330-1-roger.pau@citrix.com> MIME-Version: 1.0 Currently when a unity range overlaps with memory being used as RAM by the hypervisor the result would be that the IOMMU gets disabled. However that's not enough, as even with the IOMMU disabled the device will still access the affected RAM areas. Note that IVMD or RMRR ranges being placed over RAM is a firmware bug. Doing so also allows to simplify the code and use a switch over the reported memory type(s). Signed-off-by: Roger Pau Monné --- xen/drivers/passthrough/x86/iommu.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/x86/iommu.c index 63d4cb898218..9b977f84582f 100644 --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -806,10 +806,14 @@ bool __init iommu_unity_region_ok(mfn_t start, mfn_t end) for ( addr = start; !mfn_eq(addr, end); mfn_add(addr, 1) ) { - unsigned int type = page_get_ram_type(addr); - - if ( type == RAM_TYPE_UNKNOWN ) + /* + * Any page that's at least partially of type RESERVED, UNUSABLE or + * ACPI will be considered by Xen of being all of that type, and hence + * the problematic pages are those that are fully holes or RAM. + */ + switch ( page_get_ram_type(addr) ) { + case RAM_TYPE_UNKNOWN: if ( e820_add_range(mfn_to_maddr(addr), mfn_to_maddr(addr) + PAGE_SIZE, E820_RESERVED) ) continue; @@ -817,7 +821,10 @@ bool __init iommu_unity_region_ok(mfn_t start, mfn_t end) "IOMMU: page at %#" PRI_mfn " couldn't be reserved\n", mfn_x(addr)); return false; - } + + case RAM_TYPE_CONVENTIONAL: + panic("IOMMU: page at %#" PRI_mfn " overlaps RAM range\n", + mfn_x(addr)); /* * Types which aren't RAM are considered good enough. @@ -825,14 +832,7 @@ bool __init iommu_unity_region_ok(mfn_t start, mfn_t end) * force Xen into assuming the whole page as having that type in * practice. */ - if ( type & (RAM_TYPE_RESERVED | RAM_TYPE_ACPI | - RAM_TYPE_UNUSABLE) ) - continue; - - printk(XENLOG_WARNING - "IOMMU: page at %#" PRI_mfn " can't be converted\n", - mfn_x(addr)); - return false; + } } return true;