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 hu507c3BarVjyWCJOylMNR98Yd8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fLOH+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> 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) ||