Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp828718ybm; Fri, 29 May 2020 13:13:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydByybjO833VkZY1Am5xJORmwXyxK44MTmMQkxjh3/Og1ft5qMkvpw4J9aCt64fET5WNZ+ X-Received: by 2002:a05:6402:296:: with SMTP id l22mr10429794edv.353.1590783223695; Fri, 29 May 2020 13:13:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590783223; cv=none; d=google.com; s=arc-20160816; b=MuQPLQocqsncHWN0us7n78kVk+XadLc1KgY+nevP3hvuLui58HDXhe2pWTRY0f7EaX reLDxi8/yRDHvOtpTRowelKOhdY0dO5GuJD3/GwOVlAn1NBaxmG8V9XGts/7KLqq0ySB ySmFfDjl2mVZArhHDpuXaNyIp9fyk4K7M5acYfEWuVC9eX5HsQXAkO9LLgTC15IlxCaT BMrGABL5msr8+SBmxA9AUebHYl1owpDbWTgLk/imgaELKwhE+z/+DJruFi2nsM67Je4T 00GMIwXR7A3y3hh+7WnRHnlBwTzp/1hNHFdqZ5ogu7Ug6sQrqA61koe4f18WV6RQfXKk u1rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=SoELVLpF66pA/8wo7TskFAko35rc8mbnrozw6yNUhbQ=; b=nwlR0X51ldIRP1ChUqnzT+gbfXzuJgsTEIT4XtsJOTUmyHes30jGU+FPqcDdss6FIK pfVck1JPKpMFMa5FMI+R/5UnF4AhhaIuq42J7ERVoCmToBzcYFVn4O9gDhBqAhQAfRVV YXeiRpaWT0qkrlNGzibaoarm+LWvaU0pnSzNCL7r4seiN/pNeBCTAQnj1rsh1fsW14e0 CiLt7KE734eR2FJ0ZVe9erU8PyKUhRYijHAmGgXAVjx37EEzaLhCkQYdlfCvhWxG2Yl3 1iOFBw69aISqdPsIsAP3NOcqrtn7YGl3llBfOjHy+GpGIk1/lMmxT+i64ivdqtNcSERS CS+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h1si5838821edq.86.2020.05.29.13.13.19; Fri, 29 May 2020 13:13:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728129AbgE2ULJ (ORCPT + 99 others); Fri, 29 May 2020 16:11:09 -0400 Received: from mail.ispras.ru ([83.149.199.45]:38116 "EHLO mail.ispras.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726866AbgE2ULJ (ORCPT ); Fri, 29 May 2020 16:11:09 -0400 Received: from localhost.localdomain (unknown [46.188.10.168]) by mail.ispras.ru (Postfix) with ESMTPSA id 3BDC8CD461; Fri, 29 May 2020 23:11:06 +0300 (MSK) From: Alexander Monakov To: linux-kernel@vger.kernel.org Cc: Alexander Monakov , Joerg Roedel , Suravee Suthikulpanit , iommu@lists.linux-foundation.org Subject: [PATCH] iommu/amd: Fix event counter availability check Date: Fri, 29 May 2020 23:07:38 +0300 Message-Id: <20200529200738.1923-1-amonakov@ispras.ru> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The driver performs an extra check if the IOMMU's capabilities advertise presence of performance counters: it verifies that counters are writable by writing a hard-coded value to a counter and testing that reading that counter gives back the same value. Unfortunately it does so quite early, even before pci_enable_device is called for the IOMMU, i.e. when accessing its MMIO space is not guaranteed to work. On Ryzen 4500U CPU, this actually breaks the test: the driver assumes the counters are not writable, and disables the functionality. Moving init_iommu_perf_ctr just after iommu_flush_all_caches resolves the issue. This is the earliest point in amd_iommu_init_pci where the call succeeds on my laptop. Signed-off-by: Alexander Monakov Cc: Joerg Roedel Cc: Suravee Suthikulpanit Cc: iommu@lists.linux-foundation.org --- PS. I'm seeing another hiccup with IOMMU probing on my system: pci 0000:00:00.2: can't derive routing for PCI INT A pci 0000:00:00.2: PCI INT A: not connected Hopefully I can figure it out, but I'd appreciate hints. drivers/iommu/amd_iommu_init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 5b81fd16f5fa..1b7ec6b6a282 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -1788,8 +1788,6 @@ static int __init iommu_init_pci(struct amd_iommu *iommu) if (iommu->cap & (1UL << IOMMU_CAP_NPCACHE)) amd_iommu_np_cache = true; - init_iommu_perf_ctr(iommu); - if (is_rd890_iommu(iommu->dev)) { int i, j; @@ -1891,8 +1889,10 @@ static int __init amd_iommu_init_pci(void) init_device_table_dma(); - for_each_iommu(iommu) + for_each_iommu(iommu) { iommu_flush_all_caches(iommu); + init_iommu_perf_ctr(iommu); + } if (!ret) print_iommu_info(); base-commit: 75caf310d16cc5e2f851c048cd597f5437013368 -- 2.26.2