From nobody Sat Dec 21 14:23:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1707141335; cv=none; d=zohomail.com; s=zohoarc; b=X9Lr6LIREQlsPZvJCic/8VTma5u1oAa7XKXB2l5RuHVAbUpFM6266Cjg9yd/9iL+jY3BKhUL27fB0FX7xg/UiAUA9evhI9D+NELsc0yOP+zhI1wvuCiAtW78QUDNFl+XHxiuLca946l6+NqPr2ehUHASxhYDhjY1uHE6zJyx5HE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707141335; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xWCA/5RL2ARwAkMhUTOsGwspLyYaB9W2mN7GzM8E/nc=; b=HF48mKCJBNEBEQ8lNAcqxE73z3nz0bYYyHWQD0zh/aIiXlH/a8SsCGA8PCGQqLVuzM4pdnzYO9gaip6ZYBH0eZ4zQCUDShS42aIL5kD7h7c0XmBRtIPUDtAgARFhDWOcRLgVhxGbMjCfxiWX7tCAup5NcO2L8K9OFlmGCQTeH8Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707141335824532.0363192742893; Mon, 5 Feb 2024 05:55:35 -0800 (PST) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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-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> Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707141336902100001 Content-Type: text/plain; charset="utf-8" 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); =20 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; } =20 +static int __init register_one_satc(struct acpi_satc_unit *satcu) +{ + bool ignore =3D false; + unsigned int i =3D 0; + int ret =3D 0; + + /* Skip checking if segment is not accessible yet. */ + if ( !pci_known_segment(satcu->segment) ) + i =3D UINT_MAX; + + for ( ; i < satcu->scope.devices_cnt; i++ ) + { + uint8_t b =3D PCI_BUS(satcu->scope.devices[i]); + uint8_t d =3D PCI_SLOT(satcu->scope.devices[i]); + uint8_t f =3D PCI_FUNC(satcu->scope.devices[i]); + + if ( pci_device_detect(satcu->segment, b, d, f) =3D=3D 0 ) + { + dprintk(XENLOG_WARNING VTDPREFIX, + " Non-existent device (%pp) is reported in SATC scope!= \n", + &PCI_SBDF(satcu->segment, b, d, f)); + ignore =3D true; + } + else + { + ignore =3D 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 =3D + 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 =3D acpi_dmar_check_length(header, sizeof(*satc))) !=3D 0 ) + return ret; + + satcu =3D xzalloc(struct acpi_satc_unit); + if ( !satcu ) + return -ENOMEM; + + satcu->segment =3D satc->segment; + satcu->atc_required =3D satc->flags & 1; + + dev_scope_start =3D (const void *)(satc + 1); + dev_scope_end =3D (const void *)satc + header->length; + ret =3D acpi_parse_dev_scope(dev_scope_start, dev_scope_end, + &satcu->scope, SATC_TYPE, satc->segment); + + if ( !ret && satcu->scope.devices_cnt ) + { + ret =3D 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 =3D 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 =3D acpi_parse_one_rhsa(entry_header); break; + case ACPI_DMAR_TYPE_SATC: + if ( iommu_verbose ) + printk(VTDPREFIX "found ACPI_DMAR_SATC:\n"); + ret =3D 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; }; =20 +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) =20 @@ -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 =20 #define DMAR_OPERATION_TIMEOUT MILLISECS(1000) =20 --- 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 =3D 1, ACPI_DMAR_TYPE_ATSR =3D 2, ACPI_DMAR_HARDWARE_AFFINITY =3D 3, - ACPI_DMAR_TYPE_RESERVED =3D 4 /* 4 and greater are reserved */ + ACPI_DMAR_TYPE_SATC =3D 5, + ACPI_DMAR_TYPE_RESERVED =3D 7 /* 7 and greater are reserved */ }; =20 /* DMAR Device Scope structure */ @@ -427,6 +428,15 @@ struct acpi_dmar_rhsa { u32 proximity_domain; }; =20 +/* 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 nobody Sat Dec 21 14:23:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1707141364; cv=none; d=zohomail.com; s=zohoarc; b=iM3HZF0xaWaPCXk7fQl9FRx1KzqCbrc6gakn1mmyLYyZVcTAFEkiA4ExGH9K2ITDdeE4OwGJ0fa9yF9drcFJEzEY+D0yk8KBoLVmE2wYCrA3vYb4WVectzOTlDkydPkGtlTobFsP6IkjKEZorF/0igAlaU58Yngr4Kds0F1Dh5I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707141364; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fiaRUGgpUjwp5AtuY8peqqWBSdls0Fsu1GdGBsfM0J0=; b=LhGS0bO/A+r4xyTA3pB9wxN+HIttDROpeMKcHVyzJqTq6QawQQ9GibJm6Z6kdrO5u8lLgZemweBAgT4OYNrQKzhZGN+el3cZNTPeqKyLK+y6qh3zMy0Eh4m045CQ13L1ZeO9nYRqyJdqiXGA2GUEQXpNI4L6gE8J2uuKIrtaUJ4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707141364774693.3483937632694; Mon, 5 Feb 2024 05:56:04 -0800 (PST) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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=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> Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707141367001100001 Content-Type: text/plain; charset="utf-8" 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; =20 - if ( !ats_enabled ) + if ( opt_ats <=3D 0 ) return; =20 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); } =20 - if ( ats_enabled ) + if ( opt_ats > 0 ) { amd_iommu_flush_all_iotlbs(d, daddr, order); =20 --- 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 =3D ivrs_dev->dte_allow_exclusion; dte->sys_mgt =3D MASK_EXTR(ivrs_dev->device_flags, ACPI_IVHD_SYSTE= M_MGMT); =20 - 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 =3D ats_enabled; + iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) && + pci_ats_device(iommu->seg, bus, pdev->devfn) ) + dte->i =3D true; =20 spin_unlock_irqrestore(&iommu->lock, flags); =20 @@ -248,10 +249,11 @@ static int __must_check amd_iommu_setup_ ASSERT(dte->sys_mgt =3D=3D MASK_EXTR(ivrs_dev->device_flags, ACPI_IVHD_SYSTEM_MGMT)); =20 - 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 =3D=3D ats_enabled); + iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) && + pci_ats_device(iommu->seg, bus, pdev->devfn) ) + ASSERT(dte->i); =20 spin_unlock_irqrestore(&iommu->lock, flags); =20 @@ -268,9 +270,10 @@ static int __must_check amd_iommu_setup_ =20 ASSERT(pcidevs_locked()); =20 - 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 =3D=3D pdev->devfn ) --- a/xen/drivers/passthrough/ats.c +++ b/xen/drivers/passthrough/ats.c @@ -18,8 +18,8 @@ #include #include "ats.h" =20 -bool __read_mostly ats_enabled; -boolean_param("ats", ats_enabled); +int8_t __ro_after_init opt_ats =3D -1; +boolean_param("ats", opt_ats); =20 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) =20 -extern bool ats_enabled; +extern int8_t opt_ats; =20 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 =20 static inline int pci_ats_device(int seg, int bus, int devfn) { - if ( !ats_enabled ) + if ( !opt_ats ) return 0; =20 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( } =20 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; =20 - if ( !ats_enabled || !iommu_qinval ) + if ( opt_ats <=3D 0 || !iommu_qinval ) return 0; =20 if ( !ecap_queued_inval(drhd->iommu->ecap) || From nobody Sat Dec 21 14:23:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1707141396; cv=none; d=zohomail.com; s=zohoarc; b=fTox2dJr7GFzNPqwgsOGXOjqva5+LkPHfIpMxod+7ot7rmi1uT0EpeioK1MyFwjGzVHQF7IZ26JRiw6Np6V4sZXvrcUr6V34IBDHzkBL60yZLZtgbZh8Ij5VOizlaY9wrzVtGR2/XmcG7+fg0pfnyGMZweLsv6ELWKqFU0HXqv8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707141396; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=f3H4Ur0/gJhZeUF8ayz9NPkqLMEexvZyofs8rqJKkAY=; b=KHoStmTnti2xCyKmjUsPtEYNvWOMe3OStibh6TfMFjFQ4eB7aJUlwHyxyVqD3W1L3BsgEyOCt5YoIKHy/qzySV1JnR+JVIZb7aWIQqwYBYLPstdi5t2ZY/u+hm4HDyWvwTPJdxoYEwtH717itVUudYcHzETaEKmrNObj3L5D0Rw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707141396273517.7780727133003; Mon, 5 Feb 2024 05:56:36 -0800 (PST) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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 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> Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707141397173100001 Content-Type: text/plain; charset="utf-8" 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` =20 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 indi= cate +that certain devices need to have ATS enabled for proper operation. For su= ch +devices ATS will be enabled by default, unless the option is used in its +negative form. =20 **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; } =20 +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 !=3D pdev->seg ) + continue; + + for ( unsigned int i =3D 0; i < satc->scope.devices_cnt; ++i ) + if ( satc->scope.devices[i] =3D=3D 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 { =20 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); =20 #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 =3D acpi_find_matched_drhd_unit(= pdev); + const struct acpi_satc_unit *satc =3D acpi_find_matched_satc_unit(= pdev); + + /* + * Prevent the device from getting assigned to an unprivileged dom= ain + * when firmware indicates ATS is required, but ATS could not be e= nabled + * (e.g. because of being suppressed via command line option). + */ + if ( satc && satc->atc_required && + (!drhd || ats_device(pdev, drhd) <=3D 0 || + !pci_ats_enabled(pdev->seg, pdev->bus, pdev->devfn)) ) + { + printk(XENLOG_WARNING "ATS: %pp is not eligible for pass-throu= gh\n", + &pdev->sbdf); + pdev->broken =3D true; + } + } =20 return ret; } @@ -2375,12 +2394,27 @@ static int cf_check intel_iommu_enable_d =20 pci_vtd_quirk(pdev); =20 - if ( ret <=3D 0 ) - return ret; + if ( ret <=3D 0 || + (ret =3D enable_ats_device(pdev, &drhd->iommu->ats_devices)) < 0 ) + { + const struct acpi_satc_unit *satc =3D acpi_find_matched_satc_unit(= pdev); + + /* + * Prevent the device from getting assigned to an unprivileged dom= ain + * when firmware indicates ATS is required, but ATS use was disabl= ed + * via command line option. + */ + if ( satc && satc->atc_required && !pdev->broken ) + { + printk(XENLOG_WARNING "ATS: %pp is not eligible for pass-throu= gh\n", + &pdev->sbdf); + pdev->broken =3D true; + } =20 - ret =3D enable_ats_device(pdev, &drhd->iommu->ats_devices); + return ret; + } =20 - return ret >=3D 0 ? 0 : ret; + return 0; } =20 static int cf_check intel_iommu_remove_device(u8 devfn, struct pci_dev *pd= ev) --- 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 *dr= hd) { struct acpi_drhd_unit *ats_drhd; + const struct acpi_satc_unit *satc; int pos; =20 - if ( opt_ats <=3D 0 || !iommu_qinval ) + if ( !opt_ats || !iommu_qinval ) return 0; =20 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; =20 + satc =3D acpi_find_matched_satc_unit(pdev); + if ( opt_ats < 0 && (!satc || !satc->atc_required) ) + return 0; + ats_drhd =3D find_ats_dev_drhd(drhd->iommu); pos =3D pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS); From nobody Sat Dec 21 14:23:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1707141418; cv=none; d=zohomail.com; s=zohoarc; b=SWfsh6dHX1NO4nOH4f94S7N8LvqRC2WpBsmf6TIQFAFykAQkvmSqW/LWjrsBBUA24+jGHsZB6OorACkwlEKVjqBX8nuP38dKuOeDv626PkhAFhJ+XQ7vLoN8CqW8Zct9YEoOlTHGk6xYRZ8xorueLASSJkGRedK7etESjINOiiQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707141418; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=K+PEfDQdWqrjmqD3hRobqZrRVXYu7/7wPkddLoGAyb8=; b=VqH6MYXimUd1oE4WtjIXXPWFoFq764oslz5lOHVwYHV9QenHlaIa5I1XFWCyVkVugeVeJJJPqhjOWweh5uh0hiKCak8i/M7CdueHyBpKJBM4/dbqg0NNZd/lkZdABUgOPXS9J2OxBz2HoZRJP4IT+EtosKfWr83XWXoCJQY697g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 17071414188681010.5822459209784; Mon, 5 Feb 2024 05:56:58 -0800 (PST) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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> Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707141419244100001 Content-Type: text/plain; charset="utf-8" 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=C3=A9 --- 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); =20 -struct acpi_drhd_unit *find_ats_dev_drhd(struct vtd_iommu *iommu); - int ats_device(const struct pci_dev *, const struct acpi_drhd_unit *); =20 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( } =20 static int __must_check iommu_flush_iotlb_global(struct vtd_iommu *iommu, - bool flush_non_present_en= try, - bool flush_dev_iotlb) + bool flush_non_present_en= try) { int status; =20 @@ -633,7 +632,7 @@ static int __must_check iommu_flush_iotl vtd_ops_preamble_quirk(iommu); =20 status =3D 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); =20 /* undo platform specific errata workarounds */ vtd_ops_postamble_quirk(iommu); @@ -642,8 +641,7 @@ static int __must_check iommu_flush_iotl } =20 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; =20 @@ -651,7 +649,7 @@ static int __must_check iommu_flush_iotl vtd_ops_preamble_quirk(iommu); =20 status =3D 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); =20 /* undo platform specific errata workarounds */ vtd_ops_postamble_quirk(iommu); @@ -661,26 +659,23 @@ static int __must_check iommu_flush_iotl =20 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; =20 /* 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); =20 /* 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); =20 /* apply platform specific errata workarounds */ vtd_ops_preamble_quirk(iommu); =20 status =3D iommu->flush.iotlb(iommu, did, addr, order, DMA_TLB_PSI_FLU= SH, - flush_non_present_entry, flush_dev_iotlb); + flush_non_present_entry, iommu->flush_dev_= iotlb); =20 /* 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 =3D 0; =20 flush_local(FLUSH_CACHE); @@ -703,8 +697,7 @@ static int __must_check iommu_flush_all( =20 iommu =3D drhd->iommu; context_rc =3D iommu_flush_context_global(iommu, 0); - flush_dev_iotlb =3D !!find_ats_dev_drhd(iommu); - iotlb_rc =3D iommu_flush_iotlb_global(iommu, 0, flush_dev_iotlb); + iotlb_rc =3D iommu_flush_iotlb_global(iommu, 0); =20 /* * The current logic for returns: @@ -734,7 +727,6 @@ static int __must_check cf_check iommu_f struct domain_iommu *hd =3D dom_iommu(d); struct acpi_drhd_unit *drhd; struct vtd_iommu *iommu; - bool flush_dev_iotlb; int iommu_domid; int ret =3D 0; =20 @@ -762,21 +754,18 @@ static int __must_check cf_check iommu_f if ( !test_bit(iommu->index, hd->arch.vtd.iommu_bitmap) ) continue; =20 - flush_dev_iotlb =3D !!find_ats_dev_drhd(iommu); iommu_domid =3D get_iommu_did(d->domain_id, iommu, !d->is_dying); if ( iommu_domid =3D=3D -1 ) continue; =20 if ( !page_count || (page_count & (page_count - 1)) || dfn_eq(dfn, INVALID_DFN) || !IS_ALIGNED(dfn_x(dfn), page_coun= t) ) - rc =3D iommu_flush_iotlb_dsi(iommu, iommu_domid, - 0, flush_dev_iotlb); + rc =3D iommu_flush_iotlb_dsi(iommu, iommu_domid, 0); else rc =3D iommu_flush_iotlb_psi(iommu, iommu_domid, dfn_to_daddr(dfn), get_order_from_pages(page_count), - !(flush_flags & IOMMU_FLUSHF_modifi= ed), - flush_dev_iotlb); + !(flush_flags & IOMMU_FLUSHF_modifi= ed)); =20 if ( rc > 0 ) iommu_flush_write_buffer(iommu); @@ -1488,7 +1477,6 @@ int domain_context_mapping_one( uint16_t seg =3D iommu->drhd->segment, prev_did =3D 0; struct domain *prev_dom =3D NULL; int rc, ret; - bool flush_dev_iotlb; =20 if ( QUARANTINE_SKIP(domain, pgd_maddr) ) return 0; @@ -1637,8 +1625,7 @@ int domain_context_mapping_one( =20 rc =3D iommu_flush_context_device(iommu, prev_did, PCI_BDF(bus, devfn), DMA_CCMD_MASK_NOBIT, !prev_dom); - flush_dev_iotlb =3D !!find_ats_dev_drhd(iommu); - ret =3D iommu_flush_iotlb_dsi(iommu, prev_did, !prev_dom, flush_dev_io= tlb); + ret =3D iommu_flush_iotlb_dsi(iommu, prev_did, !prev_dom); =20 /* * 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; =20 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); =20 - flush_dev_iotlb =3D !!find_ats_dev_drhd(iommu); - ret =3D iommu_flush_iotlb_dsi(iommu, iommu_domid, 0, flush_dev_iotlb); + ret =3D iommu_flush_iotlb_dsi(iommu, iommu_domid, 0); =20 /* * 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; =20 --- 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" =20 -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 =3D=3D iommu ) - return drhd; - } - return NULL; -} - int ats_device(const struct pci_dev *pdev, const struct acpi_drhd_unit *dr= hd) { - struct acpi_drhd_unit *ats_drhd; const struct acpi_satc_unit *satc; int pos; =20 @@ -61,17 +47,10 @@ int ats_device(const struct pci_dev *pde if ( opt_ats < 0 && (!satc || !satc->atc_required) ) return 0; =20 - ats_drhd =3D find_ats_dev_drhd(drhd->iommu); pos =3D pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS); + if ( pos ) + drhd->iommu->flush_dev_iotlb =3D true; =20 - if ( pos && (ats_drhd =3D=3D NULL) ) - { - ats_drhd =3D xmalloc(struct acpi_drhd_unit); - if ( !ats_drhd ) - return -ENOMEM; - *ats_drhd =3D *drhd; - list_add_tail(&ats_drhd->list, &ats_dev_drhd_units); - } return pos; } From nobody Sat Dec 21 14:23:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1707141434; cv=none; d=zohomail.com; s=zohoarc; b=dezamWc8S4NA1lsDxtqsLCJgg+Nc6gn9eCkqAWi6oGQmzcLlLhtqx5/m+rfFJVx2TQ/A8oWbqBUIVlNsHedO5ZiYV6/goVvVdmrji15zRAJ/5NjeRowwqdakiMh4yqQB9w64i1xrwSnsWIKuwuglV8FqtdE4tK6kEnXUkSiZkAo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707141434; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xeo9DHqLhyAKD6WkqcE7ZsPzOC6r3GO9FyNnjBbVjWg=; b=eVL4g5icdKU/0+AthdJVPdDhlEg9XiQEJxa+rNx2aAyPzF4G5EqdSA6XQ2Ttb61k2Zh/eF9vcpVVrAcT7rJUyugt8X07Wd8IRAoKTb5YJDs5fUBm78kpFXfhXWiuKJ8lDDpYqkSakTeTUjP7dKpjXd+Q+b7fltzXsmXh5yZnsN8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 17071414347753.5812526092511234; Mon, 5 Feb 2024 05:57:14 -0800 (PST) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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 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> Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707141436029100001 Content-Type: text/plain; charset="utf-8" ..., 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=C3=A9 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); =20 -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); =20 --- 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_ } } =20 +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 =3D acpi_find_matched_satc_unit(pdev); + if ( opt_ats < 0 && (!satc || !satc->atc_required) ) + return 0; + + pos =3D pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS); + if ( pos ) + drhd->iommu->flush_dev_iotlb =3D 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" =20 -int ats_device(const struct pci_dev *pdev, const struct acpi_drhd_unit *dr= hd) -{ - 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 =3D acpi_find_matched_satc_unit(pdev); - if ( opt_ats < 0 && (!satc || !satc->atc_required) ) - return 0; - - pos =3D pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS); - if ( pos ) - drhd->iommu->flush_dev_iotlb =3D true; - - return pos; -} - static bool device_in_domain(const struct vtd_iommu *iommu, const struct pci_dev *pdev, uint16_t did) { From nobody Sat Dec 21 14:23:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1707141452; cv=none; d=zohomail.com; s=zohoarc; b=KRpWsw7zaQLzW4b571x3xTfDEdRlTj7qNHpUlvMWNglltXS9mkbrRAFnKl9UsC8AofFWUU9dGLkcVf0EjN7xtFe5n13UPt5lSBi0qxNtXQ5Qjy0rzrVuK3OYLpf83T0xa3xBHRcw9u9K4IQCDplhr8UpIuc7n0sIzRxWVaWBWFY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707141452; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DHe5MlAMnMR5U49EdLt7+W2yJjwbBdMvr2wcdgX2lS0=; b=Sh0rc3j9IGOiVZqFJaPyzp+RcIuKcRR5s6hVhkIYE4P2W6w86ye1WtqIE6ms/CtzD+mR/f9YiJZzSGtC7BMV8KEXVfY9lOO1vbfQ2kNxcIeL7EfW5R3w83fCoa/O4+RlRpKBId94R44g4ZzbY4U0q4H3lBFVv2K+2XfDcNwb98k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707141452140367.3963681184962; Mon, 5 Feb 2024 05:57:32 -0800 (PST) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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 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> Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707141453466100001 Content-Type: text/plain; charset="utf-8" ..., 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=C3=A9 --- 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); =20 -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); =20 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; } =20 -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); } =20 +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 =3D NULL; + unsigned int tt; + bool found =3D false; + + if ( unlikely(!iommu->root_maddr) ) + { + ASSERT_UNREACHABLE(); + return false; + } + + root_entry =3D map_vtd_domain_page(iommu->root_maddr); + if ( !root_present(root_entry[pdev->bus]) ) + goto out; + + ctxt_entry =3D map_vtd_domain_page(root_entry[pdev->bus].val); + if ( context_domain_id(ctxt_entry[pdev->devfn]) !=3D did ) + goto out; + + tt =3D context_translation_type(ctxt_entry[pdev->devfn]); + if ( tt !=3D CONTEXT_TT_DEV_IOTLB ) + goto out; + + found =3D 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 =3D 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 =3D 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=3D1,bit_63=3D0,bit[62:12]= =3D1 */ + sbit =3D 1; + addr =3D (~0UL << PAGE_SHIFT_4K) & 0x7FFFFFFFFFFFFFFF; + rc =3D 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 <=3D 4K, set sbit =3D 0, else set sbit =3D 1 */ + sbit =3D size_order ? 1 : 0; + + /* clear lower bits */ + addr &=3D ~0UL << PAGE_SHIFT_4K; + + /* if sbit =3D=3D 1, zero out size_order bit and set lower bit= s to 1 */ + if ( sbit ) + { + addr &=3D ~((u64)PAGE_SIZE_4K << (size_order - 1)); + addr |=3D (((u64)1 << (size_order - 1)) - 1) << PAGE_SHIFT= _4K; + } + + rc =3D 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 =3D rc; + } + + return ret; +} + static int __must_check queue_invalidate_iec_sync(struct vtd_iommu *iommu, u8 granu, u8 im, u16 iid= x) { --- a/xen/drivers/passthrough/vtd/x86/Makefile +++ b/xen/drivers/passthrough/vtd/x86/Makefile @@ -1,2 +1 @@ -obj-y +=3D ats.o obj-y +=3D 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 f= or - * 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 =3D NULL; - unsigned int tt; - bool found =3D false; - - if ( unlikely(!iommu->root_maddr) ) - { - ASSERT_UNREACHABLE(); - return false; - } - - root_entry =3D map_vtd_domain_page(iommu->root_maddr); - if ( !root_present(root_entry[pdev->bus]) ) - goto out; - - ctxt_entry =3D map_vtd_domain_page(root_entry[pdev->bus].val); - if ( context_domain_id(ctxt_entry[pdev->devfn]) !=3D did ) - goto out; - - tt =3D context_translation_type(ctxt_entry[pdev->devfn]); - if ( tt !=3D CONTEXT_TT_DEV_IOTLB ) - goto out; - - found =3D 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 =3D 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 =3D 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=3D1,bit_63=3D0,bit[62:12]= =3D1 */ - sbit =3D 1; - addr =3D (~0UL << PAGE_SHIFT_4K) & 0x7FFFFFFFFFFFFFFF; - rc =3D 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 <=3D 4K, set sbit =3D 0, else set sbit =3D 1 */ - sbit =3D size_order ? 1 : 0; - - /* clear lower bits */ - addr &=3D ~0UL << PAGE_SHIFT_4K; - - /* if sbit =3D=3D 1, zero out size_order bit and set lower bit= s to 1 */ - if ( sbit ) - { - addr &=3D ~((u64)PAGE_SIZE_4K << (size_order - 1)); - addr |=3D (((u64)1 << (size_order - 1)) - 1) << PAGE_SHIFT= _4K; - } - - rc =3D 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 =3D rc; - } - - return ret; -} From nobody Sat Dec 21 14:23:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1707141464; cv=none; d=zohomail.com; s=zohoarc; b=JXZewAyEYwHfcgEJXsOiXo/VCJWnooxsHv84dvBDWb1QL93vfhUk4tU+IwdDf52fZJ/QhdmoAMr61QgLxsQOAWRQ06CDb7M1AxmH+cte9w4yHwmaojevDLwCtRWE7u41z5lawUQ7Wko8QIMl9mENgWGK3ffh56Fdq/qa/DOjdsc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707141464; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uXBzhqSfaSDHiztTRpLA+4XGmypB9k5L3zoFSjZ2FGw=; b=aU1rM4ONsGEhfVQ7Yo8Ij3qkOjx3PLAvVTrGwFllu2CPdSy4HX2xWnnWIvawigYj4dhurzUZu7KwawliDXDsFoHFLaT373R/de4l3euhXUyitsk7AnOyZZidQxwzNmAZjEfkESTnd1bHa2Bndn42CsskHcxocM6STnaWmSta11U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707141464065174.22282308459125; Mon, 5 Feb 2024 05:57:44 -0800 (PST) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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 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> Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707141465516100001 Content-Type: text/plain; charset="utf-8" ..., 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=3Dmap-inclusive" is similarly generic, and documentation also doesn't say anything. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monn=C3=A9 --- a/xen/drivers/passthrough/vtd/Makefile +++ b/xen/drivers/passthrough/vtd/Makefile @@ -1,5 +1,3 @@ -obj-$(CONFIG_X86) +=3D x86/ - obj-y +=3D iommu.o obj-y +=3D dmar.o obj-y +=3D utils.o --- a/xen/drivers/passthrough/vtd/extern.h +++ b/xen/drivers/passthrough/vtd/extern.h @@ -21,6 +21,7 @@ #define _VTD_EXTERN_H_ =20 #include "dmar.h" +#include #include =20 #define VTDPREFIX "[VT-D]" @@ -68,8 +69,6 @@ struct acpi_rhsa_unit *drhd_to_rhsa(cons =20 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 *io= mmu, 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); =20 +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 +=3D 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 f= or - * 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 =3D true; =20 enum iommu_intremap __read_mostly iommu_intremap =3D iommu_intremap_full; =20 +/* + * 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;