From nobody Mon Sep 16 19:15:48 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+LpBtvjBu1R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qF4rnB0AQD12/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; }