From patchwork Thu Feb 15 10:13:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13557781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F2B3DC4829E for ; Thu, 15 Feb 2024 10:13:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681472.1060253 (Exim 4.92) (envelope-from ) id 1raYkE-00087K-8h; Thu, 15 Feb 2024 10:13:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681472.1060253; Thu, 15 Feb 2024 10:13:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1raYkE-00087D-6E; Thu, 15 Feb 2024 10:13:30 +0000 Received: by outflank-mailman (input) for mailman id 681472; Thu, 15 Feb 2024 10:13:28 +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 1raYkC-000877-Q4 for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 10:13:28 +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 dbd172f2-cbea-11ee-98f5-efadbce2ee36; Thu, 15 Feb 2024 11:13:26 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4121a8635a2so2697005e9.3 for ; Thu, 15 Feb 2024 02:13:26 -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 bs3-20020a056000070300b0033b45bdb2a1sm1361072wrb.4.2024.02.15.02.13.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Feb 2024 02:13:25 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: dbd172f2-cbea-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707992006; x=1708596806; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=kaaCGUPluoRwbjKkcfJEfltfLrIYbRueMH6UyOi+fqA=; b=Vd3Xrg6XndVs6UwuGMJ67Hvv+h71ufP30hEAK6md2Wh2UZwJ5e+YCH/Vh6r9sG2Rhp Tjx+GMdJB/tfjBDyXHvihrrbjMrQ9kNqdN8pHZBD9EEPrI9YA1THblFP0K2vHO+DX9op g9FnP1fJjpxjvZIviNucrvkiWyJo53DWFD2sq4jhs53P2FVEMGWOXWMbHCV5TFoxeYht FmPBBMmR/tNIr7eoeFXDP8UrsDUmaFbyF+tY4VjfUDQm7qfmOQZOBycR5d7nH31iOyrM OI+EDygncUH0MWjagC9oJGEu5dYh/6n7RK7ipG4X9R8AOHxVa9QBT20WeS/iuXONWnoa lGQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707992006; x=1708596806; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kaaCGUPluoRwbjKkcfJEfltfLrIYbRueMH6UyOi+fqA=; b=wIECJdEa3hGjD+qNbjoyCG0ghokd0vjLxdQHsWtkMVsy3oW/DzgH/xxiM6RVjPkix9 7vys7T0Pdoq7oN1dJT5mRgdUE1Vwx2ku7ji1Ve//OgJlCbIJG6n7iL2evWAJ2Xw/NHPN 1wsonEHJXhqsdIK3k4gGbxGkMww60fToa0b5rxd15auqTAa4W6A1kA/sq6sbc5S3BoPz iJVx5S2HsOOagtnaJfV9L/DkgulQPDHSh+cPIVYC1nkJpGouDgjw6p7PyRUCR1R6dubN VU3QHD3v3nLbBmeetP/iF/fb60jroBzEudv/L2dx4d5NqujFUaiyuCQnqGCAmtJfhGOk 6B+A== X-Gm-Message-State: AOJu0YyLrzkVAUD5xN9zhLaZZ/uemxqtVvchyN3SY+QeWQ6zwONIw/ot GoeOgbQsQ4DzU7Ryl62BUlsHIl10t+EETGu66zYQ+95QTZaP6q/wPVnXMbExKDTnz6hvPGsD/GI = X-Google-Smtp-Source: AGHT+IH1qlDa3iBjsRLyla193sMpUv7aYmnrfSROwwzh0LTnvgsw6UdyGbNpFEs8UsZtldmOTZ0/kQ== X-Received: by 2002:a05:600c:34c1:b0:411:c25d:703b with SMTP id d1-20020a05600c34c100b00411c25d703bmr1072716wmq.16.1707992006185; Thu, 15 Feb 2024 02:13:26 -0800 (PST) Message-ID: <3686dae7-e005-47b5-9235-14208a68eec5@suse.com> Date: Thu, 15 Feb 2024 11:13:24 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 01/12] VT-d: correct ATS checking for root complex integrated devices From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Kevin Tian , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Paul Durrant References: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3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3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> Spec version 4.1 says "The ATSR structures identifies PCI Express Root-Ports supporting Address Translation Services (ATS) transactions. Software must enable ATS on endpoint devices behind a Root Port only if the Root Port is reported as supporting ATS transactions." Clearly root complex integrated devices aren't "behind root ports", matching my observation on a SapphireRapids system having an ATS- capable root complex integrated device. Hence for such devices we shouldn't try to locate a corresponding ATSR. Since both pci_find_ext_capability() and pci_find_cap_offset() return "unsigned int", change "pos" to that type at the same time. Fixes: 903b93211f56 ("[VTD] laying the ground work for ATS") Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné --- v2: New. --- a/xen/drivers/passthrough/vtd/x86/ats.c +++ b/xen/drivers/passthrough/vtd/x86/ats.c @@ -44,7 +44,7 @@ struct acpi_drhd_unit *find_ats_dev_drhd int ats_device(const struct pci_dev *pdev, const struct acpi_drhd_unit *drhd) { struct acpi_drhd_unit *ats_drhd; - int pos; + unsigned int pos, expfl = 0; if ( !ats_enabled || !iommu_qinval ) return 0; @@ -53,7 +53,12 @@ int ats_device(const struct pci_dev *pde !ecap_dev_iotlb(drhd->iommu->ecap) ) return 0; - if ( !acpi_find_matched_atsr_unit(pdev) ) + pos = pci_find_cap_offset(pdev->sbdf, PCI_CAP_ID_EXP); + if ( pos ) + expfl = pci_conf_read16(pdev->sbdf, pos + PCI_EXP_FLAGS); + + if ( MASK_EXTR(expfl, PCI_EXP_FLAGS_TYPE) != PCI_EXP_TYPE_RC_END && + !acpi_find_matched_atsr_unit(pdev) ) return 0; ats_drhd = find_ats_dev_drhd(drhd->iommu); From patchwork Thu Feb 15 10:14:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13557820 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA8ADC4829E for ; Thu, 15 Feb 2024 10:14:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681476.1060263 (Exim 4.92) (envelope-from ) id 1raYko-0000Ac-H5; Thu, 15 Feb 2024 10:14:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681476.1060263; Thu, 15 Feb 2024 10:14:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1raYko-0000AU-E7; Thu, 15 Feb 2024 10:14:06 +0000 Received: by outflank-mailman (input) for mailman id 681476; Thu, 15 Feb 2024 10:14:05 +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 1raYkn-000877-Gm for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 10:14:05 +0000 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [2a00:1450:4864:20::433]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f1d22946-cbea-11ee-98f5-efadbce2ee36; Thu, 15 Feb 2024 11:14:03 +0100 (CET) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-33d01faf711so279534f8f.1 for ; Thu, 15 Feb 2024 02:14:03 -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 bs3-20020a056000070300b0033b45bdb2a1sm1361072wrb.4.2024.02.15.02.14.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Feb 2024 02:14:02 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f1d22946-cbea-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707992043; x=1708596843; 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=KU/lqMLMrEbpy7S9jjdmyz27GyrWioKTxk0YxtgDY6A=; b=RS3sxTB80kNFYvvxKXiD5fE0JIuIb67cB56i/lx9KLxTbqVdvFtyGwTNBkQDt8uK+B 5Lf4rVj9wWbuNSK4ZTQwMXO383WJuFh24TabAOtifO5tyW020EW8XMdxJozZiSRDQv24 Ubays/0ZbEkRUPEmO3A7xuTO4fM2nZuExrj02cJAWYgtxbgZST57sSVZ84H7phEYKKFG EZX+SYzAYsfddiVWfgcuq7MD3CRVv+HQ/Du6oaxHwFfppwWLTcNgJDXB/evAFhezaTfx lzsA1+nAVvHgSCofOsFNAgd8T4HjV7Zg2iwHtayUdGebmMSIbUUkA6NKTqqxHUYZBttN 5mvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707992043; x=1708596843; 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=KU/lqMLMrEbpy7S9jjdmyz27GyrWioKTxk0YxtgDY6A=; b=d0UtahmGns4m50McaFNC12u5tDfnfuCyxfy18uGz1hb6pXlzyE8eGv5HZVFvPcP5zi ejSvHDes1aH1rYTbFV/KFXgA2E7ogTZVC0SoJM2pH+N2eu831yW3kDpjEQRG8zC9liE0 VPgSghg/spFOcxWy47fWcGBawD6OQX+pziYiqHW1xGi6OHMZjCo2o0v6bkkyBSptr1kT UMjzKRAJBmnBZZOBFtUCpCmMJgWBkA+HFMYBMO5L96GrPuF+5QYGKH+lBF2L6/zBjy0u hCRwzTwVlfKkgGRT70vz8qYUFW2ltuMBCb0J7zSFc3Ccc98Fw1wUq34L4jxNb8ObuaPk fgng== X-Gm-Message-State: AOJu0YzLq+x3ftdxcWLtQOiHn7Z2f6B88k8Fasv//syiDOuPBJXZanVa 89Q+P9Gc8x8R78Wm7dzgBz2hGnmJo74p+seazMh1zE0+N1ABJF4xDrUDyKKwLBQDWDkR3Gg1H3U = X-Google-Smtp-Source: AGHT+IHKaWfAiFYhRjDVVpSwFB7pRSbD3IcCQS5JuxOtu7EYgKWLGl4fizouEZ0cB440LcqOK4QmQw== X-Received: by 2002:a5d:5591:0:b0:33c:d139:66fb with SMTP id i17-20020a5d5591000000b0033cd13966fbmr1219944wrv.52.1707992043032; Thu, 15 Feb 2024 02:14:03 -0800 (PST) Message-ID: <97577ebf-3871-47be-97c5-8164701be756@suse.com> Date: Thu, 15 Feb 2024 11:14:02 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 02/12] VT-d: tidy error handling of RMRR parsing 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: <64b028be-2197-4951-ae5b-32f9eabfa84a@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: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> It's acpi_parse_one_rmrr() where the allocation is coming from (by way of invoking acpi_parse_dev_scope()), or in add_one_user_rmrr()'s case allocation is even open-coded there, so freeing would better also happen there. Care needs to be taken to preserve acpi_parse_one_rmrr()'s ultimate return value. While fiddling with callers also move scope_devices_free() to .init and have it use XFREE() instead of open-coding it. In register_one_rmrr() also have the "ignore" path take the main function return path. Suggested-by: Roger Pau Monné Signed-off-by: Jan Beulich Reviewed-by: Roger Pau Monné --- v2: New. --- a/xen/drivers/passthrough/vtd/dmar.c +++ b/xen/drivers/passthrough/vtd/dmar.c @@ -82,14 +82,13 @@ static int __init acpi_register_rmrr_uni return 0; } -static void scope_devices_free(struct dmar_scope *scope) +static void __init scope_devices_free(struct dmar_scope *scope) { if ( !scope ) return; scope->devices_cnt = 0; - xfree(scope->devices); - scope->devices = NULL; + XFREE(scope->devices); } static void __init disable_all_dmar_units(void) @@ -595,17 +594,13 @@ static int register_one_rmrr(struct acpi " Ignore RMRR [%"PRIx64",%"PRIx64"] as no device" " under its scope is PCI discoverable!\n", rmrru->base_address, rmrru->end_address); - scope_devices_free(&rmrru->scope); - xfree(rmrru); - return 1; + ret = 1; } else if ( rmrru->base_address > rmrru->end_address ) { dprintk(XENLOG_WARNING VTDPREFIX, " RMRR [%"PRIx64",%"PRIx64"] is incorrect!\n", rmrru->base_address, rmrru->end_address); - scope_devices_free(&rmrru->scope); - xfree(rmrru); ret = -EFAULT; } else @@ -660,21 +655,20 @@ acpi_parse_one_rmrr(struct acpi_dmar_hea &rmrru->scope, RMRR_TYPE, rmrr->segment); if ( !ret && (rmrru->scope.devices_cnt != 0) ) - { ret = register_one_rmrr(rmrru); - /* - * register_one_rmrr() returns greater than 0 when a specified - * PCIe device cannot be detected. To prevent VT-d from being - * disabled in such cases, reset the return value to 0 here. - */ - if ( ret > 0 ) - ret = 0; - } - else + if ( ret ) + { + scope_devices_free(&rmrru->scope); xfree(rmrru); + } - return ret; + /* + * register_one_rmrr() returns greater than 0 when a specified PCIe + * device cannot be detected. To prevent VT-d from being disabled in + * such cases, make the return value 0 here. + */ + return ret > 0 ? 0 : ret; } static int __init @@ -945,9 +939,13 @@ static int __init add_one_user_rmrr(unsi rmrr->scope.devices_cnt = dev_count; if ( register_one_rmrr(rmrr) ) + { printk(XENLOG_ERR VTDPREFIX "Could not register RMMR range "ERMRRU_FMT"\n", ERMRRU_ARG); + scope_devices_free(&rmrr->scope); + xfree(rmrr); + } return 1; } From patchwork Thu Feb 15 10:14:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13557821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4137DC4829E for ; Thu, 15 Feb 2024 10:14:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681481.1060273 (Exim 4.92) (envelope-from ) id 1raYlG-0000kQ-RK; Thu, 15 Feb 2024 10:14:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681481.1060273; Thu, 15 Feb 2024 10:14:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1raYlG-0000kJ-Of; Thu, 15 Feb 2024 10:14:34 +0000 Received: by outflank-mailman (input) for mailman id 681481; Thu, 15 Feb 2024 10:14:33 +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 1raYlF-0000Sx-JE for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 10:14:33 +0000 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [2a00:1450:4864:20::32b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0329edfd-cbeb-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 11:14:32 +0100 (CET) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-41205e19660so4893155e9.2 for ; Thu, 15 Feb 2024 02:14:32 -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 bs3-20020a056000070300b0033b45bdb2a1sm1361072wrb.4.2024.02.15.02.14.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Feb 2024 02:14:32 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0329edfd-cbeb-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707992072; x=1708596872; 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=fj8qUorQgdMO+SEeflpHtiiMwgxTjCex7pYcfIyVQuE=; b=e8tdgsXF24xURiNWHJri0h8BL3XuKB77vTGJOPmBLlJoW+thPghgJRRx3kEwBLr1R/ FZmIw03rDpYS7WNPa6hY/CFsC9ioUNb6K6MsF9OQA9GHj2b4HIJ3wEaQHaAGHOGgrpF/ 4DTlysSVws1n7xcZyMoAFvZ/Qoh4/dmv6/pFqfqfYL/e/pNU1OmyVHEBl975sbhIT5Je hM3vR6VWI7WHvn+v9KXekTslM0nSpR0gyUJWWjJSkwJ2fkoyGGRbHgGIOUiIcKn/DMx4 6oYjQ5fPOOIWwr2Bv58uCsvr3EC49j7NSupJVpRx72cHSFn+tM/5xEG+B5bDhTMEPOci EihA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707992072; x=1708596872; 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=fj8qUorQgdMO+SEeflpHtiiMwgxTjCex7pYcfIyVQuE=; b=kgbzVEAOoNzsu/7ETPu7ksmEwjD6sQ1TRLgmjF+/zafCkMHhYMxzXJvBGEWYMbyPtr btRP0CNSEtEd/MFb5zBQUNThH7vJUdlYJ1tUhWuNMFVtLYiFd8RtmdNiisN3W9QAP2Je HYqeONnuk/4PnyPCwVYtSCNy5qk54GZ/hCo6p3R/hIMYdMvGBY0hOShNX7y9DNoI2JJn 3f7gHkBtX30DjHZxVQIb31aPebdKepNDLX29ZUlBw/PzljvSwJxB/eI8975KQTRYnQSl p964f7uKutSrTekG8h1l8wgqZnw2tjcSvYp+MP5dtdkm69k/TC0hO+4wDErNR+TZVA3p KvTA== X-Gm-Message-State: AOJu0YxrzXSvlIV9/TNOE6OEgck+eZZomH/JeK5oczLVmsLHzbx5Ixg0 fdLtgKrtehIfn8GAAsGGBqANEeptpB/vYM4sAhfwB5GWcOHDWlyMVUx2FURVwDcXtd1s+ATlPP4 = X-Google-Smtp-Source: AGHT+IGFGMj7EAeEq5MHaPpPZFlgUlUywi+V2oHpegmyE6iJJ0Ys0Olf4VeGGL4VOtkXN+7+isl0vQ== X-Received: by 2002:adf:ec82:0:b0:33b:1a39:e501 with SMTP id z2-20020adfec82000000b0033b1a39e501mr874165wrn.28.1707992072274; Thu, 15 Feb 2024 02:14:32 -0800 (PST) Message-ID: Date: Thu, 15 Feb 2024 11:14:31 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 03/12] 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: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX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ZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> This is a prereq to us, in particular, respecting the "ATC required" flag. Note that ACPI_SATC_ATC_REQUIRED has its #define put in dmar.h, as we try to keep actbl*.h in sync what Linux (who in turn inherit from ACPI CA) has. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné --- Lovely: On the SPR system with the SATC I tried passing "ats" (the "required" flag is clear there), just to then hit "IOMMU#4: QI dev wait descriptor taking too long" while setting up Dom0. The 2nd message there doesn't ever appear, so the request never completes. Not sure whether that's us doing something wrong or the hardware acting up. In the former case I'd generally expect an IOMMU fault to be raised, though. FTR same on 4.18 with just "VT-d: correct ATS checking for root complex integrated devices" backported there. Should we check scope entries for appropriate types? (If so, then also for e.g. ATSR.) --- v2: Move error case freeing to acpi_parse_one_satc(). Introduce #define for the flag bit. Style. --- a/xen/drivers/passthrough/vtd/dmar.c +++ b/xen/drivers/passthrough/vtd/dmar.c @@ -47,6 +47,7 @@ LIST_HEAD_READ_MOSTLY(acpi_drhd_units); LIST_HEAD_READ_MOSTLY(acpi_rmrr_units); static LIST_HEAD_READ_MOSTLY(acpi_atsr_units); static LIST_HEAD_READ_MOSTLY(acpi_rhsa_units); +static LIST_HEAD_READ_MOSTLY(acpi_satc_units); static struct acpi_table_header *__read_mostly dmar_table; static int __read_mostly dmar_flags; @@ -750,6 +751,93 @@ acpi_parse_one_rhsa(struct acpi_dmar_hea return ret; } +static int __init register_one_satc(struct acpi_satc_unit *satcu) +{ + bool ignore = false; + unsigned int i = 0; + int ret = 0; + + /* Skip checking if segment is not accessible yet. */ + if ( !pci_known_segment(satcu->segment) ) + i = UINT_MAX; + + for ( ; i < satcu->scope.devices_cnt; i++ ) + { + uint8_t b = PCI_BUS(satcu->scope.devices[i]); + uint8_t d = PCI_SLOT(satcu->scope.devices[i]); + uint8_t f = PCI_FUNC(satcu->scope.devices[i]); + + if ( !pci_device_detect(satcu->segment, b, d, f) ) + { + dprintk(XENLOG_WARNING VTDPREFIX, + " Non-existent device (%pp) is reported in SATC scope!\n", + &PCI_SBDF(satcu->segment, b, d, f)); + ignore = true; + } + else + { + ignore = false; + break; + } + } + + if ( ignore ) + { + dprintk(XENLOG_WARNING VTDPREFIX, + " Ignore SATC for seg %04x as no device under its scope is PCI discoverable\n", + satcu->segment); + return 1; + } + + if ( iommu_verbose ) + printk(VTDPREFIX " ATC required: %d\n", satcu->atc_required); + + list_add(&satcu->list, &acpi_satc_units); + + return ret; +} + +static int __init +acpi_parse_one_satc(const struct acpi_dmar_header *header) +{ + const struct acpi_dmar_satc *satc = + container_of(header, const struct acpi_dmar_satc, header); + struct acpi_satc_unit *satcu; + const void *dev_scope_start, *dev_scope_end; + int ret = acpi_dmar_check_length(header, sizeof(*satc)); + + if ( ret ) + return ret; + + satcu = xzalloc(struct acpi_satc_unit); + if ( !satcu ) + return -ENOMEM; + + satcu->segment = satc->segment; + satcu->atc_required = satc->flags & ACPI_SATC_ATC_REQUIRED; + + dev_scope_start = (const void *)(satc + 1); + dev_scope_end = (const void *)satc + header->length; + ret = acpi_parse_dev_scope(dev_scope_start, dev_scope_end, + &satcu->scope, SATC_TYPE, satc->segment); + + if ( !ret && satcu->scope.devices_cnt ) + ret = register_one_satc(satcu); + + if ( ret ) + { + scope_devices_free(&satcu->scope); + xfree(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, make the return value 0 here. + */ + return ret > 0 ? 0 : ret; +} + static int __init cf_check acpi_parse_dmar(struct acpi_table_header *table) { struct acpi_table_dmar *dmar; @@ -803,6 +891,13 @@ static int __init cf_check acpi_parse_dm printk(VTDPREFIX "found ACPI_DMAR_RHSA:\n"); ret = acpi_parse_one_rhsa(entry_header); break; + + case ACPI_DMAR_TYPE_SATC: + if ( iommu_verbose ) + printk(VTDPREFIX "found ACPI_DMAR_SATC:\n"); + ret = acpi_parse_one_satc(entry_header); + break; + default: dprintk(XENLOG_WARNING VTDPREFIX, "Ignore unknown DMAR structure type (%#x)\n", --- a/xen/drivers/passthrough/vtd/dmar.h +++ b/xen/drivers/passthrough/vtd/dmar.h @@ -91,6 +91,16 @@ struct acpi_rhsa_unit { u32 proximity_domain; }; +struct acpi_satc_unit { + struct dmar_scope scope; + struct list_head list; + uint16_t segment; + bool atc_required:1; +}; + +/* In lieu of a definition in actbl2.h. */ +#define ACPI_SATC_ATC_REQUIRED (1U << 0) + #define for_each_drhd_unit(drhd) \ list_for_each_entry(drhd, &acpi_drhd_units, list) @@ -106,6 +116,7 @@ struct acpi_atsr_unit *acpi_find_matched #define DMAR_TYPE 1 #define RMRR_TYPE 2 #define ATSR_TYPE 3 +#define SATC_TYPE 4 #define DMAR_OPERATION_TIMEOUT MILLISECS(1000) --- a/xen/include/acpi/actbl2.h +++ b/xen/include/acpi/actbl2.h @@ -345,7 +345,8 @@ enum acpi_dmar_type { ACPI_DMAR_TYPE_RESERVED_MEMORY = 1, ACPI_DMAR_TYPE_ATSR = 2, ACPI_DMAR_HARDWARE_AFFINITY = 3, - ACPI_DMAR_TYPE_RESERVED = 4 /* 4 and greater are reserved */ + ACPI_DMAR_TYPE_SATC = 5, + ACPI_DMAR_TYPE_RESERVED = 7 /* 7 and greater are reserved */ }; /* DMAR Device Scope structure */ @@ -427,6 +428,15 @@ struct acpi_dmar_rhsa { u32 proximity_domain; }; +/* 5: SOC Integrated Address Translation Cache Reporting Structure */ + +struct acpi_dmar_satc { + struct acpi_dmar_header header; + uint8_t flags; + uint8_t reserved; + uint16_t segment; +}; + /******************************************************************************* * * HPET - High Precision Event Timer table From patchwork Thu Feb 15 10:15:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13557822 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 81CB4C4829E for ; Thu, 15 Feb 2024 10:15:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681488.1060282 (Exim 4.92) (envelope-from ) id 1raYlx-0001HP-36; Thu, 15 Feb 2024 10:15:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681488.1060282; Thu, 15 Feb 2024 10:15: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 1raYlx-0001HI-0a; Thu, 15 Feb 2024 10:15:17 +0000 Received: by outflank-mailman (input) for mailman id 681488; Thu, 15 Feb 2024 10:15: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 1raYlv-0001H1-GX for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 10:15:15 +0000 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [2a00:1450:4864:20::429]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1b66a041-cbeb-11ee-98f5-efadbce2ee36; Thu, 15 Feb 2024 11:15:13 +0100 (CET) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-33cf7812777so360866f8f.0 for ; Thu, 15 Feb 2024 02:15: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 bs3-20020a056000070300b0033b45bdb2a1sm1361072wrb.4.2024.02.15.02.15.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Feb 2024 02:15:12 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1b66a041-cbeb-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707992113; x=1708596913; 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=0wmyC+dd48xUA9r3hY+U4fMTTXevckC3qoc0ZYZfRhM=; b=USz6MfuGjH/VMGz2zKdeerjYyC7kDh6JwBzQ8044JHn24DXU7ohqZOKuvoza72pRKK 3chya4b/n7xptNoAKF/z4kUG8xFmOaAlplD4YAfoJKC6BFOCRYJcgbo2o272oSZnhbQr qS0gDHtiu/pHHMO+APqHLEKFZH71ItpC5qvE7BpK7B44ZvxwvDW1WRwXMvYAV2KfKBHg wpdrlLWDSP9T2xPhFsYyyPCHEmCEt8Q7u5vmInI2WRN5SqUdYImGaZThgJsDXNR5XXLa 1AuzbQ9cJ6K+PGv57YjikhDCzWqHueERg+mIOI/rWLkKqDOGMCYWuqyby4jEjjoVZf4F rsgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707992113; x=1708596913; 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=0wmyC+dd48xUA9r3hY+U4fMTTXevckC3qoc0ZYZfRhM=; b=dqyULo5DNb3HClvNF64EoSsWJAhpWf32uAShRYag+7JpzdOxdsZ0vEQQC3uPWIPgNM CbpElsY7l63JcsVdYu3+oREOB+0flFrEJXDo84BB6mheWTYtAOy3gRCiqELoSQGAKCJ1 7ovLXb3bUV9K8TEEOcrF2b8Y0qGck4VE6N5jWPTv7Ng0C23nS+Eyi7CIBN1vFGEtDxCq gHiKTpEp/Ux+uoNNOZS7hbmyyqoDu1KThtPSvLbDqSaikvEwMSlJQhreu8VHLqXyvzPY FnmSqqy6pb+bJQboCNBLaRhozx8wKE2IRLO2YcRmx2jDRnT7iH4CWGwomhGA32z/12be bOOQ== X-Gm-Message-State: AOJu0Yxm4mFGcrrFcNWRFHuNZw7Xnia1V5Fj3CpJfRI5TKxa6/dJuLzj LhrvrrguA4xeAfqmYD+62uZtX42CvS6ciqpmQoS++irJde8VArTk48YJLCTfCTOgw81gzgyuL7M = X-Google-Smtp-Source: AGHT+IGyu8WOKpuuNtyzo0ztbULmjaz0cTNntwvaxaHRhmZlM8/A6Elcft8I2B1XFnN9DAfe5SK+/Q== X-Received: by 2002:a5d:4a4f:0:b0:33b:5087:c913 with SMTP id v15-20020a5d4a4f000000b0033b5087c913mr1055855wrs.54.1707992112857; Thu, 15 Feb 2024 02:15:12 -0800 (PST) Message-ID: Date: Thu, 15 Feb 2024 11:15:12 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 04/12] AMD/IOMMU: add helper to check whether ATS is to be used for a device Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Paul Durrant , Andrew Cooper References: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9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GQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> The same set of conditions is used in three places, requiring to be kept in sync. Introduce a helper to centralize these checks. To allow all parameters of the new helper be pointer-to-const, iommu_has_cap() also needs its 1st parameter to be constified. Beyond that further "modernize" that function. Requested-by: Roger Pau Monné Signed-off-by: Jan Beulich Reviewed-by: Roger Pau Monné --- v2: New. --- a/xen/drivers/passthrough/amd/iommu.h +++ b/xen/drivers/passthrough/amd/iommu.h @@ -404,9 +404,9 @@ static inline void __free_amd_iommu_tabl free_xenheap_pages(table, order); } -static inline int iommu_has_cap(struct amd_iommu *iommu, uint32_t bit) +static inline bool iommu_has_cap(const struct amd_iommu *iommu, unsigned int bit) { - return !!(iommu->cap.header & (1u << bit)); + return iommu->cap.header & (1u << bit); } /* access device id field from iommu cmd */ --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -114,6 +114,16 @@ static bool any_pdev_behind_iommu(const return false; } +static bool use_ats( + const struct pci_dev *pdev, + const struct amd_iommu *iommu, + const struct ivrs_mappings *ivrs_dev) +{ + return !ivrs_dev->block_ats && + iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) && + pci_ats_device(iommu->seg, pdev->bus, pdev->devfn); +} + static int __must_check amd_iommu_setup_domain_device( struct domain *domain, struct amd_iommu *iommu, uint8_t devfn, struct pci_dev *pdev) @@ -185,9 +195,7 @@ static int __must_check amd_iommu_setup_ dte->ex = ivrs_dev->dte_allow_exclusion; dte->sys_mgt = MASK_EXTR(ivrs_dev->device_flags, ACPI_IVHD_SYSTEM_MGMT); - if ( pci_ats_device(iommu->seg, bus, pdev->devfn) && - !ivrs_dev->block_ats && - iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) ) + if ( use_ats(pdev, iommu, ivrs_dev) ) dte->i = ats_enabled; spin_unlock_irqrestore(&iommu->lock, flags); @@ -248,9 +256,7 @@ static int __must_check amd_iommu_setup_ ASSERT(dte->sys_mgt == MASK_EXTR(ivrs_dev->device_flags, ACPI_IVHD_SYSTEM_MGMT)); - if ( pci_ats_device(iommu->seg, bus, pdev->devfn) && - !ivrs_dev->block_ats && - iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) ) + if ( use_ats(pdev, iommu, ivrs_dev) ) ASSERT(dte->i == ats_enabled); spin_unlock_irqrestore(&iommu->lock, flags); @@ -268,9 +274,7 @@ static int __must_check amd_iommu_setup_ ASSERT(pcidevs_locked()); - if ( pci_ats_device(iommu->seg, bus, pdev->devfn) && - !ivrs_dev->block_ats && - iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) && + if ( use_ats(pdev, iommu, ivrs_dev) && !pci_ats_enabled(iommu->seg, bus, pdev->devfn) ) { if ( devfn == pdev->devfn ) From patchwork Thu Feb 15 10:15:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13557823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2A673C4829E for ; Thu, 15 Feb 2024 10:15:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681490.1060293 (Exim 4.92) (envelope-from ) id 1raYmM-0001lj-CX; Thu, 15 Feb 2024 10:15:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681490.1060293; Thu, 15 Feb 2024 10:15:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1raYmM-0001lY-7c; Thu, 15 Feb 2024 10:15:42 +0000 Received: by outflank-mailman (input) for mailman id 681490; Thu, 15 Feb 2024 10:15:41 +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 1raYmL-0001ZT-3o for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 10:15:41 +0000 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [2a00:1450:4864:20::42b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2b716d5d-cbeb-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 11:15:40 +0100 (CET) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-339289fead2so377451f8f.3 for ; Thu, 15 Feb 2024 02:15:40 -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 bs3-20020a056000070300b0033b45bdb2a1sm1361072wrb.4.2024.02.15.02.15.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Feb 2024 02:15:39 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2b716d5d-cbeb-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707992140; x=1708596940; 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=gocTw3drw4/MldPbi03GFmG0diUgBYkMjWI02M8R94k=; b=YoeDS2lZx4qkPuxr6nyw8h4lIMFW2T+tijVEWGdk7iFQA6mMyUmtVw6C5cHH1SnL7E M/ov3lqSlZSoA9JzfHIbvDNtmdqQh2eCpXURvjBicmAE+riF52fCH3Ctmuc7SOTlPWUH wjrS2+cNs0EHVC0nlKXZvPL9GZcEIqnwbKzChH18xJcrZyVLeZ2LVLwFEq45lIvWU6Zw NpI53bICnXZZwn15arEevfsOS2fZ59URfu32x5733VD5LnUpgCTDT8RsFgc86jVNMgoq XkknDeTmpzmx4X3OodrL6JMFRb86vSal6m8Uoxso+hHepjRuhcLedxTuD5ns8oFOMkAD j3AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707992140; x=1708596940; 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=gocTw3drw4/MldPbi03GFmG0diUgBYkMjWI02M8R94k=; b=D9TeeT80adyBIGUxbeSLdFXANcUrl3XPzt97YSQpLvQO0VFpNRaclD7pCnPuZblPxQ muaOnbY9WW/GYU5G32+gBNVL2bRcaBERLuKsEHlZA9eVgwjSiH3w6mGRIEjqHIy4/aOO hu7Yyy+7Q234nK5U8H6bMCNhJttj1oA5c4hcebi9cwnSRzHwufmQDQwgflbROxfF3Q2A NVAYL6lAdQUFYnMW+V0WMV4e6FrYAMU9wQQnjqn+oqQ4r7VWVxu7BatWw1GngNA2t0qr BddkzBevczdU2Z3jEuOMate56TfzazNOgCQFwiqNsMqDi/SEvF7+fuHwq0JRrI01CsXA hleg== X-Gm-Message-State: AOJu0Yzp0biwbjAB7Two7fF4kFS8yVxX97sv3TnTnmeXD6ZxGDPg4LIi KFS4D6dH1z4uzCd/NBHwvgtLFcleien85IsNDi5rPkb2VrwXxrJli4kVwN42rmT+HCjyY/vTYdw = X-Google-Smtp-Source: AGHT+IEoOerVJ4qI6jh0D6P7vaV4hh6KoDawu6j/5/bl736eUS0wdzKYkiDCBkV8iHrfET6mnp+gkQ== X-Received: by 2002:a5d:660e:0:b0:33c:f9d6:fb20 with SMTP id n14-20020a5d660e000000b0033cf9d6fb20mr1025439wru.45.1707992139790; Thu, 15 Feb 2024 02:15:39 -0800 (PST) Message-ID: <7f11ca06-9bed-443b-9c79-0e62b71a1f96@suse.com> Date: Thu, 15 Feb 2024 11:15:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 05/12] 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 References: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmB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wSHEeAWPgskBQL In-Reply-To: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> Make the variable a tristate, with (as done elsewhere) a negative value meaning "default". Since all use sites need looking at, also rename it to match our usual "opt_*" pattern. While touching it, also move it to .data.ro_after_init. The only place it retains boolean nature is pci_ats_device(), for now. In AMD code re-order conditionals to have the config space accesses after (cheaper) flag checks. Signed-off-by: Jan Beulich --- In domain_context_mapping_one() I'm a little puzzled that translation type is selected based on only IOMMU and global properties, i.e. not taking the device itself into account. --- v2: Re-base over new earlier patches. --- a/xen/drivers/passthrough/amd/iommu_cmd.c +++ b/xen/drivers/passthrough/amd/iommu_cmd.c @@ -282,7 +282,7 @@ void amd_iommu_flush_iotlb(u8 devfn, con struct amd_iommu *iommu; unsigned int req_id, queueid, maxpend; - if ( !ats_enabled ) + if ( opt_ats <= 0 ) return; if ( !pci_ats_enabled(pdev->seg, pdev->bus, pdev->devfn) ) @@ -340,7 +340,7 @@ static void _amd_iommu_flush_pages(struc flush_command_buffer(iommu, 0); } - if ( ats_enabled ) + if ( opt_ats > 0 ) { amd_iommu_flush_all_iotlbs(d, daddr, order); --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -119,7 +119,7 @@ static bool use_ats( const struct amd_iommu *iommu, const struct ivrs_mappings *ivrs_dev) { - return !ivrs_dev->block_ats && + return opt_ats > 0 && !ivrs_dev->block_ats && iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) && pci_ats_device(iommu->seg, pdev->bus, pdev->devfn); } @@ -196,7 +196,7 @@ static int __must_check amd_iommu_setup_ dte->sys_mgt = MASK_EXTR(ivrs_dev->device_flags, ACPI_IVHD_SYSTEM_MGMT); if ( use_ats(pdev, iommu, ivrs_dev) ) - dte->i = ats_enabled; + dte->i = true; spin_unlock_irqrestore(&iommu->lock, flags); @@ -257,7 +257,7 @@ static int __must_check amd_iommu_setup_ ACPI_IVHD_SYSTEM_MGMT)); if ( use_ats(pdev, iommu, ivrs_dev) ) - ASSERT(dte->i == ats_enabled); + ASSERT(dte->i); spin_unlock_irqrestore(&iommu->lock, flags); --- a/xen/drivers/passthrough/ats.c +++ b/xen/drivers/passthrough/ats.c @@ -18,8 +18,8 @@ #include #include "ats.h" -bool __read_mostly ats_enabled; -boolean_param("ats", ats_enabled); +int8_t __ro_after_init opt_ats = -1; +boolean_param("ats", opt_ats); int enable_ats_device(struct pci_dev *pdev, struct list_head *ats_list) { --- a/xen/drivers/passthrough/ats.h +++ b/xen/drivers/passthrough/ats.h @@ -22,7 +22,7 @@ #define ATS_QUEUE_DEPTH_MASK 0x1f #define ATS_ENABLE (1<<15) -extern bool ats_enabled; +extern int8_t opt_ats; int enable_ats_device(struct pci_dev *pdev, struct list_head *ats_list); void disable_ats_device(struct pci_dev *pdev); @@ -43,7 +43,7 @@ static inline int pci_ats_enabled(int se static inline int pci_ats_device(int seg, int bus, int devfn) { - if ( !ats_enabled ) + if ( !opt_ats ) return 0; return pci_find_ext_capability(PCI_SBDF(seg, bus, devfn), --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -1543,7 +1543,7 @@ int domain_context_mapping_one( } context_set_address_root(lctxt, root); - if ( ats_enabled && ecap_dev_iotlb(iommu->ecap) ) + if ( opt_ats > 0 && ecap_dev_iotlb(iommu->ecap) ) context_set_translation_type(lctxt, CONTEXT_TT_DEV_IOTLB); else context_set_translation_type(lctxt, CONTEXT_TT_MULTI_LEVEL); --- a/xen/drivers/passthrough/vtd/x86/ats.c +++ b/xen/drivers/passthrough/vtd/x86/ats.c @@ -46,7 +46,7 @@ int ats_device(const struct pci_dev *pde struct acpi_drhd_unit *ats_drhd; unsigned int pos, expfl = 0; - if ( !ats_enabled || !iommu_qinval ) + if ( opt_ats <= 0 || !iommu_qinval ) return 0; if ( !ecap_queued_inval(drhd->iommu->ecap) || From patchwork Thu Feb 15 10:16:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13557824 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D6C69C4829E for ; Thu, 15 Feb 2024 10:16:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681497.1060302 (Exim 4.92) (envelope-from ) id 1raYmt-0002Nm-Ko; Thu, 15 Feb 2024 10:16:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681497.1060302; Thu, 15 Feb 2024 10:16:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1raYmt-0002Nf-IF; Thu, 15 Feb 2024 10:16:15 +0000 Received: by outflank-mailman (input) for mailman id 681497; Thu, 15 Feb 2024 10:16:13 +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 1raYmr-0001ZT-CG for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 10:16:13 +0000 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [2a00:1450:4864:20::22a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3eb48278-cbeb-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 11:16:12 +0100 (CET) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2d0d95e8133so8328621fa.1 for ; Thu, 15 Feb 2024 02:16:12 -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 bs3-20020a056000070300b0033b45bdb2a1sm1361072wrb.4.2024.02.15.02.16.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Feb 2024 02:16:11 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3eb48278-cbeb-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707992172; x=1708596972; 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=pvYCja/S6ezysFDR56QyJhiQ4LakZ7EGAU+IRQcHkow=; b=E8F7ztVqfJzJ4XvJ5Ep2pMkHhXV/cb7Po+L6EML++7dr1c0HpG4Jqn+KkDnkQgtR6P 4aUMYMNfDBn0bgUq2TvpSp/s7vZf+CkOVccOuR4p4KV7cSrh2yH+CBQBmiRa6P273hPF Td7yflXf89uoGWsir1x4zEMQe7W5udHa9SpQn6Mw+lL31W/ptNzwZ/3rHqbzk/tdfXLy UDA3hm7BshaHpUZ6MOzua0NdpLAWmcHBUxVd9nxu6T7FsuEK1jJii01lEPGKwjSjT8p7 pyWc+FDR/c8C3jRKyXXT49YMSSt5uNQ5MywfsE6stm/OZpNDjL8m9Jf6u6JU8RuJmljY Pu2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707992172; x=1708596972; 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=pvYCja/S6ezysFDR56QyJhiQ4LakZ7EGAU+IRQcHkow=; b=Qrhfw8gk1TbGXJGEVVnYHX9fei6L7WS/2KmhPyDKa5rhAEVlpjNt9NbJ+B8IFlk+uc AJy9Rxaph6v56NLVYGg+t3p9uyDe7aLtU0ObSb2Dgh0CHXhTa9cFmsSVJg7IVUGFCdly y0kqATwHsx+8RgNioL1pW0dQ6D6VIGUsSIgNsbGUjTt+LkHGruXDu95Z6B1b8+DcQldi 2uEDCLBmeifGluEeLa10QLgmHqS+VavdlNa0KDAGNUedqEM1xCnK/wJwZY6ztRxZ4Py7 rYe12OdGCuFHp4sUER1SivF0z/DJITflIN7+KL91jK2UFfGW3poR3BB+hdt7zJKyZZ+5 M7+w== X-Gm-Message-State: AOJu0YyhunNqMy3wITLvUAMzumBu9SnK4WYXFeFFxLcm4oJfcrxVKx8y rfPqjlXsSw3xlSSf8h351P3sNDYvPGrapOjmtpGkSuVMl9TnuWY/jqX83SN2EGO4rZ5YHD7ZgHI = X-Google-Smtp-Source: AGHT+IHaNfJ1XoIWuOA4FB8Cfvo2/hwJaB1FIeDk2PiK1bwBIgOwZw0rqaqNJdskZ8Y97NbZ1KnyeA== X-Received: by 2002:a2e:a171:0:b0:2d0:a90b:e4e3 with SMTP id u17-20020a2ea171000000b002d0a90be4e3mr844303ljl.27.1707992172169; Thu, 15 Feb 2024 02:16:12 -0800 (PST) Message-ID: Date: Thu, 15 Feb 2024 11:16:11 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 06/12] 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: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/D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bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> When the flag is set, permit Dom0 to control the device (no worse than what we had before and in line with other "best effort" behavior we use when it comes to Dom0), but suppress passing through to DomU-s unless ATS can actually be enabled for such devices (and was explicitly enabled on the command line). Signed-off-by: Jan Beulich --- v2: Re-base over new earlier patches. --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -225,7 +225,11 @@ exceptions (watchdog NMIs and unexpected > Default: `false` Permits Xen to set up and use PCI Address Translation Services. This is a -performance optimisation for PCI Passthrough. +performance optimisation for PCI Passthrough. Note that firmware may indicate +that certain devices need to have ATS enabled for proper operation. For such +devices ATS will be enabled by default, unless the option is used in its +negative form. Such devices will still not be eligible for passing through to +guests, unless the option is used in its positive form. **WARNING: Xen cannot currently safely use ATS because of its synchronous wait loops for Queued Invalidation completions.** --- a/xen/drivers/passthrough/vtd/dmar.c +++ b/xen/drivers/passthrough/vtd/dmar.c @@ -253,6 +253,24 @@ struct acpi_atsr_unit *acpi_find_matched return all_ports; } +const struct acpi_satc_unit *acpi_find_matched_satc_unit( + const struct pci_dev *pdev) +{ + const struct acpi_satc_unit *satc; + + list_for_each_entry ( satc, &acpi_satc_units, list ) + { + if ( satc->segment != pdev->seg ) + continue; + + for ( unsigned int i = 0; i < satc->scope.devices_cnt; ++i ) + if ( satc->scope.devices[i] == pdev->sbdf.bdf ) + return satc; + } + + return NULL; +} + struct acpi_rhsa_unit *drhd_to_rhsa(const struct acpi_drhd_unit *drhd) { struct acpi_rhsa_unit *rhsa; --- a/xen/drivers/passthrough/vtd/dmar.h +++ b/xen/drivers/passthrough/vtd/dmar.h @@ -112,6 +112,8 @@ struct acpi_satc_unit { struct acpi_drhd_unit *acpi_find_matched_drhd_unit(const struct pci_dev *); struct acpi_atsr_unit *acpi_find_matched_atsr_unit(const struct pci_dev *); +const struct acpi_satc_unit *acpi_find_matched_satc_unit( + const struct pci_dev *pdev); #define DMAR_TYPE 1 #define RMRR_TYPE 2 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -2364,6 +2364,26 @@ static int cf_check intel_iommu_add_devi if ( ret ) dprintk(XENLOG_ERR VTDPREFIX, "%pd: context mapping failed\n", pdev->domain); + else if ( !pdev->broken ) + { + const struct acpi_drhd_unit *drhd = acpi_find_matched_drhd_unit(pdev); + const struct acpi_satc_unit *satc = acpi_find_matched_satc_unit(pdev); + + /* + * Prevent the device from getting assigned to an unprivileged domain + * when firmware indicates ATS is required, but ATS could not be enabled + * or was not explicitly enabled via command line option. + */ + if ( satc && satc->atc_required && + (!drhd || ats_device(pdev, drhd) <= 0 || + !pci_ats_enabled(pdev->seg, pdev->bus, pdev->devfn) || + opt_ats < 0) ) + { + printk(XENLOG_WARNING "ATS: %pp is not eligible for pass-through\n", + &pdev->sbdf); + pdev->broken = true; + } + } return ret; } @@ -2375,12 +2395,26 @@ static int cf_check intel_iommu_enable_d pci_vtd_quirk(pdev); - if ( ret <= 0 ) - return ret; + if ( ret <= 0 || + (ret = enable_ats_device(pdev, &drhd->iommu->ats_devices)) < 0 || + opt_ats < 0 ) + { + const struct acpi_satc_unit *satc = acpi_find_matched_satc_unit(pdev); + + /* + * Besides in error cases also prevent the device from getting assigned + * to an unprivileged domain when firmware indicates ATS is required, + * but ATS use was not explicitly enabled via command line option. + */ + if ( satc && satc->atc_required && !pdev->broken ) + { + printk(XENLOG_WARNING "ATS: %pp is not eligible for pass-through\n", + &pdev->sbdf); + pdev->broken = true; + } + } - ret = enable_ats_device(pdev, &drhd->iommu->ats_devices); - - return ret >= 0 ? 0 : ret; + return ret <= 0 ? ret : 0; } static int cf_check intel_iommu_remove_device(u8 devfn, struct pci_dev *pdev) --- a/xen/drivers/passthrough/vtd/x86/ats.c +++ b/xen/drivers/passthrough/vtd/x86/ats.c @@ -45,8 +45,9 @@ int ats_device(const struct pci_dev *pde { struct acpi_drhd_unit *ats_drhd; unsigned int pos, expfl = 0; + const struct acpi_satc_unit *satc; - if ( opt_ats <= 0 || !iommu_qinval ) + if ( !opt_ats || !iommu_qinval ) return 0; if ( !ecap_queued_inval(drhd->iommu->ecap) || @@ -61,6 +62,10 @@ int ats_device(const struct pci_dev *pde !acpi_find_matched_atsr_unit(pdev) ) return 0; + satc = acpi_find_matched_satc_unit(pdev); + if ( opt_ats < 0 && (!satc || !satc->atc_required) ) + return 0; + ats_drhd = find_ats_dev_drhd(drhd->iommu); pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS); From patchwork Thu Feb 15 10:16:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13557825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0A015C4829E for ; Thu, 15 Feb 2024 10:16:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681501.1060313 (Exim 4.92) (envelope-from ) id 1raYnE-0002sO-TQ; Thu, 15 Feb 2024 10:16:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681501.1060313; Thu, 15 Feb 2024 10:16:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1raYnE-0002sH-Qn; Thu, 15 Feb 2024 10:16:36 +0000 Received: by outflank-mailman (input) for mailman id 681501; Thu, 15 Feb 2024 10:16:36 +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 1raYnD-0001ZT-Rs for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 10:16:35 +0000 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [2a00:1450:4864:20::430]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4c127b56-cbeb-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 11:16:35 +0100 (CET) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-33b4e6972f6so277487f8f.2 for ; Thu, 15 Feb 2024 02:16:35 -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 bs3-20020a056000070300b0033b45bdb2a1sm1361072wrb.4.2024.02.15.02.16.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Feb 2024 02:16:34 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4c127b56-cbeb-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707992194; x=1708596994; 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=XNeK3bYqgsZfsvAYZefEQLICnz9K9i5e8fWmt9YKjrw=; b=FAAFF1AcP2IY3bkknHl7wbK8GpMFJf2q1TRCaw7K1nvQcsoqWESng/m023h/HW+uU2 dQ0B9JDHjNXoFVCS639eLWlj7v3w4sWTLTzyqLTbQlhHW7r/aUKP8x/uxFFcVMqvtkAL faCK0mdlou7aVzYxpGuPLLki3AzcWPLSIbK+JOuSIXaNNX7hdGBKuzaMmrB54kPC7lcQ HKGf14iar+ATuyfQJKdxlGlkqpE1XnchjvtjNA5XW8dRWna0D2Zb7E4UxCjSkfLyyDex 1ZtmsyRwEt9WvsvmMpdqzmRbWMScVEANTB3N2lIEOFW7j62UOHxgSllR43rey7VeYZ+I Mo3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707992194; x=1708596994; 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=XNeK3bYqgsZfsvAYZefEQLICnz9K9i5e8fWmt9YKjrw=; b=tK3WkF4J0zxfoAWVzOG/hpVt/eM51oHjtY2g4/SPxLqx74wcsFpgo631e0kxDiI9UX EfRF/JbXpIoVG/d18iYoWLuKRW2fIeMADCWRRLC9eNLdQJP9XH0y8mLHPBdIADcZr66H tQS7VgwwdLvpIetrBeJloFJwTH2bCFWPA5/Y6j91Uocnh5enbg4etBxddpWvHPIGaTET bS+3+RqRWMB29cozqN3jisgFI+ope9Fcdd1RxwEC/oei0wPprTOAh7dtwX5rh1BYEycJ rfsmukQ7gj1Y9QwWQ16DoTdeu2miK1/bxjJJAqBjNQ1OyvN5tnvKrqfZgi3RQUvj6xUZ XOFA== X-Gm-Message-State: AOJu0YzjP0SS6aNUWENzMoAP2YCiETQHMIT15kKwKTTQJ4DOL475wuk3 zE9mEVVl9Q1NvXLQlmMOMfM8FqyIgWQ6qh0LTOC+hGXEiTgzoe/9qR2D5CWRniK8HU2DuePBeT4 = X-Google-Smtp-Source: AGHT+IEBToj/5jt4OtESG6EbViirEv991GlvJtBi+TFX2uxp33Hn+F84evlIFXdE+Q/+B48v8GDU0A== X-Received: by 2002:a5d:6882:0:b0:33b:6d5e:7645 with SMTP id h2-20020a5d6882000000b0033b6d5e7645mr759086wru.38.1707992194487; Thu, 15 Feb 2024 02:16:34 -0800 (PST) Message-ID: Date: Thu, 15 Feb 2024 11:16:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 07/12] 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: <64b028be-2197-4951-ae5b-32f9eabfa84a@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: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> All callers only care about boolean outcome. For this there's no point in allocating a duplicate of the respective DRHD structure; a simple boolean suffices (which eventually may want 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. (While the corresponding hook can have the parameter dropped too then, leave this for a separate change, to limit scope here.) No functional effect intended. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné --- v2: Re-base over new earlier patches. --- a/xen/drivers/passthrough/vtd/extern.h +++ b/xen/drivers/passthrough/vtd/extern.h @@ -65,8 +65,6 @@ struct acpi_drhd_unit *ioapic_to_drhd(un struct acpi_drhd_unit *hpet_to_drhd(unsigned int hpet_id); struct acpi_rhsa_unit *drhd_to_rhsa(const struct acpi_drhd_unit *drhd); -struct acpi_drhd_unit *find_ats_dev_drhd(struct vtd_iommu *iommu); - int ats_device(const struct pci_dev *, const struct acpi_drhd_unit *); int dev_invalidate_iotlb(struct vtd_iommu *iommu, u16 did, --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -624,8 +624,7 @@ int cf_check vtd_flush_iotlb_reg( } static int __must_check iommu_flush_iotlb_global(struct vtd_iommu *iommu, - bool flush_non_present_entry, - bool flush_dev_iotlb) + bool flush_non_present_entry) { int status; @@ -633,7 +632,7 @@ static int __must_check iommu_flush_iotl vtd_ops_preamble_quirk(iommu); status = iommu->flush.iotlb(iommu, 0, 0, 0, DMA_TLB_GLOBAL_FLUSH, - flush_non_present_entry, flush_dev_iotlb); + flush_non_present_entry, iommu->flush_dev_iotlb); /* undo platform specific errata workarounds */ vtd_ops_postamble_quirk(iommu); @@ -642,8 +641,7 @@ static int __must_check iommu_flush_iotl } static int __must_check iommu_flush_iotlb_dsi(struct vtd_iommu *iommu, u16 did, - bool flush_non_present_entry, - bool flush_dev_iotlb) + bool flush_non_present_entry) { int status; @@ -651,7 +649,7 @@ static int __must_check iommu_flush_iotl vtd_ops_preamble_quirk(iommu); status = iommu->flush.iotlb(iommu, did, 0, 0, DMA_TLB_DSI_FLUSH, - flush_non_present_entry, flush_dev_iotlb); + flush_non_present_entry, iommu->flush_dev_iotlb); /* undo platform specific errata workarounds */ vtd_ops_postamble_quirk(iommu); @@ -661,26 +659,23 @@ static int __must_check iommu_flush_iotl static int __must_check iommu_flush_iotlb_psi(struct vtd_iommu *iommu, u16 did, u64 addr, unsigned int order, - bool flush_non_present_entry, - bool flush_dev_iotlb) + bool flush_non_present_entry) { int status; /* Fallback to domain selective flush if no PSI support */ if ( !cap_pgsel_inv(iommu->cap) ) - return iommu_flush_iotlb_dsi(iommu, did, flush_non_present_entry, - flush_dev_iotlb); + return iommu_flush_iotlb_dsi(iommu, did, flush_non_present_entry); /* Fallback to domain selective flush if size is too big */ if ( order > cap_max_amask_val(iommu->cap) ) - return iommu_flush_iotlb_dsi(iommu, did, flush_non_present_entry, - flush_dev_iotlb); + return iommu_flush_iotlb_dsi(iommu, did, flush_non_present_entry); /* apply platform specific errata workarounds */ vtd_ops_preamble_quirk(iommu); status = iommu->flush.iotlb(iommu, did, addr, order, DMA_TLB_PSI_FLUSH, - flush_non_present_entry, flush_dev_iotlb); + flush_non_present_entry, iommu->flush_dev_iotlb); /* undo platform specific errata workarounds */ vtd_ops_postamble_quirk(iommu); @@ -692,7 +687,6 @@ static int __must_check iommu_flush_all( { struct acpi_drhd_unit *drhd; struct vtd_iommu *iommu; - bool flush_dev_iotlb; int rc = 0; flush_local(FLUSH_CACHE); @@ -703,8 +697,7 @@ static int __must_check iommu_flush_all( iommu = drhd->iommu; context_rc = iommu_flush_context_global(iommu, 0); - flush_dev_iotlb = !!find_ats_dev_drhd(iommu); - iotlb_rc = iommu_flush_iotlb_global(iommu, 0, flush_dev_iotlb); + iotlb_rc = iommu_flush_iotlb_global(iommu, 0); /* * The current logic for returns: @@ -734,7 +727,6 @@ static int __must_check cf_check iommu_f struct domain_iommu *hd = dom_iommu(d); struct acpi_drhd_unit *drhd; struct vtd_iommu *iommu; - bool flush_dev_iotlb; int iommu_domid; int ret = 0; @@ -762,21 +754,18 @@ static int __must_check cf_check iommu_f if ( !test_bit(iommu->index, hd->arch.vtd.iommu_bitmap) ) continue; - flush_dev_iotlb = !!find_ats_dev_drhd(iommu); iommu_domid = get_iommu_did(d->domain_id, iommu, !d->is_dying); if ( iommu_domid == -1 ) continue; if ( !page_count || (page_count & (page_count - 1)) || dfn_eq(dfn, INVALID_DFN) || !IS_ALIGNED(dfn_x(dfn), page_count) ) - rc = iommu_flush_iotlb_dsi(iommu, iommu_domid, - 0, flush_dev_iotlb); + rc = iommu_flush_iotlb_dsi(iommu, iommu_domid, 0); else rc = iommu_flush_iotlb_psi(iommu, iommu_domid, dfn_to_daddr(dfn), get_order_from_pages(page_count), - !(flush_flags & IOMMU_FLUSHF_modified), - flush_dev_iotlb); + !(flush_flags & IOMMU_FLUSHF_modified)); if ( rc > 0 ) iommu_flush_write_buffer(iommu); @@ -1488,7 +1477,6 @@ int domain_context_mapping_one( uint16_t seg = iommu->drhd->segment, prev_did = 0; struct domain *prev_dom = NULL; int rc, ret; - bool flush_dev_iotlb; if ( QUARANTINE_SKIP(domain, pgd_maddr) ) return 0; @@ -1637,8 +1625,7 @@ int domain_context_mapping_one( rc = iommu_flush_context_device(iommu, prev_did, PCI_BDF(bus, devfn), DMA_CCMD_MASK_NOBIT, !prev_dom); - flush_dev_iotlb = !!find_ats_dev_drhd(iommu); - ret = iommu_flush_iotlb_dsi(iommu, prev_did, !prev_dom, flush_dev_iotlb); + ret = iommu_flush_iotlb_dsi(iommu, prev_did, !prev_dom); /* * The current logic for returns: @@ -1882,7 +1869,6 @@ int domain_context_unmap_one( struct context_entry *context, *context_entries; u64 maddr; int iommu_domid, rc, ret; - bool flush_dev_iotlb; ASSERT(pcidevs_locked()); spin_lock(&iommu->lock); @@ -1908,8 +1894,7 @@ int domain_context_unmap_one( PCI_BDF(bus, devfn), DMA_CCMD_MASK_NOBIT, 0); - flush_dev_iotlb = !!find_ats_dev_drhd(iommu); - ret = iommu_flush_iotlb_dsi(iommu, iommu_domid, 0, flush_dev_iotlb); + ret = iommu_flush_iotlb_dsi(iommu, iommu_domid, 0); /* * The current logic for returns: --- a/xen/drivers/passthrough/vtd/iommu.h +++ b/xen/drivers/passthrough/vtd/iommu.h @@ -484,6 +484,7 @@ struct vtd_iommu { spinlock_t register_lock; /* protect iommu register handling */ u64 root_maddr; /* root entry machine address */ nodeid_t node; + bool flush_dev_iotlb; struct msi_desc msi; struct acpi_drhd_unit *drhd; --- a/xen/drivers/passthrough/vtd/x86/ats.c +++ b/xen/drivers/passthrough/vtd/x86/ats.c @@ -28,22 +28,8 @@ #include "../extern.h" #include "../../ats.h" -static LIST_HEAD(ats_dev_drhd_units); - -struct acpi_drhd_unit *find_ats_dev_drhd(struct vtd_iommu *iommu) -{ - struct acpi_drhd_unit *drhd; - list_for_each_entry ( drhd, &ats_dev_drhd_units, list ) - { - if ( drhd->iommu == iommu ) - return drhd; - } - return NULL; -} - int ats_device(const struct pci_dev *pdev, const struct acpi_drhd_unit *drhd) { - struct acpi_drhd_unit *ats_drhd; unsigned int pos, expfl = 0; const struct acpi_satc_unit *satc; @@ -66,17 +52,10 @@ int ats_device(const struct pci_dev *pde if ( opt_ats < 0 && (!satc || !satc->atc_required) ) return 0; - ats_drhd = find_ats_dev_drhd(drhd->iommu); pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS); + if ( pos ) + drhd->iommu->flush_dev_iotlb = true; - if ( pos && (ats_drhd == NULL) ) - { - ats_drhd = xmalloc(struct acpi_drhd_unit); - if ( !ats_drhd ) - return -ENOMEM; - *ats_drhd = *drhd; - list_add_tail(&ats_drhd->list, &ats_dev_drhd_units); - } return pos; } From patchwork Thu Feb 15 10:17:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13557826 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1B892C4829E for ; Thu, 15 Feb 2024 10:17:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681508.1060323 (Exim 4.92) (envelope-from ) id 1raYoJ-0003UX-62; Thu, 15 Feb 2024 10:17:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681508.1060323; Thu, 15 Feb 2024 10:17:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1raYoJ-0003UQ-3E; Thu, 15 Feb 2024 10:17:43 +0000 Received: by outflank-mailman (input) for mailman id 681508; Thu, 15 Feb 2024 10:17:41 +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 1raYoH-0003UC-P1 for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 10:17:41 +0000 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [2a00:1450:4864:20::229]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 72f11edc-cbeb-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 11:17:40 +0100 (CET) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2d0f7585d89so7928721fa.3 for ; Thu, 15 Feb 2024 02:17:40 -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 bs3-20020a056000070300b0033b45bdb2a1sm1361072wrb.4.2024.02.15.02.17.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Feb 2024 02:17:39 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 72f11edc-cbeb-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707992260; x=1708597060; 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=S2x+PfdcoJsKEcm0haAnCx/jYnp6JxJ2K1CdYjIZgsY=; b=Dg+PeYY4g7ZFSrD2W2hUwW5aXV8YhLSoQlPeN8H6B9opyo1Cl3DtFKjDHpfU6Saxzd 8hkWxWcf7s1zyiep8ZHAj9wvy3ArN16M8xMtgQdISuvo51mImOncpNqx/QXP4UPRbfil YSRzOcbP04x36MXUgs5KQyq/gItiQr5LUNTaIri2TRMp3LSKxpsKSjBmR1sSnwvhheSR lap1LGUc9cguEJx+i+845aybJpsigz4+Yh5NFya0ie+i78mkUdEBqcZWHQLEYAUz16Rg bp8XXwmsUIYExaZXoSkoHYJ+X2wc45Su/SqfUyu7gw2Pl8FbS6otl03nb8eaEfK6My/B fijQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707992260; x=1708597060; 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=S2x+PfdcoJsKEcm0haAnCx/jYnp6JxJ2K1CdYjIZgsY=; b=d37m98UOpBrnHA19aTO/2DtI/54axGbNpAryAEvJ4gKz140A46gXDua709ioxlB8SJ FjXUdMeCbv10UfULxZ9zjGQ4YLTcYqaQEsov9WR5tq3JLvG+d6DU47d1uOEvCzN86Tt5 PUFE4s4wlJ87sNsFz4k6z2I4/hGuqSeIlgSyF7wj1OSBU1mfrKYFEYtYdTRiBvmP2faS Vtzglhpy0t4sio3rwyYkTiFVxCad0C/rsMB/AYUG2FgROJJYCxOf/bgxhpP5jytITkST xCIdTTNvjOWkHik4rbABBwMxPELfSaz4p3k0dj0MXWuGiEgZtOSN5jMQ2AnDHeV6PQwZ /3mg== X-Gm-Message-State: AOJu0YwapNt3GckduHgtvxViUTpU45ySNnXW3lJZ3w+bt80t8tE8BmLB wKJGMs0FtAqltrYuGH1ayZOYZMRKld18k3YjRIq+7bvptTWIV7hzrfhPjeSCB13T/YFEFFdeT/Q = X-Google-Smtp-Source: AGHT+IF2ihrYWltASVeLsOU7+3qM+8Hfay8U7bH1prne8Az8dp65xgQ56op0n2UWrhK6Bm6HsDI41w== X-Received: by 2002:a2e:9e10:0:b0:2d1:10cf:e887 with SMTP id e16-20020a2e9e10000000b002d110cfe887mr1135113ljk.29.1707992259760; Thu, 15 Feb 2024 02:17:39 -0800 (PST) Message-ID: <0a30cf57-93ca-4ae8-a125-48c155f1f5a5@suse.com> Date: Thu, 15 Feb 2024 11:17:38 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 08/12] 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: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZg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WDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> ..., thus allowing it to become static, and thus reducing scope overlap between it and pci_ats_device(). There's nothing x86-specific about this function anyway. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné --- a/xen/drivers/passthrough/vtd/extern.h +++ b/xen/drivers/passthrough/vtd/extern.h @@ -65,8 +65,6 @@ struct acpi_drhd_unit *ioapic_to_drhd(un struct acpi_drhd_unit *hpet_to_drhd(unsigned int hpet_id); struct acpi_rhsa_unit *drhd_to_rhsa(const struct acpi_drhd_unit *drhd); -int ats_device(const struct pci_dev *, const struct acpi_drhd_unit *); - int dev_invalidate_iotlb(struct vtd_iommu *iommu, u16 did, u64 addr, unsigned int size_order, u64 type); --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -1455,6 +1455,38 @@ static void __hwdom_init cf_check intel_ } } +static int ats_device(const struct pci_dev *pdev, + const struct acpi_drhd_unit *drhd) +{ + unsigned int pos, expfl = 0; + const struct acpi_satc_unit *satc; + + if ( !opt_ats || !iommu_qinval ) + return 0; + + if ( !ecap_queued_inval(drhd->iommu->ecap) || + !ecap_dev_iotlb(drhd->iommu->ecap) ) + return 0; + + pos = pci_find_cap_offset(pdev->sbdf, PCI_CAP_ID_EXP); + if ( pos ) + expfl = pci_conf_read16(pdev->sbdf, pos + PCI_EXP_FLAGS); + + if ( MASK_EXTR(expfl, PCI_EXP_FLAGS_TYPE) != PCI_EXP_TYPE_RC_END && + !acpi_find_matched_atsr_unit(pdev) ) + return 0; + + satc = acpi_find_matched_satc_unit(pdev); + if ( opt_ats < 0 && (!satc || !satc->atc_required) ) + return 0; + + pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS); + if ( pos ) + drhd->iommu->flush_dev_iotlb = true; + + return pos; +} + /* * This function returns * - a negative errno value upon error, --- a/xen/drivers/passthrough/vtd/x86/ats.c +++ b/xen/drivers/passthrough/vtd/x86/ats.c @@ -28,37 +28,6 @@ #include "../extern.h" #include "../../ats.h" -int ats_device(const struct pci_dev *pdev, const struct acpi_drhd_unit *drhd) -{ - unsigned int pos, expfl = 0; - const struct acpi_satc_unit *satc; - - if ( !opt_ats || !iommu_qinval ) - return 0; - - if ( !ecap_queued_inval(drhd->iommu->ecap) || - !ecap_dev_iotlb(drhd->iommu->ecap) ) - return 0; - - pos = pci_find_cap_offset(pdev->sbdf, PCI_CAP_ID_EXP); - if ( pos ) - expfl = pci_conf_read16(pdev->sbdf, pos + PCI_EXP_FLAGS); - - if ( MASK_EXTR(expfl, PCI_EXP_FLAGS_TYPE) != PCI_EXP_TYPE_RC_END && - !acpi_find_matched_atsr_unit(pdev) ) - return 0; - - satc = acpi_find_matched_satc_unit(pdev); - if ( opt_ats < 0 && (!satc || !satc->atc_required) ) - return 0; - - pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS); - if ( pos ) - drhd->iommu->flush_dev_iotlb = true; - - return pos; -} - static bool device_in_domain(const struct vtd_iommu *iommu, const struct pci_dev *pdev, uint16_t did) { From patchwork Thu Feb 15 10:18:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13557827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3343C48BEB for ; Thu, 15 Feb 2024 10:18:22 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681514.1060333 (Exim 4.92) (envelope-from ) id 1raYop-00044x-Hr; Thu, 15 Feb 2024 10:18:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681514.1060333; Thu, 15 Feb 2024 10:18:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1raYop-00044q-DT; Thu, 15 Feb 2024 10:18:15 +0000 Received: by outflank-mailman (input) for mailman id 681514; Thu, 15 Feb 2024 10:18:14 +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 1raYoo-00043N-E2 for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 10:18:14 +0000 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [2a00:1450:4864:20::335]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 869c8619-cbeb-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 11:18:13 +0100 (CET) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-41211acfcfcso4294975e9.1 for ; Thu, 15 Feb 2024 02:18: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 bs3-20020a056000070300b0033b45bdb2a1sm1361072wrb.4.2024.02.15.02.18.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Feb 2024 02:18:12 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 869c8619-cbeb-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707992293; x=1708597093; 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=HZHY6xKr+5lB7TS1xmNKRfrrhDk5jvTKT8Lq2YpKq9o=; b=UrRsqRjpmqJ24SYijvyf46Qbb3svUkWFF4Opwt6JZ4+1Lj6+t0wSKy1ENUUO9M6SG4 /QY2GTG97GbXlEUmhzyAHZe6g7lTGjnsuTDoYOvxmDPhMw9q2QmdtaIyNVP0wl2/uN5J J2b3HNt6/gAFbTBUwv6vJ1yNH7uGToqhmTQhozQIVytcZKKw4QjYuRPRKrjYttaiYkvC TsTm4zJHNh7mO9A/5r0Sk3y0+a/ZcRgeLCKe+yCURHnScxuMlQCSvwCUcd9nRbpj8xNF jWrH3Od1g2W8fMIlsxsGxJmLry/bOAJh52vgLLzRH1NUVYjwxZwrnHAunfdNZB6rekBR jszg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707992293; x=1708597093; 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=HZHY6xKr+5lB7TS1xmNKRfrrhDk5jvTKT8Lq2YpKq9o=; b=RRo97C1moMrKyf9/Xy1ks1ftUhS4kieUweW+5kSg1K3/G1kTJmyWzGFWA9Y43T8CdT zeVwkiP4Uvy5ublexZIsBLD95Zcx06JZmHYNTCgTmzTOyoMDEXxUjJIq6g5rDgY/Jxue DNQLUEMgykY3+rozwqxS7KbZcgJwjtPjnLMWl2UJkesPYFT6e3WbLVOOtOQ0C2TC195n L/ZW4N6L7suW/TeH8K+6k2nUbVzdeDlnQNwve+o3XBK2owe6UIv/tHR9cTMUAGU3j6NO EhzA19LXHZWc9wuGoAqYL3svRR5fkmpMXrZNN2Fuu1XVFY9azr/qGMu/fmZLDiJqfSq/ wOvQ== X-Gm-Message-State: AOJu0YwvmeMLMJvKxCzaOzntnUF/oOKeLuB68qU3+blxBeOCi6SRHlh3 wdJGEqBeYxBi8dJriHCQYWEXpOJISCxptWsvA2/o8Uy5RWlLvRRA1pjxb19iOe2gW9hufNAm2U8 = X-Google-Smtp-Source: AGHT+IHu/29TZZKNZ6L7qX+8fg//66hhzuIgaQn81jdnlckinsaiscRFqx1rMrhGjUnySpqPZTP6kw== X-Received: by 2002:a05:600c:35d2:b0:410:8ab6:8c72 with SMTP id r18-20020a05600c35d200b004108ab68c72mr934767wmq.31.1707992292681; Thu, 15 Feb 2024 02:18:12 -0800 (PST) Message-ID: <0af1d658-c43b-46f9-b290-22447ebfd0be@suse.com> Date: Thu, 15 Feb 2024 11:18:11 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 09/12] 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: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5Cl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AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> ..., thus allowing it and qinval_device_iotlb_sync() to become static. There's nothing x86-specific about the function anyway. While moving, adjust types to better match ./CODING_STYLE (albeit use of fixed-width types for parameters is retained to limit the effective change). Append a UL to a constant while moving, to please Misra. Also insert blank lines in the switch(), between non-fall-through case blocks. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné --- v2: Cosmetics. --- a/xen/drivers/passthrough/vtd/extern.h +++ b/xen/drivers/passthrough/vtd/extern.h @@ -65,13 +65,6 @@ struct acpi_drhd_unit *ioapic_to_drhd(un struct acpi_drhd_unit *hpet_to_drhd(unsigned int hpet_id); struct acpi_rhsa_unit *drhd_to_rhsa(const struct acpi_drhd_unit *drhd); -int dev_invalidate_iotlb(struct vtd_iommu *iommu, u16 did, - u64 addr, unsigned int size_order, u64 type); - -int __must_check qinval_device_iotlb_sync(struct vtd_iommu *iommu, - struct pci_dev *pdev, - u16 did, u16 size, u64 addr); - uint64_t alloc_pgtable_maddr(unsigned long npages, nodeid_t node); void free_pgtable_maddr(u64 maddr); void *map_vtd_domain_page(u64 maddr); --- a/xen/drivers/passthrough/vtd/qinval.c +++ b/xen/drivers/passthrough/vtd/qinval.c @@ -251,8 +251,9 @@ static int __must_check dev_invalidate_s return rc; } -int qinval_device_iotlb_sync(struct vtd_iommu *iommu, struct pci_dev *pdev, - u16 did, u16 size, u64 addr) +static int qinval_device_iotlb_sync(struct vtd_iommu *iommu, + struct pci_dev *pdev, uint16_t did, + uint16_t size, paddr_t addr) { unsigned long flags; unsigned int index; @@ -282,6 +283,103 @@ int qinval_device_iotlb_sync(struct vtd_ return dev_invalidate_sync(iommu, pdev, did); } +static bool device_in_domain(const struct vtd_iommu *iommu, + const struct pci_dev *pdev, uint16_t did) +{ + struct root_entry *root_entry; + struct context_entry *ctxt_entry = NULL; + unsigned int tt; + bool found = false; + + if ( unlikely(!iommu->root_maddr) ) + { + ASSERT_UNREACHABLE(); + return false; + } + + root_entry = map_vtd_domain_page(iommu->root_maddr); + if ( !root_present(root_entry[pdev->bus]) ) + goto out; + + ctxt_entry = map_vtd_domain_page(root_entry[pdev->bus].val); + if ( context_domain_id(ctxt_entry[pdev->devfn]) != did ) + goto out; + + tt = context_translation_type(ctxt_entry[pdev->devfn]); + if ( tt != CONTEXT_TT_DEV_IOTLB ) + goto out; + + found = true; + out: + if ( root_entry ) + unmap_vtd_domain_page(root_entry); + + if ( ctxt_entry ) + unmap_vtd_domain_page(ctxt_entry); + + return found; +} + +static int dev_invalidate_iotlb(struct vtd_iommu *iommu, uint16_t did, + paddr_t addr, unsigned int size_order, + uint64_t type) +{ + struct pci_dev *pdev, *temp; + int ret = 0; + + if ( !ecap_dev_iotlb(iommu->ecap) ) + return ret; + + list_for_each_entry_safe ( pdev, temp, &iommu->ats_devices, ats.list ) + { + bool sbit; + int rc = 0; + + switch ( type ) + { + case DMA_TLB_DSI_FLUSH: + if ( !device_in_domain(iommu, pdev, did) ) + break; + /* fall through if DSI condition met */ + case DMA_TLB_GLOBAL_FLUSH: + /* invalidate all translations: sbit=1,bit_63=0,bit[62:12]=1 */ + sbit = 1; + addr = (~0UL << PAGE_SHIFT_4K) & 0x7FFFFFFFFFFFFFFFUL; + rc = qinval_device_iotlb_sync(iommu, pdev, did, sbit, addr); + break; + + case DMA_TLB_PSI_FLUSH: + if ( !device_in_domain(iommu, pdev, did) ) + break; + + /* if size <= 4K, set sbit = 0, else set sbit = 1 */ + sbit = size_order ? 1 : 0; + + /* clear lower bits */ + addr &= ~0UL << PAGE_SHIFT_4K; + + /* if sbit == 1, zero out size_order bit and set lower bits to 1 */ + if ( sbit ) + { + addr &= ~((u64)PAGE_SIZE_4K << (size_order - 1)); + addr |= (((u64)1 << (size_order - 1)) - 1) << PAGE_SHIFT_4K; + } + + rc = qinval_device_iotlb_sync(iommu, pdev, did, sbit, addr); + break; + + default: + dprintk(XENLOG_WARNING VTDPREFIX, "invalid vt-d flush type\n"); + return -EOPNOTSUPP; + } + + if ( !ret ) + ret = rc; + } + + return ret; +} + static int __must_check queue_invalidate_iec_sync(struct vtd_iommu *iommu, u8 granu, u8 im, u16 iidx) { --- a/xen/drivers/passthrough/vtd/x86/Makefile +++ b/xen/drivers/passthrough/vtd/x86/Makefile @@ -1,2 +1 @@ -obj-y += ats.o obj-y += vtd.o --- a/xen/drivers/passthrough/vtd/x86/ats.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2006, Intel Corporation. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; If not, see . - * - * Author: Allen Kay - */ - -#include -#include -#include -#include -#include -#include -#include "../iommu.h" -#include "../dmar.h" -#include "../vtd.h" -#include "../extern.h" -#include "../../ats.h" - -static bool device_in_domain(const struct vtd_iommu *iommu, - const struct pci_dev *pdev, uint16_t did) -{ - struct root_entry *root_entry; - struct context_entry *ctxt_entry = NULL; - unsigned int tt; - bool found = false; - - if ( unlikely(!iommu->root_maddr) ) - { - ASSERT_UNREACHABLE(); - return false; - } - - root_entry = map_vtd_domain_page(iommu->root_maddr); - if ( !root_present(root_entry[pdev->bus]) ) - goto out; - - ctxt_entry = map_vtd_domain_page(root_entry[pdev->bus].val); - if ( context_domain_id(ctxt_entry[pdev->devfn]) != did ) - goto out; - - tt = context_translation_type(ctxt_entry[pdev->devfn]); - if ( tt != CONTEXT_TT_DEV_IOTLB ) - goto out; - - found = true; -out: - if ( root_entry ) - unmap_vtd_domain_page(root_entry); - - if ( ctxt_entry ) - unmap_vtd_domain_page(ctxt_entry); - - return found; -} - -int dev_invalidate_iotlb(struct vtd_iommu *iommu, u16 did, - u64 addr, unsigned int size_order, u64 type) -{ - struct pci_dev *pdev, *temp; - int ret = 0; - - if ( !ecap_dev_iotlb(iommu->ecap) ) - return ret; - - list_for_each_entry_safe( pdev, temp, &iommu->ats_devices, ats.list ) - { - bool sbit; - int rc = 0; - - switch ( type ) - { - case DMA_TLB_DSI_FLUSH: - if ( !device_in_domain(iommu, pdev, did) ) - break; - /* fall through if DSI condition met */ - case DMA_TLB_GLOBAL_FLUSH: - /* invalidate all translations: sbit=1,bit_63=0,bit[62:12]=1 */ - sbit = 1; - addr = (~0UL << PAGE_SHIFT_4K) & 0x7FFFFFFFFFFFFFFF; - rc = qinval_device_iotlb_sync(iommu, pdev, did, sbit, addr); - break; - case DMA_TLB_PSI_FLUSH: - if ( !device_in_domain(iommu, pdev, did) ) - break; - - /* if size <= 4K, set sbit = 0, else set sbit = 1 */ - sbit = size_order ? 1 : 0; - - /* clear lower bits */ - addr &= ~0UL << PAGE_SHIFT_4K; - - /* if sbit == 1, zero out size_order bit and set lower bits to 1 */ - if ( sbit ) - { - addr &= ~((u64)PAGE_SIZE_4K << (size_order - 1)); - addr |= (((u64)1 << (size_order - 1)) - 1) << PAGE_SHIFT_4K; - } - - rc = qinval_device_iotlb_sync(iommu, pdev, did, sbit, addr); - break; - default: - dprintk(XENLOG_WARNING VTDPREFIX, "invalid vt-d flush type\n"); - return -EOPNOTSUPP; - } - - if ( !ret ) - ret = rc; - } - - return ret; -} From patchwork Thu Feb 15 10:18:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13557828 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D277DC4829E for ; Thu, 15 Feb 2024 10:18:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681518.1060342 (Exim 4.92) (envelope-from ) id 1raYpB-0004ax-NT; Thu, 15 Feb 2024 10:18:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681518.1060342; Thu, 15 Feb 2024 10:18:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1raYpB-0004aq-Ks; Thu, 15 Feb 2024 10:18:37 +0000 Received: by outflank-mailman (input) for mailman id 681518; Thu, 15 Feb 2024 10:18:36 +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 1raYpA-0003nv-4z for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 10:18:36 +0000 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [2a00:1450:4864:20::32f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9333dd1a-cbeb-11ee-98f5-efadbce2ee36; Thu, 15 Feb 2024 11:18:34 +0100 (CET) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4121b1aad00so2221515e9.1 for ; Thu, 15 Feb 2024 02:18:34 -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 bs3-20020a056000070300b0033b45bdb2a1sm1361072wrb.4.2024.02.15.02.18.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Feb 2024 02:18:33 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9333dd1a-cbeb-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707992314; x=1708597114; 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=lLmg0pi++GhJOs1eVe+G5sBQYtePLzeMwHyGVwgdUjw=; b=ZiLqlKtiGeUelRY/XUEBDvqooZJV6xXkOPpklK6R+KtUO3PnhqzDxBOQGNdRykytRZ aAY/nqKgZV+qjngS14xYePUeDLGJFaQGm7NxesniwOqJ61Zc63HVECJQgSAcLajeXjph Iy4XzhwbAA2AOQX0XE+iBp+x6Bf/eMmUsVdiFPiTIBYxxnhQ5qpUtTesjVE5WxPe4lRe 2gCMqXN7U02hvL6JxQevA3fiohY5EelVK29pGNpPqZCqWCLz0bwqlj3SMRACqYtGvOqV wV5/IttYZ0RY0ejbUHnodIx0bsf2rDXnqowOke5ni2k0s0iLxmpHMteKzZ/nQmJIuSXo 5ekQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707992314; x=1708597114; 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=lLmg0pi++GhJOs1eVe+G5sBQYtePLzeMwHyGVwgdUjw=; b=gdbOziBznxE2lZhiftc4i4piCBvkhbhijfiPmKLIupnM8X13PxXjWM57Sc2tSFJOmU ijqEJzZ5GfN6eD99ne7XNrl5oPHtMA5fbDWFVjpH0HReJvvbHCdyo2XUCwvq/DHLm1wY nly7di4gcQHI0YCn8VPySz1cGSrz7PiPsvtkTdRAADr8yZD2qCOk9x73pIHaAvPDW2bC tqGLRBdD0gNi2S881/DM3s7tflQV90B3R6UdLUMvYUNjZU2FTzJXIa8W4DWcskwXr6l+ SZ5CysQ0Ukm0QE2pYE6VlmZlUuavuKwpLubtGl3aPip1eLETbqKveMruTdxp2ZMY/aUh QTOQ== X-Gm-Message-State: AOJu0YxtpAmDiDJMw6L4Yhv2R3+oO+DbWcwYLQgRXj9ehfyze/LK8KC0 jUy2a+GU7afoUZuyPZ6Rkj2fq5ZECQWqsXa5udhwn+Yui4aFdJpf2HL8Es674bT2i79pT4vuuao = X-Google-Smtp-Source: AGHT+IE2IMDkOamlYVi9ilGu+LX74qvQUe0kA2NJiX3civPx6gq8DwGohV9AMUXH4tiR9vyAQr20cQ== X-Received: by 2002:a5d:51ce:0:b0:33c:eb37:470e with SMTP id n14-20020a5d51ce000000b0033ceb37470emr985627wrv.44.1707992313772; Thu, 15 Feb 2024 02:18:33 -0800 (PST) Message-ID: <67bfa370-f4be-4f93-aa63-cbca7636a49c@suse.com> Date: Thu, 15 Feb 2024 11:18:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 10/12] 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: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9I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RCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> ..., thus allowing them to become static. There's nothing x86-specific about these functions anyway. Since only the "iommu_inclusive_mapping" parameter declaration would be left in the file, move that as well. There's nothing VT-d specific about it (anymore?): "dom0-iommu=map-inclusive" is similarly generic, and documentation also doesn't say anything. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné --- v2: doc adjustment. --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -1633,7 +1633,7 @@ Specify the timeout of the device IOTLB By default, the timeout is 1000 ms. When you see error 'Queue invalidate wait descriptor timed out', try increasing this value. -### iommu_inclusive_mapping +### iommu_inclusive_mapping (x86) > `= ` **WARNING: This command line option is deprecated, and superseded by --- a/xen/drivers/passthrough/vtd/Makefile +++ b/xen/drivers/passthrough/vtd/Makefile @@ -1,5 +1,3 @@ -obj-$(CONFIG_X86) += x86/ - obj-y += iommu.o obj-y += dmar.o obj-y += utils.o --- a/xen/drivers/passthrough/vtd/extern.h +++ b/xen/drivers/passthrough/vtd/extern.h @@ -21,6 +21,7 @@ #define _VTD_EXTERN_H_ #include "dmar.h" +#include #include #define VTDPREFIX "[VT-D]" @@ -67,8 +68,6 @@ struct acpi_rhsa_unit *drhd_to_rhsa(cons uint64_t alloc_pgtable_maddr(unsigned long npages, nodeid_t node); void free_pgtable_maddr(u64 maddr); -void *map_vtd_domain_page(u64 maddr); -void unmap_vtd_domain_page(const void *va); int domain_context_mapping_one(struct domain *domain, struct vtd_iommu *iommu, uint8_t bus, uint8_t devfn, const struct pci_dev *pdev, domid_t domid, @@ -78,6 +77,16 @@ int domain_context_unmap_one(struct doma int cf_check intel_iommu_get_reserved_device_memory( iommu_grdm_t *func, void *ctxt); +static inline void *map_vtd_domain_page(paddr_t maddr) +{ + return map_domain_page(_mfn(paddr_to_pfn(maddr))); +} + +static inline void unmap_vtd_domain_page(const void *va) +{ + unmap_domain_page(va); +} + unsigned int cf_check io_apic_read_remap_rte( unsigned int apic, unsigned int reg); void cf_check io_apic_write_remap_rte( --- a/xen/drivers/passthrough/vtd/x86/Makefile +++ /dev/null @@ -1 +0,0 @@ -obj-y += vtd.o --- a/xen/drivers/passthrough/vtd/x86/vtd.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2008, Intel Corporation. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; If not, see . - * - * Copyright (C) Allen Kay - * Copyright (C) Weidong Han - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../iommu.h" -#include "../dmar.h" -#include "../vtd.h" -#include "../extern.h" - -/* - * iommu_inclusive_mapping: when set, all memory below 4GB is included in dom0 - * 1:1 iommu mappings except xen and unusable regions. - */ -boolean_param("iommu_inclusive_mapping", iommu_hwdom_inclusive); - -void *map_vtd_domain_page(u64 maddr) -{ - return map_domain_page(_mfn(paddr_to_pfn(maddr))); -} - -void unmap_vtd_domain_page(const void *va) -{ - unmap_domain_page(va); -} --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -36,6 +37,12 @@ bool __initdata iommu_superpages = true; enum iommu_intremap __read_mostly iommu_intremap = iommu_intremap_full; +/* + * iommu_inclusive_mapping: When set, all memory below 4GB is included in dom0 + * 1:1 iommu mappings except xen and unusable regions. + */ +boolean_param("iommu_inclusive_mapping", iommu_hwdom_inclusive); + #ifdef CONFIG_PV /* Possible unfiltered LAPIC/MSI messages from untrusted sources? */ bool __read_mostly untrusted_msi; From patchwork Thu Feb 15 10:18:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13557829 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3C887C4829E for ; Thu, 15 Feb 2024 10:19:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681521.1060353 (Exim 4.92) (envelope-from ) id 1raYpU-00053X-Vt; Thu, 15 Feb 2024 10:18:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681521.1060353; Thu, 15 Feb 2024 10:18:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1raYpU-00053L-Ss; Thu, 15 Feb 2024 10:18:56 +0000 Received: by outflank-mailman (input) for mailman id 681521; Thu, 15 Feb 2024 10:18:55 +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 1raYpT-0003nv-A1 for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 10:18:55 +0000 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [2a00:1450:4864:20::334]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9e90d39c-cbeb-11ee-98f5-efadbce2ee36; Thu, 15 Feb 2024 11:18:53 +0100 (CET) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40fd72f7125so5788495e9.1 for ; Thu, 15 Feb 2024 02:18:53 -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 bs3-20020a056000070300b0033b45bdb2a1sm1361072wrb.4.2024.02.15.02.18.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Feb 2024 02:18:52 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9e90d39c-cbeb-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707992333; x=1708597133; 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=9Q/98Bd60cvr5LoSwMJPfl73bySzka3cm2CynrCQTbw=; b=OBZAwYdd0Ifor+dYnfJXkpiymKgVy7HAny6JjBEg8G6ehLRaj2Llv5D420fvzrdmDo xMwcjn5zs3OcrOtTI9qS8jcUsOQvf/fBC3Gc4mxlpD76zk06AYYHCHHrchvbUsnGXrLM U8eGUEn0fDpvUl0PXB70eOoy2DI7nwDg8IriT6/ktpkKh9bYmmIQk879uWFsGi9sQ5uG AYuDFmIE4htCpRz+ZLvIZjBPQEZieOb27cRLT7mzbo1S6wio4OYj4rKdkImgkIfjyrF1 YMMVVbB9y50tTCXkFtdnxjAEMfvIX6o3GpF40xaWz6uGWyI5PQB5iBLvmxkCn8OZ+ZDB DgdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707992333; x=1708597133; 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=9Q/98Bd60cvr5LoSwMJPfl73bySzka3cm2CynrCQTbw=; b=nXMCHCgwQhiPDnmOW31QKj26XtbnHKu1KUeIgawr3o39HDK305YGtAQcRgPcXxBpuy 1wWfRwfwdIikPwC8HdrQ8auAHXx4SPHBPzrt7sjCydhDp++4KbspiCRE7XU2ZKgLnW19 Z5GzuNamlpvc59qnhLDCCHmXLom3ccQoZdvVUzlI7a873pXcTIlpeTv6bF6CZKiEDp0p MFbBATAOtieuFoOxMETyIdQSR24WSNBp/buTS9N0/QN5eyR29IPfDbPd8b/f83989vMC d0z0NWALjoOHxI6PQWU/liQ9sFkNAOLfIe5H9rETZMl3KGvktZo/DglhOXpXb5Wky7mR f/ew== X-Gm-Message-State: AOJu0Ywp/PGOAg3josftSm+LoCffIb1f37hVsDjAPHejKpKLD6uf1+0G S7zG5vbsao9VtqYXWRVaqxA7CazJmK3HM5gCTxwjpp+fldDoupmVatttWnXdAO7tgt4P/4tDsXo = X-Google-Smtp-Source: AGHT+IETeTFl4XumyccwXgmsgDQE0YKt+uSSmDRwDjhG+soVHGC3zw23pHuAHdnqMQ5jXb+tByKWvg== X-Received: by 2002:adf:f682:0:b0:33d:fb3:9021 with SMTP id v2-20020adff682000000b0033d0fb39021mr290463wrp.54.1707992332965; Thu, 15 Feb 2024 02:18:52 -0800 (PST) Message-ID: Date: Thu, 15 Feb 2024 11:18:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 11/12] VT-d: drop flush_dev_iotlb parameter from IOTLB flush hook 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: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJk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/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> All call sites pass it using the flag from the IOMMU which they also pass. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné --- v2: New. --- a/xen/drivers/passthrough/vtd/extern.h +++ b/xen/drivers/passthrough/vtd/extern.h @@ -57,8 +57,7 @@ int __must_check cf_check vtd_flush_cont uint8_t function_mask, uint64_t type, bool flush_non_present_entry); int __must_check cf_check vtd_flush_iotlb_reg( struct vtd_iommu *iommu, uint16_t did, uint64_t addr, - unsigned int size_order, uint64_t type, bool flush_non_present_entry, - bool flush_dev_iotlb); + unsigned int size_order, uint64_t type, bool flush_non_present_entry); struct vtd_iommu *ioapic_to_iommu(unsigned int apic_id); struct vtd_iommu *hpet_to_iommu(unsigned int hpet_id); --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -566,8 +566,7 @@ static int __must_check iommu_flush_cont /* return value determine if we need a write buffer flush */ int cf_check vtd_flush_iotlb_reg( struct vtd_iommu *iommu, uint16_t did, uint64_t addr, - unsigned int size_order, uint64_t type, bool flush_non_present_entry, - bool flush_dev_iotlb) + unsigned int size_order, uint64_t type, bool flush_non_present_entry) { int tlb_offset = ecap_iotlb_offset(iommu->ecap); uint64_t val = type | DMA_TLB_IVT; @@ -632,7 +631,7 @@ static int __must_check iommu_flush_iotl vtd_ops_preamble_quirk(iommu); status = iommu->flush.iotlb(iommu, 0, 0, 0, DMA_TLB_GLOBAL_FLUSH, - flush_non_present_entry, iommu->flush_dev_iotlb); + flush_non_present_entry); /* undo platform specific errata workarounds */ vtd_ops_postamble_quirk(iommu); @@ -649,7 +648,7 @@ static int __must_check iommu_flush_iotl vtd_ops_preamble_quirk(iommu); status = iommu->flush.iotlb(iommu, did, 0, 0, DMA_TLB_DSI_FLUSH, - flush_non_present_entry, iommu->flush_dev_iotlb); + flush_non_present_entry); /* undo platform specific errata workarounds */ vtd_ops_postamble_quirk(iommu); @@ -675,7 +674,7 @@ static int __must_check iommu_flush_iotl vtd_ops_preamble_quirk(iommu); status = iommu->flush.iotlb(iommu, did, addr, order, DMA_TLB_PSI_FLUSH, - flush_non_present_entry, iommu->flush_dev_iotlb); + flush_non_present_entry); /* undo platform specific errata workarounds */ vtd_ops_postamble_quirk(iommu); --- a/xen/drivers/passthrough/vtd/iommu.h +++ b/xen/drivers/passthrough/vtd/iommu.h @@ -502,8 +502,7 @@ struct vtd_iommu { bool non_present_entry_flush); int __must_check (*iotlb)(struct vtd_iommu *iommu, u16 did, u64 addr, unsigned int size_order, u64 type, - bool flush_non_present_entry, - bool flush_dev_iotlb); + bool flush_non_present_entry); } flush; struct list_head ats_devices; --- a/xen/drivers/passthrough/vtd/qinval.c +++ b/xen/drivers/passthrough/vtd/qinval.c @@ -452,7 +452,7 @@ static int __must_check cf_check flush_c static int __must_check cf_check flush_iotlb_qi( struct vtd_iommu *iommu, u16 did, u64 addr, unsigned int size_order, - u64 type, bool flush_non_present_entry, bool flush_dev_iotlb) + u64 type, bool flush_non_present_entry) { u8 dr = 0, dw = 0; int ret = 0, rc; @@ -478,7 +478,7 @@ static int __must_check cf_check flush_i if ( !ret ) ret = rc; - if ( flush_dev_iotlb ) + if ( iommu->flush_dev_iotlb ) { rc = dev_invalidate_iotlb(iommu, did, addr, size_order, type); if ( !ret ) @@ -573,8 +573,7 @@ static int cf_check vtd_flush_context_no static int cf_check vtd_flush_iotlb_noop( struct vtd_iommu *iommu, uint16_t did, uint64_t addr, - unsigned int size_order, uint64_t type, bool flush_non_present_entry, - bool flush_dev_iotlb) + unsigned int size_order, uint64_t type, bool flush_non_present_entry) { WARN(); return -EIO; From patchwork Thu Feb 15 10:19:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13557830 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9CEE7C4829E for ; Thu, 15 Feb 2024 10:19:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681532.1060363 (Exim 4.92) (envelope-from ) id 1raYqM-00062z-BH; Thu, 15 Feb 2024 10:19:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681532.1060363; Thu, 15 Feb 2024 10:19:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1raYqM-00062s-8i; Thu, 15 Feb 2024 10:19:50 +0000 Received: by outflank-mailman (input) for mailman id 681532; Thu, 15 Feb 2024 10:19:49 +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 1raYqL-00062N-DJ for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 10:19:49 +0000 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [2a00:1450:4864:20::429]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id becc0f8a-cbeb-11ee-98f5-efadbce2ee36; Thu, 15 Feb 2024 11:19:47 +0100 (CET) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-33d10936af1so63996f8f.1 for ; Thu, 15 Feb 2024 02:19:47 -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 bs3-20020a056000070300b0033b45bdb2a1sm1361072wrb.4.2024.02.15.02.19.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Feb 2024 02:19:46 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: becc0f8a-cbeb-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707992387; x=1708597187; 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=n1vU3iIA9oaJ5u3mwUz26PW+j70BjJveVatCei2osX4=; b=A7AkwQ4YMd9dftW5esA3vyDOBmmJNEgTY2RgxZs5rdusj6OxC5sZZxqMBu/1T6RCkQ DOQOnlj9TELtJGKRIZl6uu17GNCZ3KVhmYQ5AmvA6TStwwhhVhK82WjHk/QvRb6VXh9m XqJKV/WzL3JwXvyMQflF+fvMW7Ak68V4e2QBLGq//xlA0Xr6nxxxgUe20Z4GY+rYT8FZ IBMWd7iG8vw+YzEXndb357jaBt9PkIxjGz2e7UG5zcOo3xzi6/Te8rU3gT+PnxkTqzt4 yGPybe31O+456ngkHhXaSXRQdNT2I9ikeFli8BvwhJlYzRw2t7w9ben9ApIX+z20l/Wn d4Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707992387; x=1708597187; 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=n1vU3iIA9oaJ5u3mwUz26PW+j70BjJveVatCei2osX4=; b=XD7fxLOft60MqoC9ZwYhspOrqBI2n7QYZC82DE4TnxQsqkfhy8w4AwNwvHqVRBDpqp SAaHeUY1pDZT/a+BC19+Pm7RfAbZkgFQja+pBt7KnCxGujiCkaEIUxlJT56b/BW1AxcR +fEhYWMeip+fxuHB9ksJBiWWY1ghuWcmutKvcHHzuRE3mPos5fhWReFmINfCKvRGGlFM WXpSEPOr9oNMGMcEw7PJhdQpfWpXf5gpGQ8LF9p91D8ng7btm+TCVZp0ZMv5C7IAiYZY nLr0GRUf9Qiq1VnlHg6Oh85mn2zjzT08kbxZNJ0h06SZHbC4HnXdrJc8FtQKQ7E+q7mN HJ9Q== X-Gm-Message-State: AOJu0YwlIlh2ky1u/9A4gNcQRJiAtCbD03eiBy2lJ+rYRc3oCNTG9sms HiEORAsAfpODYuS+zEk9Fp/5J5aory7beKlJnm2fV7rDpjxUX+LLiKBgnLqdBn17QAcm/zmFV4E = X-Google-Smtp-Source: AGHT+IGIfIj8HOKsHO7ITuiOtJqVOoRtnWdu7rLwJYHY0y3h/emNo2LUPfyhohPAdb/ytCC6Nmdofg== X-Received: by 2002:a5d:644b:0:b0:33b:68c0:8e2f with SMTP id d11-20020a5d644b000000b0033b68c08e2fmr1001767wrw.46.1707992386941; Thu, 15 Feb 2024 02:19:46 -0800 (PST) Message-ID: Date: Thu, 15 Feb 2024 11:19:46 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 12/12] PCI/ATS: tidy {en,dis}able_ats_device() a little 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: <64b028be-2197-4951-ae5b-32f9eabfa84a@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: <64b028be-2197-4951-ae5b-32f9eabfa84a@suse.com> Use appropriate types for the control register value as well as the capability position. Constify a pointer. Use "else" in favor of encoding the opposite condition of the earlier if(). Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné --- v2: New. --- a/xen/drivers/passthrough/ats.c +++ b/xen/drivers/passthrough/ats.c @@ -23,10 +23,9 @@ boolean_param("ats", opt_ats); int enable_ats_device(struct pci_dev *pdev, struct list_head *ats_list) { - u32 value; - int pos; + uint16_t value; + unsigned int pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS); - pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS); BUG_ON(!pos); if ( iommu_verbose ) @@ -35,7 +34,7 @@ int enable_ats_device(struct pci_dev *pd value = pci_conf_read16(pdev->sbdf, pos + ATS_REG_CTL); if ( value & ATS_ENABLE ) { - struct pci_dev *other; + const struct pci_dev *other; list_for_each_entry ( other, ats_list, ats.list ) if ( other == pdev ) @@ -44,8 +43,7 @@ int enable_ats_device(struct pci_dev *pd break; } } - - if ( !(value & ATS_ENABLE) ) + else { value |= ATS_ENABLE; pci_conf_write16(pdev->sbdf, pos + ATS_REG_CTL, value); @@ -69,7 +67,7 @@ int enable_ats_device(struct pci_dev *pd void disable_ats_device(struct pci_dev *pdev) { - u32 value; + uint16_t value; BUG_ON(!pdev->ats.cap_pos);