From patchwork Mon Feb 5 13:55:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13545583 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 DE04FC4828D for ; Mon, 5 Feb 2024 13:55:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.676090.1051922 (Exim 4.92) (envelope-from ) id 1rWzRS-0005zJ-FW; Mon, 05 Feb 2024 13:55:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 676090.1051922; Mon, 05 Feb 2024 13:55:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWzRS-0005zC-D0; Mon, 05 Feb 2024 13:55:22 +0000 Received: by outflank-mailman (input) for mailman id 676090; Mon, 05 Feb 2024 13:55:20 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWzRQ-0005z2-IB for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 13:55:20 +0000 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [2a00:1450:4864:20::331]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 328309ed-c42e-11ee-8a45-1f161083a0e0; Mon, 05 Feb 2024 14:55:19 +0100 (CET) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40fdf2b69b2so431675e9.1 for ; Mon, 05 Feb 2024 05:55:19 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id s10-20020a05600c044a00b0040efc268713sm8570104wmb.26.2024.02.05.05.55.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Feb 2024 05:55:18 -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: 328309ed-c42e-11ee-8a45-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707141319; x=1707746119; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=xWCA/5RL2ARwAkMhUTOsGwspLyYaB9W2mN7GzM8E/nc=; b=VJAEkUsHmFp2LnhIGGi3MaJmXgKRWUeK98uD3HkkxOQkq2MWx8OGnPh7/tJt5nthNa EzZyJ2+WTXiIPMZorzEJOcN3iDgEqXmtb1wDrzsf4z3VKaGqIwVsYDCopffHV1H6J1YX 6ShcJ6RylYSVTzlZRq83Fs4buDGu6Ln9ni7K+HrUDzuFQKhaaF3MaCSIWUtO23aIGVOU gRJvwuU/ekwQUAw9zlcW+IKQ7NQ1bk95uxcjw4gUYLpCwB69oYESJWH8MjVume3p5CEu T1lC9v1Yrv43UXPMhmzhgemtT2XEhoJUhntO3QR+bg5Qo9OpaGUHIToWLTydtJ7QHGL2 FBfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707141319; x=1707746119; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xWCA/5RL2ARwAkMhUTOsGwspLyYaB9W2mN7GzM8E/nc=; b=H4giu3hRoqONnTbzSI1q5G3lDQVuEPCi3Yze4cw0ljz13CSoDfiaYAtnCIrxs+oeYW vx3q9HKz8qWVUeVIfEUFO8F7bBmD0vu6CVP7H+2EI/MrI4nyPUWUCxFJpVMIsqbLhIrQ /2fXc8B8W4FGEM3QMql3sa4Uf//+e0/fMml3/YktdzWkz17pOTrZ/jzFfcYldCxZMZmh 4liMdnFgGbzeq37pvwnHg7C3hZ9DB0DeycNfI6DSjiLszBpoCag/8hjofOT3tPDn2Uuu /bPKWzHsuEN+V23KhA1oTl/UU5t+MCpkHgdGZDzoBJlOh+Q8QCyxwGYlV4TXX9OCE2Ba KbRw== X-Gm-Message-State: AOJu0YwIcZ14sMMg2YgXiddho3snEKpJOTCXB/8E9C8WZlab9d19ISos sJJDQ0sDZc07oCMw4bG49MwFZPpWG5fDOMtmVwdkI72+nl6wOe+UoU0Jez6DE/czrU1JmCcbUMs = X-Google-Smtp-Source: AGHT+IE3Y6Nnj8BJo5oq8ZdSRhY8/K2PsXc/x8+2sF7Kx4VHPHvV8o+WE+HTnA9gj7y71d+JW8fk2A== X-Received: by 2002:a05:600c:19cb:b0:40e:cca6:d82f with SMTP id u11-20020a05600c19cb00b0040ecca6d82fmr4310954wmq.16.1707141318842; Mon, 05 Feb 2024 05:55:18 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCV0KkxzR5NiOqJ00N1ujGxrmv45Diry5WnCzIm0nWt87sZTJAC3qQhvKya64f9AKgujYygQZbdLBMFC6KdviRsZgBZDAkIrvrHxs7RBBdCus6Yj Message-ID: Date: Mon, 5 Feb 2024 14:55:17 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 1/7] VT-d: parse ACPI "SoC Integrated Address Translation Cache Reporting Structure"s Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Kevin Tian , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Paul Durrant References: <25506838-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lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <25506838-b818-4686-8c16-3a198338af44@suse.com> This is a prereq to us, in particular, respecting the "ATC required" flag. Signed-off-by: Jan Beulich --- Should we check scope entries for appropriate types? (If so, then also for e.g. ATSR.) --- a/xen/drivers/passthrough/vtd/dmar.c +++ b/xen/drivers/passthrough/vtd/dmar.c @@ -47,6 +47,7 @@ LIST_HEAD_READ_MOSTLY(acpi_drhd_units); LIST_HEAD_READ_MOSTLY(acpi_rmrr_units); static LIST_HEAD_READ_MOSTLY(acpi_atsr_units); static LIST_HEAD_READ_MOSTLY(acpi_rhsa_units); +static LIST_HEAD_READ_MOSTLY(acpi_satc_units); static struct acpi_table_header *__read_mostly dmar_table; static int __read_mostly dmar_flags; @@ -764,6 +765,95 @@ acpi_parse_one_rhsa(struct acpi_dmar_hea return ret; } +static int __init register_one_satc(struct acpi_satc_unit *satcu) +{ + bool ignore = false; + unsigned int i = 0; + int ret = 0; + + /* Skip checking if segment is not accessible yet. */ + if ( !pci_known_segment(satcu->segment) ) + i = UINT_MAX; + + for ( ; i < satcu->scope.devices_cnt; i++ ) + { + uint8_t b = PCI_BUS(satcu->scope.devices[i]); + uint8_t d = PCI_SLOT(satcu->scope.devices[i]); + uint8_t f = PCI_FUNC(satcu->scope.devices[i]); + + if ( pci_device_detect(satcu->segment, b, d, f) == 0 ) + { + dprintk(XENLOG_WARNING VTDPREFIX, + " Non-existent device (%pp) is reported in SATC scope!\n", + &PCI_SBDF(satcu->segment, b, d, f)); + ignore = true; + } + else + { + ignore = false; + break; + } + } + + if ( ignore ) + { + dprintk(XENLOG_WARNING VTDPREFIX, + " Ignore SATC for seg %04x as no device under its scope is PCI discoverable!\n", + satcu->segment); + scope_devices_free(&satcu->scope); + xfree(satcu); + return 1; + } + + if ( iommu_verbose ) + printk(VTDPREFIX " ATC required: %d\n", satcu->atc_required); + + list_add(&satcu->list, &acpi_satc_units); + + return ret; +} + +static int __init +acpi_parse_one_satc(const struct acpi_dmar_header *header) +{ + const struct acpi_dmar_satc *satc = + container_of(header, const struct acpi_dmar_satc, header); + struct acpi_satc_unit *satcu; + const void *dev_scope_start, *dev_scope_end; + int ret; + + if ( (ret = acpi_dmar_check_length(header, sizeof(*satc))) != 0 ) + return ret; + + satcu = xzalloc(struct acpi_satc_unit); + if ( !satcu ) + return -ENOMEM; + + satcu->segment = satc->segment; + satcu->atc_required = satc->flags & 1; + + dev_scope_start = (const void *)(satc + 1); + dev_scope_end = (const void *)satc + header->length; + ret = acpi_parse_dev_scope(dev_scope_start, dev_scope_end, + &satcu->scope, SATC_TYPE, satc->segment); + + if ( !ret && satcu->scope.devices_cnt ) + { + ret = register_one_satc(satcu); + /* + * register_one_satc() returns greater than 0 when a specified + * PCIe device cannot be detected. To prevent VT-d from being + * disabled in such cases, reset the return value to 0 here. + */ + if ( ret > 0 ) + ret = 0; + } + else + xfree(satcu); + + return ret; +} + static int __init cf_check acpi_parse_dmar(struct acpi_table_header *table) { struct acpi_table_dmar *dmar; @@ -817,6 +907,11 @@ static int __init cf_check acpi_parse_dm printk(VTDPREFIX "found ACPI_DMAR_RHSA:\n"); ret = acpi_parse_one_rhsa(entry_header); break; + case ACPI_DMAR_TYPE_SATC: + if ( iommu_verbose ) + printk(VTDPREFIX "found ACPI_DMAR_SATC:\n"); + ret = acpi_parse_one_satc(entry_header); + break; default: dprintk(XENLOG_WARNING VTDPREFIX, "Ignore unknown DMAR structure type (%#x)\n", --- a/xen/drivers/passthrough/vtd/dmar.h +++ b/xen/drivers/passthrough/vtd/dmar.h @@ -91,6 +91,13 @@ struct acpi_rhsa_unit { u32 proximity_domain; }; +struct acpi_satc_unit { + struct dmar_scope scope; + struct list_head list; + uint16_t segment; + bool atc_required:1; +}; + #define for_each_drhd_unit(drhd) \ list_for_each_entry(drhd, &acpi_drhd_units, list) @@ -106,6 +113,7 @@ struct acpi_atsr_unit *acpi_find_matched #define DMAR_TYPE 1 #define RMRR_TYPE 2 #define ATSR_TYPE 3 +#define SATC_TYPE 4 #define DMAR_OPERATION_TIMEOUT MILLISECS(1000) --- a/xen/include/acpi/actbl2.h +++ b/xen/include/acpi/actbl2.h @@ -345,7 +345,8 @@ enum acpi_dmar_type { ACPI_DMAR_TYPE_RESERVED_MEMORY = 1, ACPI_DMAR_TYPE_ATSR = 2, ACPI_DMAR_HARDWARE_AFFINITY = 3, - ACPI_DMAR_TYPE_RESERVED = 4 /* 4 and greater are reserved */ + ACPI_DMAR_TYPE_SATC = 5, + ACPI_DMAR_TYPE_RESERVED = 7 /* 7 and greater are reserved */ }; /* DMAR Device Scope structure */ @@ -427,6 +428,15 @@ struct acpi_dmar_rhsa { u32 proximity_domain; }; +/* 5: SOC Integrated Address Translation Cache Reporting Structure */ + +struct acpi_dmar_satc { + struct acpi_dmar_header header; + uint8_t flags; + uint8_t reserved; + uint16_t segment; +}; + /******************************************************************************* * * HPET - High Precision Event Timer table From patchwork Mon Feb 5 13:55:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13545584 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 4B5D1C4828D for ; Mon, 5 Feb 2024 13:55:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.676092.1051932 (Exim 4.92) (envelope-from ) id 1rWzRr-0006Tk-Nq; Mon, 05 Feb 2024 13:55:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 676092.1051932; Mon, 05 Feb 2024 13:55:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWzRr-0006Td-L9; Mon, 05 Feb 2024 13:55:47 +0000 Received: by outflank-mailman (input) for mailman id 676092; Mon, 05 Feb 2024 13:55: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 1rWzRq-0006TN-A8 for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 13:55:46 +0000 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [2a00:1450:4864:20::32e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 414c2133-c42e-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 14:55:44 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40fdc63f4feso6434175e9.3 for ; Mon, 05 Feb 2024 05:55:44 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id s10-20020a05600c044a00b0040efc268713sm8570104wmb.26.2024.02.05.05.55.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Feb 2024 05:55:43 -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: 414c2133-c42e-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707141343; x=1707746143; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=fiaRUGgpUjwp5AtuY8peqqWBSdls0Fsu1GdGBsfM0J0=; b=eVJT46VGTA5zY0j+N+7lUTSfJEJF5N+ILVOdLtfG798NGdusdZoAy8oyMSKpX6mX3V /U4gXWgR5y6DMljAdaJ6Az1ok8sIyIyPnc3MakSYaZkGbUHybmKFxXcFdfGTJb1KmfyD DUn6t/QYzGt55h8d1fDxFdBwyV+AZ94ZKwgjQ/7htqvvgCwNOHde3SMUzflJD69BUbHd rLB50gEXvr317eUGb6LXLPubG4aoTsE/2lcrdhqOF2eTta6SUG+27PAs1qbHgLGvIeoz pANfG3QrmVgPCVAIPNR88ydgTMfG+/w9ayV+LCiEMZLV7vgEYYw4pikNYdCME8Xm2660 L5Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707141343; x=1707746143; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fiaRUGgpUjwp5AtuY8peqqWBSdls0Fsu1GdGBsfM0J0=; b=qKvG+U+a6fYqLioPudPRDTq5D8d5XyInf6fFHhkWcTpofYKoE12TpRxJ9ammanz+Z8 Si7h8LRjF5LzZBh3EgfMTeYzpFCw6YwWzJNMFWwRQ5W1K1T5WPvE8oEJ41Y7JlIqDLHF cyoOTZMTYpewrNVPqTH+wnPCIOgafBwg0PL54HZmu19cv8dT08WsmmM26qMZz0kLPTF0 ElfeMsO2dk2VIqv9fH3gifIL+Shk5uRn2aiwnueQ/dITtzH4Jj3e43FM2pYlsEQM98Hc XzxAE89yR1vZGQT7FXiI6wKzZn7Kj3jA53mSTnlv2vrIsZJ2IBP88/zCTNLm7eFwlBeS i2fQ== X-Gm-Message-State: AOJu0YxFiEiaf9fIiljPkqntHCVQ5dXnn3qX2cC7a5SQVIrOnDTaq+A0 IOMJbtHDO2PF94RlhZUkJghA/mJfxUIW8EPY36/iOSdJWKUWjyVK109sjXk1ZKFNxifBluxlMFo = X-Google-Smtp-Source: AGHT+IEORSTwgdGzj2v6A6YK92N93MbcF4KbXz8hjo3fgBIdt/R1+qwm6YYcycVcpUYAr3uRdJSWWw== X-Received: by 2002:a05:600c:468a:b0:40f:ddfb:8c63 with SMTP id p10-20020a05600c468a00b0040fddfb8c63mr925331wmo.14.1707141343544; Mon, 05 Feb 2024 05:55:43 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWNBHAB6Fq63DmwP5Jnjt2xj3vsjpWCfO13NCh26JGNny+nQbAl/7wbKI2lKWrAo7ls4iR5fWVA/Aushpl52rZqsqqvB7mshRL8KOonoXrYWPQwDDOu17Oy8/aLXiFzSA6m7dtUM5sdbO5rLsRk Message-ID: <467d24e1-8ed3-4dda-a334-70ff747bf94b@suse.com> Date: Mon, 5 Feb 2024 14:55:43 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 2/7] IOMMU: rename and re-type ats_enabled Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Kevin Tian , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Paul Durrant , Andrew Cooper References: <25506838-b818-4686-8c16-3a198338af44@suse.com> Autocrypt: addr=jbeul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xv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <25506838-b818-4686-8c16-3a198338af44@suse.com> Make the variable a tristate, with (as done elsewhere) a negative value meaning "default". Since all use sites need looking at, also rename it to match our usual "opt_*" pattern. While touching it, also move it to .data.ro_after_init. The only place it retains boolean nature is pci_ats_device(), for now. In AMD code re-order conditionals to have the config space accesses after (cheaper) flag checks. Signed-off-by: Jan Beulich --- In domain_context_mapping_one() I'm a little puzzled that translation type is selected based on only IOMMU and global properties, i.e. not taking the device itself into account. --- a/xen/drivers/passthrough/amd/iommu_cmd.c +++ b/xen/drivers/passthrough/amd/iommu_cmd.c @@ -282,7 +282,7 @@ void amd_iommu_flush_iotlb(u8 devfn, con struct amd_iommu *iommu; unsigned int req_id, queueid, maxpend; - if ( !ats_enabled ) + if ( opt_ats <= 0 ) return; if ( !pci_ats_enabled(pdev->seg, pdev->bus, pdev->devfn) ) @@ -340,7 +340,7 @@ static void _amd_iommu_flush_pages(struc flush_command_buffer(iommu, 0); } - if ( ats_enabled ) + if ( opt_ats > 0 ) { amd_iommu_flush_all_iotlbs(d, daddr, order); --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -185,10 +185,11 @@ static int __must_check amd_iommu_setup_ dte->ex = ivrs_dev->dte_allow_exclusion; dte->sys_mgt = MASK_EXTR(ivrs_dev->device_flags, ACPI_IVHD_SYSTEM_MGMT); - if ( pci_ats_device(iommu->seg, bus, pdev->devfn) && + if ( opt_ats > 0 && !ivrs_dev->block_ats && - iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) ) - dte->i = ats_enabled; + iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) && + pci_ats_device(iommu->seg, bus, pdev->devfn) ) + dte->i = true; spin_unlock_irqrestore(&iommu->lock, flags); @@ -248,10 +249,11 @@ static int __must_check amd_iommu_setup_ ASSERT(dte->sys_mgt == MASK_EXTR(ivrs_dev->device_flags, ACPI_IVHD_SYSTEM_MGMT)); - if ( pci_ats_device(iommu->seg, bus, pdev->devfn) && + if ( opt_ats > 0 && !ivrs_dev->block_ats && - iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) ) - ASSERT(dte->i == ats_enabled); + iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) && + pci_ats_device(iommu->seg, bus, pdev->devfn) ) + ASSERT(dte->i); spin_unlock_irqrestore(&iommu->lock, flags); @@ -268,9 +270,10 @@ static int __must_check amd_iommu_setup_ ASSERT(pcidevs_locked()); - if ( pci_ats_device(iommu->seg, bus, pdev->devfn) && + if ( opt_ats > 0 && !ivrs_dev->block_ats && iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) && + pci_ats_device(iommu->seg, bus, pdev->devfn) && !pci_ats_enabled(iommu->seg, bus, pdev->devfn) ) { if ( devfn == pdev->devfn ) --- a/xen/drivers/passthrough/ats.c +++ b/xen/drivers/passthrough/ats.c @@ -18,8 +18,8 @@ #include #include "ats.h" -bool __read_mostly ats_enabled; -boolean_param("ats", ats_enabled); +int8_t __ro_after_init opt_ats = -1; +boolean_param("ats", opt_ats); int enable_ats_device(struct pci_dev *pdev, struct list_head *ats_list) { --- a/xen/drivers/passthrough/ats.h +++ b/xen/drivers/passthrough/ats.h @@ -22,7 +22,7 @@ #define ATS_QUEUE_DEPTH_MASK 0x1f #define ATS_ENABLE (1<<15) -extern bool ats_enabled; +extern int8_t opt_ats; int enable_ats_device(struct pci_dev *pdev, struct list_head *ats_list); void disable_ats_device(struct pci_dev *pdev); @@ -43,7 +43,7 @@ static inline int pci_ats_enabled(int se static inline int pci_ats_device(int seg, int bus, int devfn) { - if ( !ats_enabled ) + if ( !opt_ats ) return 0; return pci_find_ext_capability(PCI_SBDF(seg, bus, devfn), --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -1543,7 +1543,7 @@ int domain_context_mapping_one( } context_set_address_root(lctxt, root); - if ( ats_enabled && ecap_dev_iotlb(iommu->ecap) ) + if ( opt_ats > 0 && ecap_dev_iotlb(iommu->ecap) ) context_set_translation_type(lctxt, CONTEXT_TT_DEV_IOTLB); else context_set_translation_type(lctxt, CONTEXT_TT_MULTI_LEVEL); --- a/xen/drivers/passthrough/vtd/x86/ats.c +++ b/xen/drivers/passthrough/vtd/x86/ats.c @@ -46,7 +46,7 @@ int ats_device(const struct pci_dev *pde struct acpi_drhd_unit *ats_drhd; int pos; - if ( !ats_enabled || !iommu_qinval ) + if ( opt_ats <= 0 || !iommu_qinval ) return 0; if ( !ecap_queued_inval(drhd->iommu->ecap) || From patchwork Mon Feb 5 13:56:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13545585 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 2B926C4828D for ; Mon, 5 Feb 2024 13:56:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.676094.1051943 (Exim 4.92) (envelope-from ) id 1rWzSL-0006yr-23; Mon, 05 Feb 2024 13:56:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 676094.1051943; Mon, 05 Feb 2024 13:56:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWzSK-0006yk-UX; Mon, 05 Feb 2024 13:56:16 +0000 Received: by outflank-mailman (input) for mailman id 676094; Mon, 05 Feb 2024 13:56:16 +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 1rWzSK-0005z2-EW for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 13:56:16 +0000 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [2a00:1450:4864:20::333]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 53ff4ee0-c42e-11ee-8a45-1f161083a0e0; Mon, 05 Feb 2024 14:56:15 +0100 (CET) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40fdc63f4feso6439345e9.3 for ; Mon, 05 Feb 2024 05:56:15 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id s10-20020a05600c044a00b0040efc268713sm8570104wmb.26.2024.02.05.05.56.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Feb 2024 05:56: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: 53ff4ee0-c42e-11ee-8a45-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707141375; x=1707746175; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=f3H4Ur0/gJhZeUF8ayz9NPkqLMEexvZyofs8rqJKkAY=; b=bnk6Ne5TkNLQlBI/EGNGIGMrB5XCMSXlaXx22raY7a4IrIFUVjhLevhHDdQycULtPk IrSRqXifhqn+NPcoeRWCzIMLXiV92mu5XmW44eeAPv4EbMKDQ1939kvRzIzR5NwPOsC/ L4p58qwUOHRzCLbf8ltHvvUfC6PMRavRVGFsWz6O23LtjarWSlZ2Vx5NRWKbY7zVea0V RvUMbD6Oj4z9lzpIISwB4RM+dbKwYgBQdZh9RDa3YdyWpK2NtZHcQqIAtriMVQL1AcRA j3sc4h7pURDYTtoPiPSnsDMP67zGZb11bgvPnexBhMWU5kA9BpJHy6G7RrG01wjP0Gtk cmOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707141375; x=1707746175; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=f3H4Ur0/gJhZeUF8ayz9NPkqLMEexvZyofs8rqJKkAY=; b=lMyYoMg/mEs4zKlpgb/ZzjN2+7tNhH6gpNoK++2MdrUuIs2EKM+7nchyIBfbfDlOk8 kllICMOzINyzCwCoCmnxF3q8Q/t3HjYQanOE7H0Z4jn5NOisVMHg7ZVYZ2bItKHV1qRT 02mhP9zbNZ1pSL7JkE+Bx5ZqUHiIPB8ggkRLBnpzkqjV0Yakbt6uH11ei5Tt7PSX/qfQ FPK1v6uYoHGKxfj5At8uL4fg1Sg4zFz1jPo5qLZpGgG6gnZVSSRQy0YOnqRXqo40PlSA w8XYl1UhFuwJgnnnSgCJq6JWOECNMNHUHZxLS+s9/5qfhH0787NAcmpls8A3wNpYZhzM ajjg== X-Gm-Message-State: AOJu0YwMniZxxgNRlaWLZUQsTvCHHdCSK1s2eo73a7xd9N0rK2PHOS6O 7VkYKlY5rxgAGbkrNofPqXCeY6yJfUwIRvP6PoIItPi5bYkkFXI2iEGF9NQwYwfu80q904B93Wo = X-Google-Smtp-Source: AGHT+IHKs0cihTxNqeV8nuhiv1fHgALzE+NMfvV0hATXeqzhpcrCBAjxfZRCmqp2eFQgxjF23ijOOg== X-Received: by 2002:a05:600c:3583:b0:40e:bfbf:f368 with SMTP id p3-20020a05600c358300b0040ebfbff368mr5255342wmq.2.1707141375004; Mon, 05 Feb 2024 05:56:15 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUdLl+7bK14Slxd41prmGWLqlG/OLqz6/Vf8MXC/p7KCgrx7cXUy6+eZgWOqDWZdfbp3o7Qsc8XLekPoLOzpEICNsAlr8BUdGVvywCVVBMC9Ynf Message-ID: <72496fb7-8835-4d45-bd92-7e7d612861c7@suse.com> Date: Mon, 5 Feb 2024 14:56:14 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 3/7] VT-d: respect ACPI SATC's ATC_REQUIRED flag Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Kevin Tian , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Paul Durrant References: <25506838-b818-4686-8c16-3a198338af44@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJY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xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <25506838-b818-4686-8c16-3a198338af44@suse.com> When the flag is set, permit Dom0 to control the device (no worse than what we had before and in line with other "best effort" behavior we use when it comes to Dom0), but suppress passing through to DomU-s unless ATS can actually be enabled for such devices. Signed-off-by: Jan Beulich --- Is ats_device() using acpi_find_matched_atsr_unit() unconditionally actually correct? Shouldn't that check be skipped for root complex integrated devices? --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -225,7 +225,10 @@ exceptions (watchdog NMIs and unexpected > Default: `false` Permits Xen to set up and use PCI Address Translation Services. This is a -performance optimisation for PCI Passthrough. +performance optimisation for PCI Passthrough. Note that firmware may indicate +that certain devices need to have ATS enabled for proper operation. For such +devices ATS will be enabled by default, unless the option is used in its +negative form. **WARNING: Xen cannot currently safely use ATS because of its synchronous wait loops for Queued Invalidation completions.** --- a/xen/drivers/passthrough/vtd/dmar.c +++ b/xen/drivers/passthrough/vtd/dmar.c @@ -254,6 +254,24 @@ struct acpi_atsr_unit *acpi_find_matched return all_ports; } +const struct acpi_satc_unit *acpi_find_matched_satc_unit( + const struct pci_dev *pdev) +{ + const struct acpi_satc_unit *satc; + + list_for_each_entry ( satc, &acpi_satc_units, list ) + { + if ( satc->segment != pdev->seg ) + continue; + + for ( unsigned int i = 0; i < satc->scope.devices_cnt; ++i ) + if ( satc->scope.devices[i] == pdev->sbdf.bdf ) + return satc; + } + + return NULL; +} + struct acpi_rhsa_unit *drhd_to_rhsa(const struct acpi_drhd_unit *drhd) { struct acpi_rhsa_unit *rhsa; --- a/xen/drivers/passthrough/vtd/dmar.h +++ b/xen/drivers/passthrough/vtd/dmar.h @@ -109,6 +109,8 @@ struct acpi_satc_unit { struct acpi_drhd_unit *acpi_find_matched_drhd_unit(const struct pci_dev *); struct acpi_atsr_unit *acpi_find_matched_atsr_unit(const struct pci_dev *); +const struct acpi_satc_unit *acpi_find_matched_satc_unit( + const struct pci_dev *pdev); #define DMAR_TYPE 1 #define RMRR_TYPE 2 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -2364,6 +2364,25 @@ static int cf_check intel_iommu_add_devi if ( ret ) dprintk(XENLOG_ERR VTDPREFIX, "%pd: context mapping failed\n", pdev->domain); + else if ( !pdev->broken ) + { + const struct acpi_drhd_unit *drhd = acpi_find_matched_drhd_unit(pdev); + const struct acpi_satc_unit *satc = acpi_find_matched_satc_unit(pdev); + + /* + * Prevent the device from getting assigned to an unprivileged domain + * when firmware indicates ATS is required, but ATS could not be enabled + * (e.g. because of being suppressed via command line option). + */ + if ( satc && satc->atc_required && + (!drhd || ats_device(pdev, drhd) <= 0 || + !pci_ats_enabled(pdev->seg, pdev->bus, pdev->devfn)) ) + { + printk(XENLOG_WARNING "ATS: %pp is not eligible for pass-through\n", + &pdev->sbdf); + pdev->broken = true; + } + } return ret; } @@ -2375,12 +2394,27 @@ static int cf_check intel_iommu_enable_d pci_vtd_quirk(pdev); - if ( ret <= 0 ) - return ret; + if ( ret <= 0 || + (ret = enable_ats_device(pdev, &drhd->iommu->ats_devices)) < 0 ) + { + const struct acpi_satc_unit *satc = acpi_find_matched_satc_unit(pdev); + + /* + * Prevent the device from getting assigned to an unprivileged domain + * when firmware indicates ATS is required, but ATS use was disabled + * via command line option. + */ + if ( satc && satc->atc_required && !pdev->broken ) + { + printk(XENLOG_WARNING "ATS: %pp is not eligible for pass-through\n", + &pdev->sbdf); + pdev->broken = true; + } - ret = enable_ats_device(pdev, &drhd->iommu->ats_devices); + return ret; + } - return ret >= 0 ? 0 : ret; + return 0; } static int cf_check intel_iommu_remove_device(u8 devfn, struct pci_dev *pdev) --- a/xen/drivers/passthrough/vtd/x86/ats.c +++ b/xen/drivers/passthrough/vtd/x86/ats.c @@ -44,9 +44,10 @@ struct acpi_drhd_unit *find_ats_dev_drhd int ats_device(const struct pci_dev *pdev, const struct acpi_drhd_unit *drhd) { struct acpi_drhd_unit *ats_drhd; + const struct acpi_satc_unit *satc; int pos; - if ( opt_ats <= 0 || !iommu_qinval ) + if ( !opt_ats || !iommu_qinval ) return 0; if ( !ecap_queued_inval(drhd->iommu->ecap) || @@ -56,6 +57,10 @@ int ats_device(const struct pci_dev *pde if ( !acpi_find_matched_atsr_unit(pdev) ) return 0; + satc = acpi_find_matched_satc_unit(pdev); + if ( opt_ats < 0 && (!satc || !satc->atc_required) ) + return 0; + ats_drhd = find_ats_dev_drhd(drhd->iommu); pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS); From patchwork Mon Feb 5 13:56:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13545586 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 58988C48295 for ; Mon, 5 Feb 2024 13:56:50 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.676099.1051953 (Exim 4.92) (envelope-from ) id 1rWzSh-0007VJ-D7; Mon, 05 Feb 2024 13:56:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 676099.1051953; Mon, 05 Feb 2024 13:56:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWzSh-0007VC-9X; Mon, 05 Feb 2024 13:56:39 +0000 Received: by outflank-mailman (input) for mailman id 676099; Mon, 05 Feb 2024 13:56:37 +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 1rWzSf-0005z2-Nh for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 13:56:37 +0000 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [2a00:1450:4864:20::333]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 60d851ad-c42e-11ee-8a45-1f161083a0e0; Mon, 05 Feb 2024 14:56:36 +0100 (CET) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40fc52c2ae4so28919015e9.3 for ; Mon, 05 Feb 2024 05:56:37 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id s10-20020a05600c044a00b0040efc268713sm8570104wmb.26.2024.02.05.05.56.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Feb 2024 05:56:36 -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: 60d851ad-c42e-11ee-8a45-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707141396; x=1707746196; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=K+PEfDQdWqrjmqD3hRobqZrRVXYu7/7wPkddLoGAyb8=; b=fcJP2FSG31i8dW7Rnoa/DlRHcEoJN08gElPzTROw2hJrtMySjPN5hbs468JHaLPqPD g981uNy4BNpxVhJIF18YypccCGnh7JUCoADBSpPe8zW3Sorf1RFWdi1/AUAga+iWXZeT riWmlTtqy6Jb5rKBq8IVe2KqOgqA4oSoE15uRd5OUT+713b5OWeb0dxFGxTcSGoLKKR3 NgNwI8BXqrJa/s/PN/Sg7rZMrkpXZss25PHaE73R7Jgq4iYdhezN0WhQZpWzPq31zpc8 BVvwWKTn8rXsbZcRVLg6xFbcxROD4BcYgWHeVV5czJ2bBR0clVbQDXiv61fpXE6zpEwD 4B1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707141396; x=1707746196; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=K+PEfDQdWqrjmqD3hRobqZrRVXYu7/7wPkddLoGAyb8=; b=A67wGLCaff8jTd0PAQIJYdqdnyGq1EmhxlrNF4nn7jwNJABoYa02ubrVHOIbtf3Fyq IrvE2JZPPFnDwAglkss4ENhCDDPbF8FVWT86Ykap0ws7CVbjBZqOZ3XVqd5+c4OccYfW 6+QyQ9fPbMYoYT25V2zYtyo0yIvXPF/6Bc+sTpXFWha/WbaEa8YjR3P2BK70kD3WAsLL /nro8W7GMbWxLhrzfjx05re6KPQYqunCfgnP3gEJwXAmaawPFXRl5SK4uCFoUAxAYH8K QxPfKMAV6gCGK24gLM9Ze05LpnXKknkRTLdsfz7hD6mpdFoDbaf1t4/1HNcZoPPSV1ic v3SQ== X-Gm-Message-State: AOJu0YwbxhhS4x8S9QyM7EloQ7pp+p6n6Kzqf4ORgg6a8KiMlt5vtpHt JctAUtn/5jJqtf1zifcsFRG3cAG/RXS2026s2kXdIuFc3ZQcVd5KArcgRbzC2TQf26culYoeIOw = X-Google-Smtp-Source: AGHT+IH0gtD1EaC9rv3MSpVyGG/VHdKnT9uqSW0cm30+gNZ5Bnx2NDrq09wKTc9jpodHulyT0soWnQ== X-Received: by 2002:a05:600c:3c83:b0:40f:b166:7688 with SMTP id bg3-20020a05600c3c8300b0040fb1667688mr4324676wmb.15.1707141396500; Mon, 05 Feb 2024 05:56:36 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXdFQiJue1hYUdiMogxydIS3naOKWQvRVsy3kUPh2cbI2Ok3y7t3TmVvt3gB8HU3M91kLRaeOHlHsUK9hhJe8cT8ICVYOIEeTyAG/FED4ILJFLi Message-ID: Date: Mon, 5 Feb 2024 14:56:36 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 4/7] VT-d: replace find_ats_dev_drhd() Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Kevin Tian , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Paul Durrant References: <25506838-b818-4686-8c16-3a198338af44@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <25506838-b818-4686-8c16-3a198338af44@suse.com> All callers only care about boolean outcome. For this there's no point in allocating a duplicate of the respective DRHD structure; a simple boolean suffices (which eventually may wantg to become a count, such that the "any ATS devices assigned state" can also clear again). With that boolean, remove respective parameters from internal helper functions right away, as those have access to the flag through another parameter. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné --- a/xen/drivers/passthrough/vtd/extern.h +++ b/xen/drivers/passthrough/vtd/extern.h @@ -65,8 +65,6 @@ struct acpi_drhd_unit *ioapic_to_drhd(un struct acpi_drhd_unit *hpet_to_drhd(unsigned int hpet_id); struct acpi_rhsa_unit *drhd_to_rhsa(const struct acpi_drhd_unit *drhd); -struct acpi_drhd_unit *find_ats_dev_drhd(struct vtd_iommu *iommu); - int ats_device(const struct pci_dev *, const struct acpi_drhd_unit *); int dev_invalidate_iotlb(struct vtd_iommu *iommu, u16 did, --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -624,8 +624,7 @@ int cf_check vtd_flush_iotlb_reg( } static int __must_check iommu_flush_iotlb_global(struct vtd_iommu *iommu, - bool flush_non_present_entry, - bool flush_dev_iotlb) + bool flush_non_present_entry) { int status; @@ -633,7 +632,7 @@ static int __must_check iommu_flush_iotl vtd_ops_preamble_quirk(iommu); status = iommu->flush.iotlb(iommu, 0, 0, 0, DMA_TLB_GLOBAL_FLUSH, - flush_non_present_entry, flush_dev_iotlb); + flush_non_present_entry, iommu->flush_dev_iotlb); /* undo platform specific errata workarounds */ vtd_ops_postamble_quirk(iommu); @@ -642,8 +641,7 @@ static int __must_check iommu_flush_iotl } static int __must_check iommu_flush_iotlb_dsi(struct vtd_iommu *iommu, u16 did, - bool flush_non_present_entry, - bool flush_dev_iotlb) + bool flush_non_present_entry) { int status; @@ -651,7 +649,7 @@ static int __must_check iommu_flush_iotl vtd_ops_preamble_quirk(iommu); status = iommu->flush.iotlb(iommu, did, 0, 0, DMA_TLB_DSI_FLUSH, - flush_non_present_entry, flush_dev_iotlb); + flush_non_present_entry, iommu->flush_dev_iotlb); /* undo platform specific errata workarounds */ vtd_ops_postamble_quirk(iommu); @@ -661,26 +659,23 @@ static int __must_check iommu_flush_iotl static int __must_check iommu_flush_iotlb_psi(struct vtd_iommu *iommu, u16 did, u64 addr, unsigned int order, - bool flush_non_present_entry, - bool flush_dev_iotlb) + bool flush_non_present_entry) { int status; /* Fallback to domain selective flush if no PSI support */ if ( !cap_pgsel_inv(iommu->cap) ) - return iommu_flush_iotlb_dsi(iommu, did, flush_non_present_entry, - flush_dev_iotlb); + return iommu_flush_iotlb_dsi(iommu, did, flush_non_present_entry); /* Fallback to domain selective flush if size is too big */ if ( order > cap_max_amask_val(iommu->cap) ) - return iommu_flush_iotlb_dsi(iommu, did, flush_non_present_entry, - flush_dev_iotlb); + return iommu_flush_iotlb_dsi(iommu, did, flush_non_present_entry); /* apply platform specific errata workarounds */ vtd_ops_preamble_quirk(iommu); status = iommu->flush.iotlb(iommu, did, addr, order, DMA_TLB_PSI_FLUSH, - flush_non_present_entry, flush_dev_iotlb); + flush_non_present_entry, iommu->flush_dev_iotlb); /* undo platform specific errata workarounds */ vtd_ops_postamble_quirk(iommu); @@ -692,7 +687,6 @@ static int __must_check iommu_flush_all( { struct acpi_drhd_unit *drhd; struct vtd_iommu *iommu; - bool flush_dev_iotlb; int rc = 0; flush_local(FLUSH_CACHE); @@ -703,8 +697,7 @@ static int __must_check iommu_flush_all( iommu = drhd->iommu; context_rc = iommu_flush_context_global(iommu, 0); - flush_dev_iotlb = !!find_ats_dev_drhd(iommu); - iotlb_rc = iommu_flush_iotlb_global(iommu, 0, flush_dev_iotlb); + iotlb_rc = iommu_flush_iotlb_global(iommu, 0); /* * The current logic for returns: @@ -734,7 +727,6 @@ static int __must_check cf_check iommu_f struct domain_iommu *hd = dom_iommu(d); struct acpi_drhd_unit *drhd; struct vtd_iommu *iommu; - bool flush_dev_iotlb; int iommu_domid; int ret = 0; @@ -762,21 +754,18 @@ static int __must_check cf_check iommu_f if ( !test_bit(iommu->index, hd->arch.vtd.iommu_bitmap) ) continue; - flush_dev_iotlb = !!find_ats_dev_drhd(iommu); iommu_domid = get_iommu_did(d->domain_id, iommu, !d->is_dying); if ( iommu_domid == -1 ) continue; if ( !page_count || (page_count & (page_count - 1)) || dfn_eq(dfn, INVALID_DFN) || !IS_ALIGNED(dfn_x(dfn), page_count) ) - rc = iommu_flush_iotlb_dsi(iommu, iommu_domid, - 0, flush_dev_iotlb); + rc = iommu_flush_iotlb_dsi(iommu, iommu_domid, 0); else rc = iommu_flush_iotlb_psi(iommu, iommu_domid, dfn_to_daddr(dfn), get_order_from_pages(page_count), - !(flush_flags & IOMMU_FLUSHF_modified), - flush_dev_iotlb); + !(flush_flags & IOMMU_FLUSHF_modified)); if ( rc > 0 ) iommu_flush_write_buffer(iommu); @@ -1488,7 +1477,6 @@ int domain_context_mapping_one( uint16_t seg = iommu->drhd->segment, prev_did = 0; struct domain *prev_dom = NULL; int rc, ret; - bool flush_dev_iotlb; if ( QUARANTINE_SKIP(domain, pgd_maddr) ) return 0; @@ -1637,8 +1625,7 @@ int domain_context_mapping_one( rc = iommu_flush_context_device(iommu, prev_did, PCI_BDF(bus, devfn), DMA_CCMD_MASK_NOBIT, !prev_dom); - flush_dev_iotlb = !!find_ats_dev_drhd(iommu); - ret = iommu_flush_iotlb_dsi(iommu, prev_did, !prev_dom, flush_dev_iotlb); + ret = iommu_flush_iotlb_dsi(iommu, prev_did, !prev_dom); /* * The current logic for returns: @@ -1882,7 +1869,6 @@ int domain_context_unmap_one( struct context_entry *context, *context_entries; u64 maddr; int iommu_domid, rc, ret; - bool flush_dev_iotlb; ASSERT(pcidevs_locked()); spin_lock(&iommu->lock); @@ -1908,8 +1894,7 @@ int domain_context_unmap_one( PCI_BDF(bus, devfn), DMA_CCMD_MASK_NOBIT, 0); - flush_dev_iotlb = !!find_ats_dev_drhd(iommu); - ret = iommu_flush_iotlb_dsi(iommu, iommu_domid, 0, flush_dev_iotlb); + ret = iommu_flush_iotlb_dsi(iommu, iommu_domid, 0); /* * The current logic for returns: --- a/xen/drivers/passthrough/vtd/iommu.h +++ b/xen/drivers/passthrough/vtd/iommu.h @@ -484,6 +484,7 @@ struct vtd_iommu { spinlock_t register_lock; /* protect iommu register handling */ u64 root_maddr; /* root entry machine address */ nodeid_t node; + bool flush_dev_iotlb; struct msi_desc msi; struct acpi_drhd_unit *drhd; --- a/xen/drivers/passthrough/vtd/x86/ats.c +++ b/xen/drivers/passthrough/vtd/x86/ats.c @@ -28,22 +28,8 @@ #include "../extern.h" #include "../../ats.h" -static LIST_HEAD(ats_dev_drhd_units); - -struct acpi_drhd_unit *find_ats_dev_drhd(struct vtd_iommu *iommu) -{ - struct acpi_drhd_unit *drhd; - list_for_each_entry ( drhd, &ats_dev_drhd_units, list ) - { - if ( drhd->iommu == iommu ) - return drhd; - } - return NULL; -} - int ats_device(const struct pci_dev *pdev, const struct acpi_drhd_unit *drhd) { - struct acpi_drhd_unit *ats_drhd; const struct acpi_satc_unit *satc; int pos; @@ -61,17 +47,10 @@ int ats_device(const struct pci_dev *pde if ( opt_ats < 0 && (!satc || !satc->atc_required) ) return 0; - ats_drhd = find_ats_dev_drhd(drhd->iommu); pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS); + if ( pos ) + drhd->iommu->flush_dev_iotlb = true; - if ( pos && (ats_drhd == NULL) ) - { - ats_drhd = xmalloc(struct acpi_drhd_unit); - if ( !ats_drhd ) - return -ENOMEM; - *ats_drhd = *drhd; - list_add_tail(&ats_drhd->list, &ats_dev_drhd_units); - } return pos; } From patchwork Mon Feb 5 13:56:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13545587 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 AE1C6C4828D for ; Mon, 5 Feb 2024 13:57:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.676101.1051963 (Exim 4.92) (envelope-from ) id 1rWzT1-0007zl-Kv; Mon, 05 Feb 2024 13:56:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 676101.1051963; Mon, 05 Feb 2024 13:56: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 1rWzT1-0007ze-I0; Mon, 05 Feb 2024 13:56:59 +0000 Received: by outflank-mailman (input) for mailman id 676101; Mon, 05 Feb 2024 13:56:58 +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 1rWzT0-0007Qa-8F for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 13:56:58 +0000 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [2a00:1450:4864:20::336]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6c801d7b-c42e-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 14:56:56 +0100 (CET) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-40fb3b5893eso36544255e9.0 for ; Mon, 05 Feb 2024 05:56:56 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id s10-20020a05600c044a00b0040efc268713sm8570104wmb.26.2024.02.05.05.56.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Feb 2024 05:56:55 -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: 6c801d7b-c42e-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707141416; x=1707746216; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=xeo9DHqLhyAKD6WkqcE7ZsPzOC6r3GO9FyNnjBbVjWg=; b=U0imfmc5NLC1819iyKXKi/sCwqF0YaJNGnuIbbCeE+srnjJuV5lv6Pekbiu4YIWowJ Z11HT6JwI9KMkM2M57r60g6z7+Uc+PVEQGu1KdPj2s8EAhCYxR5siK5jdCvt/3L/xBIy 2bOknoJLQ4bIjtBhVnAyFKIq9+bv6ybiwCQuwyt0rRsNXkpdHNgl08wD4hWJyyGHFnWC 8oPSuafUKrBM6jaNng9iVjZf9U5ht3EmbyqelIHZSYrQpSdqWrU50WurKFB9a2A3qJbi WKO5lYShbETp23lMHyVvCmEHGcMHla7CLVyx5q/ttmCLmSkFRQWJIpqHL0DoMPJSnF1T vS+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707141416; x=1707746216; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xeo9DHqLhyAKD6WkqcE7ZsPzOC6r3GO9FyNnjBbVjWg=; b=kVNvKgQhmJsYrHqKi5TZdnUeUowYN2eQGrFCFE/HQrsjlhyYMFhFqGznLLUOzcRv+/ 8ROtuSpNsl+O0O/9QNFoJvGrWzhPh/i5nYUFiDL5Wdk3CTiXGsHwrX+owb0+Ki3ashBr XFD5/9tc5YxkEZPLO+lo0ON94XNO7cK7Nn5VATxssHDaKIHBAinVCXoJ+HAgZ2jq5N6Q /QhuGqnTnWINftVUNIxL6/ViO3kYqAB+tRGwxsBn59MfmiAdS0Ep2/IclaKVbp04t7GD vriVboUBnwA6CnHUmxvDoqnMrrQRgR4wsNk8Yyrr+Tc1GEWbBhCdMjp3V6F7LL2++GXa x2zA== X-Gm-Message-State: AOJu0YwMUmBZb2YaPKh1SLIqeLIbTY+lZtILPEUhkoQwrCLjlZv82SaN Dng7fouzKED0DllACdTM8uxKMftXp8/hV9ff2E5HuxoblFC+wWy6eWLB62O47gwBB6E1aEZ/0MQ = X-Google-Smtp-Source: AGHT+IFh4g3nSQAwzF4QQsuBLBhkW4JIZ4T2NTiGOlKNdj81gjIVBNg1B7egKsB3lrK01voNNtbn3A== X-Received: by 2002:a05:600c:548f:b0:40f:ba0b:16b3 with SMTP id iv15-20020a05600c548f00b0040fba0b16b3mr5246317wmb.2.1707141415954; Mon, 05 Feb 2024 05:56:55 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVaYke9c25HWtuApe/uvtGvV7vnZoOn1fWG9SS7v5zvQJe4TjNQdcTy+WCDdN2AZwlDQI3m5PG7dztrGpLLB8lzp+OFQ6BnqY1plG2UMeiRw9NT Message-ID: Date: Mon, 5 Feb 2024 14:56:55 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 5/7] VT-d: move ats_device() to the sole file it's used from Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Kevin Tian , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Paul Durrant References: <25506838-b818-4686-8c16-3a198338af44@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcy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qscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <25506838-b818-4686-8c16-3a198338af44@suse.com> ..., thus allowing it to become static, and thus reducing scope overlap between it and pci_ats_device(). There's nothing x86-specific about this function anyway. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné zroger.pau@citrix.com> --- a/xen/drivers/passthrough/vtd/extern.h +++ b/xen/drivers/passthrough/vtd/extern.h @@ -65,8 +65,6 @@ struct acpi_drhd_unit *ioapic_to_drhd(un struct acpi_drhd_unit *hpet_to_drhd(unsigned int hpet_id); struct acpi_rhsa_unit *drhd_to_rhsa(const struct acpi_drhd_unit *drhd); -int ats_device(const struct pci_dev *, const struct acpi_drhd_unit *); - int dev_invalidate_iotlb(struct vtd_iommu *iommu, u16 did, u64 addr, unsigned int size_order, u64 type); --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -1455,6 +1455,33 @@ static void __hwdom_init cf_check intel_ } } +static int ats_device(const struct pci_dev *pdev, + const struct acpi_drhd_unit *drhd) +{ + const struct acpi_satc_unit *satc; + int pos; + + if ( !opt_ats || !iommu_qinval ) + return 0; + + if ( !ecap_queued_inval(drhd->iommu->ecap) || + !ecap_dev_iotlb(drhd->iommu->ecap) ) + return 0; + + if ( !acpi_find_matched_atsr_unit(pdev) ) + return 0; + + satc = acpi_find_matched_satc_unit(pdev); + if ( opt_ats < 0 && (!satc || !satc->atc_required) ) + return 0; + + pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS); + if ( pos ) + drhd->iommu->flush_dev_iotlb = true; + + return pos; +} + /* * This function returns * - a negative errno value upon error, --- a/xen/drivers/passthrough/vtd/x86/ats.c +++ b/xen/drivers/passthrough/vtd/x86/ats.c @@ -28,32 +28,6 @@ #include "../extern.h" #include "../../ats.h" -int ats_device(const struct pci_dev *pdev, const struct acpi_drhd_unit *drhd) -{ - const struct acpi_satc_unit *satc; - int pos; - - if ( !opt_ats || !iommu_qinval ) - return 0; - - if ( !ecap_queued_inval(drhd->iommu->ecap) || - !ecap_dev_iotlb(drhd->iommu->ecap) ) - return 0; - - if ( !acpi_find_matched_atsr_unit(pdev) ) - return 0; - - satc = acpi_find_matched_satc_unit(pdev); - if ( opt_ats < 0 && (!satc || !satc->atc_required) ) - return 0; - - pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS); - if ( pos ) - drhd->iommu->flush_dev_iotlb = true; - - return pos; -} - static bool device_in_domain(const struct vtd_iommu *iommu, const struct pci_dev *pdev, uint16_t did) { From patchwork Mon Feb 5 13:57:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13545588 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 BDD4DC4828D for ; Mon, 5 Feb 2024 13:57:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.676102.1051972 (Exim 4.92) (envelope-from ) id 1rWzTJ-00006H-Sn; Mon, 05 Feb 2024 13:57:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 676102.1051972; Mon, 05 Feb 2024 13:57:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWzTJ-00006A-QD; Mon, 05 Feb 2024 13:57:17 +0000 Received: by outflank-mailman (input) for mailman id 676102; Mon, 05 Feb 2024 13:57:15 +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 1rWzTH-0007Qa-Ti for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 13:57:15 +0000 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [2a00:1450:4864:20::335]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 76e9b37f-c42e-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 14:57:13 +0100 (CET) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40fdf2b69b2so446095e9.1 for ; Mon, 05 Feb 2024 05:57:13 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id s10-20020a05600c044a00b0040efc268713sm8570104wmb.26.2024.02.05.05.57.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Feb 2024 05:57:12 -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: 76e9b37f-c42e-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707141433; x=1707746233; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=DHe5MlAMnMR5U49EdLt7+W2yJjwbBdMvr2wcdgX2lS0=; b=fyV/cFrHngTlCj+uR2CxjhBlYSRV/IEM41P20GaIY5wW1EWG9B5tAg4auH+0YG2n87 sT+s2rTvArlnL0LPte5gK0P7s0o0pSu/7bNZTxm1UEH1tdMzF0s7RYxGztr9nJ1i61GH lKvXctNW/3StCwSWrHiRMKANxS1sbJ+L6mqApy9Achih9n/JlsPckcaxh7IooHOr3glm mgeniiqNdQcGumZoWTxh4L8jKPAm2fsvgQ91LCzLPNGeothzZfcKA8gOTz7iQ8+Cbg2o XAEo1Z2Gpfq9W3/VK2vR/5Wq/FyNAXrikCuscOlmcRUrvOIfEEFDqoAmq5Sy778Lumx6 EW/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707141433; x=1707746233; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DHe5MlAMnMR5U49EdLt7+W2yJjwbBdMvr2wcdgX2lS0=; b=IFAIXc9cyZ5x2K8oVAaRngunMtyrDaeiLPRnaKMqjvaZ8VK9xZCyLs2sCTs559JI7l ot8oNWhb11nlriQyzbWlo66MTwv97l+jSqKXFUFrIb1AZVOMpDXJ2OE0vTBjyPvWht6m wFu1Er5nujtq0tzsgFLVIbIl6SjRcfgpVZM/uVhhovC/Nwu3eiA1A9wqvRI2+1dokPak pCnozKEUiqLDT4PkJr9F/WzuKzrk2LX7J+A4F1v5j55bFs9Tp4qcC07d7xSO04xQl1GP A323n+sCNbJsW5O3+ivkeA0KxlORnxq+O/o5gOzw5hgNKhAuUDUwTFyAEhbvPrCDUjn7 TC1A== X-Gm-Message-State: AOJu0Yx7E2AdnMK7eF+Pirnwl0/EaMSYNDSQu60pj3wg1hbW+XvwLsn8 vvgy44dwi7KGAL4923rskji1vFVY8hcj+Lp2MHCSndiXJ4BPWdUg9ZUS/0q+ZRa2B/f2+frpIrE = X-Google-Smtp-Source: AGHT+IEiEcXe2SY92ZwEiLXKnHjQdViDe4WS5m9kWAg3gy+3vDjt0e9/mdD9dVZaDQxIMCIYa3lxgw== X-Received: by 2002:a05:600c:35cc:b0:40f:cb0d:4de6 with SMTP id r12-20020a05600c35cc00b0040fcb0d4de6mr4305258wmq.5.1707141433377; Mon, 05 Feb 2024 05:57:13 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUWUpE7oHc1i8YvDQQ4BMXPfmqOMeZNLennM73+mNklHfyTKYKaeVh+FZWhQBu/doKHY9RsZDtY+30D0ODfyE6tQXPLUUCYocw1xiYc03pJy0KX Message-ID: <0d14f148-32e0-4dac-b5e8-3230adfc5f9d@suse.com> Date: Mon, 5 Feb 2024 14:57:12 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 6/7] VT-d: move dev_invalidate_iotlb() to the sole file it's used from Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Kevin Tian , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Paul Durrant References: <25506838-b818-4686-8c16-3a198338af44@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLg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WPgskBQL In-Reply-To: <25506838-b818-4686-8c16-3a198338af44@suse.com> ..., thus allowing it and qinval_device_iotlb_sync() to become static. There's nothing x86-specific about the function anyway. While moving, adjust types to better match ./CODING_STYLE (albeit use of fixed-width types for parameters is retained to limit the effective change). Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné --- a/xen/drivers/passthrough/vtd/extern.h +++ b/xen/drivers/passthrough/vtd/extern.h @@ -65,12 +65,6 @@ struct acpi_drhd_unit *ioapic_to_drhd(un struct acpi_drhd_unit *hpet_to_drhd(unsigned int hpet_id); struct acpi_rhsa_unit *drhd_to_rhsa(const struct acpi_drhd_unit *drhd); -int dev_invalidate_iotlb(struct vtd_iommu *iommu, u16 did, - u64 addr, unsigned int size_order, u64 type); - -int __must_check qinval_device_iotlb_sync(struct vtd_iommu *iommu, - struct pci_dev *pdev, - u16 did, u16 size, u64 addr); uint64_t alloc_pgtable_maddr(unsigned long npages, nodeid_t node); void free_pgtable_maddr(u64 maddr); --- a/xen/drivers/passthrough/vtd/qinval.c +++ b/xen/drivers/passthrough/vtd/qinval.c @@ -251,8 +251,9 @@ static int __must_check dev_invalidate_s return rc; } -int qinval_device_iotlb_sync(struct vtd_iommu *iommu, struct pci_dev *pdev, - u16 did, u16 size, u64 addr) +static int qinval_device_iotlb_sync(struct vtd_iommu *iommu, + struct pci_dev *pdev, uint16_t did, + uint16_t size, paddr_t addr) { unsigned long flags; unsigned int index; @@ -282,6 +283,101 @@ int qinval_device_iotlb_sync(struct vtd_ return dev_invalidate_sync(iommu, pdev, did); } +static bool device_in_domain(const struct vtd_iommu *iommu, + const struct pci_dev *pdev, uint16_t did) +{ + struct root_entry *root_entry; + struct context_entry *ctxt_entry = NULL; + unsigned int tt; + bool found = false; + + if ( unlikely(!iommu->root_maddr) ) + { + ASSERT_UNREACHABLE(); + return false; + } + + root_entry = map_vtd_domain_page(iommu->root_maddr); + if ( !root_present(root_entry[pdev->bus]) ) + goto out; + + ctxt_entry = map_vtd_domain_page(root_entry[pdev->bus].val); + if ( context_domain_id(ctxt_entry[pdev->devfn]) != did ) + goto out; + + tt = context_translation_type(ctxt_entry[pdev->devfn]); + if ( tt != CONTEXT_TT_DEV_IOTLB ) + goto out; + + found = true; + out: + if ( root_entry ) + unmap_vtd_domain_page(root_entry); + + if ( ctxt_entry ) + unmap_vtd_domain_page(ctxt_entry); + + return found; +} + +static int dev_invalidate_iotlb(struct vtd_iommu *iommu, uint16_t did, + paddr_t addr, unsigned int size_order, + uint64_t type) +{ + struct pci_dev *pdev, *temp; + int ret = 0; + + if ( !ecap_dev_iotlb(iommu->ecap) ) + return ret; + + list_for_each_entry_safe( pdev, temp, &iommu->ats_devices, ats.list ) + { + bool sbit; + int rc = 0; + + switch ( type ) + { + case DMA_TLB_DSI_FLUSH: + if ( !device_in_domain(iommu, pdev, did) ) + break; + /* fall through if DSI condition met */ + case DMA_TLB_GLOBAL_FLUSH: + /* invalidate all translations: sbit=1,bit_63=0,bit[62:12]=1 */ + sbit = 1; + addr = (~0UL << PAGE_SHIFT_4K) & 0x7FFFFFFFFFFFFFFF; + rc = qinval_device_iotlb_sync(iommu, pdev, did, sbit, addr); + break; + case DMA_TLB_PSI_FLUSH: + if ( !device_in_domain(iommu, pdev, did) ) + break; + + /* if size <= 4K, set sbit = 0, else set sbit = 1 */ + sbit = size_order ? 1 : 0; + + /* clear lower bits */ + addr &= ~0UL << PAGE_SHIFT_4K; + + /* if sbit == 1, zero out size_order bit and set lower bits to 1 */ + if ( sbit ) + { + addr &= ~((u64)PAGE_SIZE_4K << (size_order - 1)); + addr |= (((u64)1 << (size_order - 1)) - 1) << PAGE_SHIFT_4K; + } + + rc = qinval_device_iotlb_sync(iommu, pdev, did, sbit, addr); + break; + default: + dprintk(XENLOG_WARNING VTDPREFIX, "invalid vt-d flush type\n"); + return -EOPNOTSUPP; + } + + if ( !ret ) + ret = rc; + } + + return ret; +} + static int __must_check queue_invalidate_iec_sync(struct vtd_iommu *iommu, u8 granu, u8 im, u16 iidx) { --- a/xen/drivers/passthrough/vtd/x86/Makefile +++ b/xen/drivers/passthrough/vtd/x86/Makefile @@ -1,2 +1 @@ -obj-y += ats.o obj-y += vtd.o --- a/xen/drivers/passthrough/vtd/x86/ats.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2006, Intel Corporation. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; If not, see . - * - * Author: Allen Kay - */ - -#include -#include -#include -#include -#include -#include -#include "../iommu.h" -#include "../dmar.h" -#include "../vtd.h" -#include "../extern.h" -#include "../../ats.h" - -static bool device_in_domain(const struct vtd_iommu *iommu, - const struct pci_dev *pdev, uint16_t did) -{ - struct root_entry *root_entry; - struct context_entry *ctxt_entry = NULL; - unsigned int tt; - bool found = false; - - if ( unlikely(!iommu->root_maddr) ) - { - ASSERT_UNREACHABLE(); - return false; - } - - root_entry = map_vtd_domain_page(iommu->root_maddr); - if ( !root_present(root_entry[pdev->bus]) ) - goto out; - - ctxt_entry = map_vtd_domain_page(root_entry[pdev->bus].val); - if ( context_domain_id(ctxt_entry[pdev->devfn]) != did ) - goto out; - - tt = context_translation_type(ctxt_entry[pdev->devfn]); - if ( tt != CONTEXT_TT_DEV_IOTLB ) - goto out; - - found = true; -out: - if ( root_entry ) - unmap_vtd_domain_page(root_entry); - - if ( ctxt_entry ) - unmap_vtd_domain_page(ctxt_entry); - - return found; -} - -int dev_invalidate_iotlb(struct vtd_iommu *iommu, u16 did, - u64 addr, unsigned int size_order, u64 type) -{ - struct pci_dev *pdev, *temp; - int ret = 0; - - if ( !ecap_dev_iotlb(iommu->ecap) ) - return ret; - - list_for_each_entry_safe( pdev, temp, &iommu->ats_devices, ats.list ) - { - bool sbit; - int rc = 0; - - switch ( type ) - { - case DMA_TLB_DSI_FLUSH: - if ( !device_in_domain(iommu, pdev, did) ) - break; - /* fall through if DSI condition met */ - case DMA_TLB_GLOBAL_FLUSH: - /* invalidate all translations: sbit=1,bit_63=0,bit[62:12]=1 */ - sbit = 1; - addr = (~0UL << PAGE_SHIFT_4K) & 0x7FFFFFFFFFFFFFFF; - rc = qinval_device_iotlb_sync(iommu, pdev, did, sbit, addr); - break; - case DMA_TLB_PSI_FLUSH: - if ( !device_in_domain(iommu, pdev, did) ) - break; - - /* if size <= 4K, set sbit = 0, else set sbit = 1 */ - sbit = size_order ? 1 : 0; - - /* clear lower bits */ - addr &= ~0UL << PAGE_SHIFT_4K; - - /* if sbit == 1, zero out size_order bit and set lower bits to 1 */ - if ( sbit ) - { - addr &= ~((u64)PAGE_SIZE_4K << (size_order - 1)); - addr |= (((u64)1 << (size_order - 1)) - 1) << PAGE_SHIFT_4K; - } - - rc = qinval_device_iotlb_sync(iommu, pdev, did, sbit, addr); - break; - default: - dprintk(XENLOG_WARNING VTDPREFIX, "invalid vt-d flush type\n"); - return -EOPNOTSUPP; - } - - if ( !ret ) - ret = rc; - } - - return ret; -} From patchwork Mon Feb 5 13:57:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13545589 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 0FEB1C48295 for ; Mon, 5 Feb 2024 13:57:40 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.676106.1051983 (Exim 4.92) (envelope-from ) id 1rWzTZ-0000cp-B4; Mon, 05 Feb 2024 13:57:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 676106.1051983; Mon, 05 Feb 2024 13:57:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWzTZ-0000ce-7Q; Mon, 05 Feb 2024 13:57:33 +0000 Received: by outflank-mailman (input) for mailman id 676106; Mon, 05 Feb 2024 13:57:32 +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 1rWzTY-0000cP-QM for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 13:57:32 +0000 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [2a00:1450:4864:20::12c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8181d953-c42e-11ee-8a45-1f161083a0e0; Mon, 05 Feb 2024 14:57:31 +0100 (CET) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-5113a7e662aso2866125e87.2 for ; Mon, 05 Feb 2024 05:57:31 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id s10-20020a05600c044a00b0040efc268713sm8570104wmb.26.2024.02.05.05.57.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Feb 2024 05:57:31 -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: 8181d953-c42e-11ee-8a45-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707141451; x=1707746251; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=uXBzhqSfaSDHiztTRpLA+4XGmypB9k5L3zoFSjZ2FGw=; b=WTepeszGzejkvWAtf3tKou+/LYsiSLa3v0GInR0N9Ge14AbFbv1iKA96qNa+Tcr4V+ mQmwsx+tCnrW/Us4kvssg0sX7FQsaIUjZi+vGllMXlIPcSkygXRtd+TOUFcqyXpnNmnD +exqSn/Fh8EBuWIGWOGffBvOOmJqbtId9c/ZPjlpwfxCW1upYpduoHDJbCZ4Y/NNTQ7N JMKMZWXzQGrmdpdbIp6Pj6NR6q0EOMuC3bqVIfSk0sBFwDUeAHayI5GkwaFys1hWbgsH QDg8rdvECZef0UfZPuuILljnToTcsXRKzs3J6E/1I4nDT5PBHKzAGyNDtxc0YSrQf8XZ KwcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707141451; x=1707746251; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uXBzhqSfaSDHiztTRpLA+4XGmypB9k5L3zoFSjZ2FGw=; b=PUWzhIlaOVQ+BldPS4bnPCn909hUMX9RmrCL29JuVPPCSnjdYbp8S805zkGkguJOPJ LfGb+bhQl3KEX/MLapdeLXgBVqxU4JbAB1fQruHjbi8wg9RQZDEvZr0jzIMQfROkQe5J VS/RjvoPSEpRKdh22GgU8goVrQxS/lFFmSKs7uH0C4Wkqf3ypEtWsUETJ+WhxjusOmuq 6/JrmCUGZ+2rafesMbIKH6GlSoISglK/9XTygIIoaFSCKnkRzIrTLaNQeS9nAYbVURgW E1Epk/nEWwuaM6z60z3XeW9iVFuhYfUwXBhs9VDiW/CqZb0sn77gZKIABR4WfIW+ccre 25Ng== X-Gm-Message-State: AOJu0YzvfYGkEAxj0gXmlUU3zU0tlYDQ+PV6CUDsyfFJE+CTTboHVXz6 ntk+v18v+EQzsInfeQ3nSdoLGOBnwWwmJSCNKkSVAr16AmB/7+IPTjNZaw7MEomDTKAGvQVTrtA = X-Google-Smtp-Source: AGHT+IHLs7xqGMOV9FUSIW0Qe9gIZaLvyw2Qc/RKngXz/bIVhXNReXe7jtU8m9R58AapmeNettF78A== X-Received: by 2002:a05:6512:3986:b0:511:38e6:6b24 with SMTP id j6-20020a056512398600b0051138e66b24mr7361998lfu.3.1707141451332; Mon, 05 Feb 2024 05:57:31 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWsYbpE8CY1tALojkxNPjsAGiREs6ASV67DA7aeFNc+U3dc/3OoOVQeWMP45ydfdCroMNsPU33ctkZIT9Qa+hpjxc1GTgdD+0O7YsaxyXIv/R+N Message-ID: <22e7036c-cf49-4160-bd26-fbba6b67ff5d@suse.com> Date: Mon, 5 Feb 2024 14:57:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 7/7] VT-d: move {,un}map_vtd_domain_page() Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Kevin Tian , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Paul Durrant References: <25506838-b818-4686-8c16-3a198338af44@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i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GBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <25506838-b818-4686-8c16-3a198338af44@suse.com> ..., thus allowing them to become static. There's nothing x86-specific about these functions anyway. Since only the "iommu_inclusive_mapping" parameter declaration would be left in the file, move that as well. There's nothing VT-d specific about it (anymore?): "dom0-iommu=map-inclusive" is similarly generic, and documentation also doesn't say anything. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné --- a/xen/drivers/passthrough/vtd/Makefile +++ b/xen/drivers/passthrough/vtd/Makefile @@ -1,5 +1,3 @@ -obj-$(CONFIG_X86) += x86/ - obj-y += iommu.o obj-y += dmar.o obj-y += utils.o --- a/xen/drivers/passthrough/vtd/extern.h +++ b/xen/drivers/passthrough/vtd/extern.h @@ -21,6 +21,7 @@ #define _VTD_EXTERN_H_ #include "dmar.h" +#include #include #define VTDPREFIX "[VT-D]" @@ -68,8 +69,6 @@ struct acpi_rhsa_unit *drhd_to_rhsa(cons uint64_t alloc_pgtable_maddr(unsigned long npages, nodeid_t node); void free_pgtable_maddr(u64 maddr); -void *map_vtd_domain_page(u64 maddr); -void unmap_vtd_domain_page(const void *va); int domain_context_mapping_one(struct domain *domain, struct vtd_iommu *iommu, uint8_t bus, uint8_t devfn, const struct pci_dev *pdev, domid_t domid, @@ -79,6 +78,16 @@ int domain_context_unmap_one(struct doma int cf_check intel_iommu_get_reserved_device_memory( iommu_grdm_t *func, void *ctxt); +static inline void *map_vtd_domain_page(paddr_t maddr) +{ + return map_domain_page(_mfn(paddr_to_pfn(maddr))); +} + +static inline void unmap_vtd_domain_page(const void *va) +{ + unmap_domain_page(va); +} + unsigned int cf_check io_apic_read_remap_rte( unsigned int apic, unsigned int reg); void cf_check io_apic_write_remap_rte( --- a/xen/drivers/passthrough/vtd/x86/Makefile +++ /dev/null @@ -1 +0,0 @@ -obj-y += vtd.o --- a/xen/drivers/passthrough/vtd/x86/vtd.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2008, Intel Corporation. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; If not, see . - * - * Copyright (C) Allen Kay - * Copyright (C) Weidong Han - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../iommu.h" -#include "../dmar.h" -#include "../vtd.h" -#include "../extern.h" - -/* - * iommu_inclusive_mapping: when set, all memory below 4GB is included in dom0 - * 1:1 iommu mappings except xen and unusable regions. - */ -boolean_param("iommu_inclusive_mapping", iommu_hwdom_inclusive); - -void *map_vtd_domain_page(u64 maddr) -{ - return map_domain_page(_mfn(paddr_to_pfn(maddr))); -} - -void unmap_vtd_domain_page(const void *va) -{ - unmap_domain_page(va); -} --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -36,6 +37,12 @@ bool __initdata iommu_superpages = true; enum iommu_intremap __read_mostly iommu_intremap = iommu_intremap_full; +/* + * iommu_inclusive_mapping: When set, all memory below 4GB is included in dom0 + * 1:1 iommu mappings except xen and unusable regions. + */ +boolean_param("iommu_inclusive_mapping", iommu_hwdom_inclusive); + #ifdef CONFIG_PV /* Possible unfiltered LAPIC/MSI messages from untrusted sources? */ bool __read_mostly untrusted_msi;