iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
To: Suravee Suthikulpanit
	<Suravee.Suthikulpanit-5C7GfCeVMHo@public.gmane.org>
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	acme-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	andihartmann-KuiJ5kEpwI6ELgA04lAiVw@public.gmane.org,
	mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	bp-Gina5bIWoIWzQB+pC5nmwQ@public.gmane.org
Subject: [PATCH] iommu/amd: Fix boot warning when device 00:00.0 is not iommu
Date: Tue, 23 Feb 2016 13:12:15 +0100	[thread overview]
Message-ID: <20160223121215.GA31151@8bytes.org> (raw)
In-Reply-To: <56CC44D8.4080604-5C7GfCeVMHo@public.gmane.org>

On Tue, Feb 23, 2016 at 06:39:04PM +0700, Suravee Suthikulpanit wrote:
> Actually, my V5 is rebased from tips which has moved several files.
> I think we might need to create a separate patch series to fix this
> issue in older kernels. Which branch should I rebase my changes for
> the older kernel?

The fix is iommu-code only. Based on your patches, I extracted this
smaller patch, which only fixes the issue. Does it look good to you? If
you are okay with it I am going to queue it asap into my iommu/fixes
branch and send it upstream.


	Joerg

>From b91309eedd77374fdecc379942c44f903e2dedff Mon Sep 17 00:00:00 2001
From: Suravee Suthikulpanit <Suravee.Suthikulpanit-5C7GfCeVMHo@public.gmane.org>
Date: Tue, 23 Feb 2016 13:03:30 +0100
Subject: [PATCH] iommu/amd: Fix boot warning when device 00:00.0 is not iommu
 covered

The setup code for the performance counters in the AMD IOMMU driver
tests whether the counters can be written. It tests to setup a counter
for device 00:00.0, which fails on systems where this particular device
is not covered by the IOMMU.

Fix this by not relying on device 00:00.0 but only on the IOMMU being
present.

Cc: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Signed-off-by: Suravee Suthikulpanit <Suravee.Suthikulpanit-5C7GfCeVMHo@public.gmane.org>
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
 drivers/iommu/amd_iommu_init.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 013bdff..d06a6d9 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -228,6 +228,10 @@ static int amd_iommu_enable_interrupts(void);
 static int __init iommu_go_to_state(enum iommu_init_state state);
 static void init_device_table_dma(void);
 
+static int iommu_pc_get_set_reg_val(struct amd_iommu *iommu,
+				    u8 bank, u8 cntr, u8 fxn,
+				    u64 *value, bool is_write);
+
 static inline void update_last_devid(u16 devid)
 {
 	if (devid > amd_iommu_last_bdf)
@@ -1142,8 +1146,8 @@ static void init_iommu_perf_ctr(struct amd_iommu *iommu)
 	amd_iommu_pc_present = true;
 
 	/* Check if the performance counters can be written to */
-	if ((0 != amd_iommu_pc_get_set_reg_val(0, 0, 0, 0, &val, true)) ||
-	    (0 != amd_iommu_pc_get_set_reg_val(0, 0, 0, 0, &val2, false)) ||
+	if ((0 != iommu_pc_get_set_reg_val(iommu, 0, 0, 0, &val, true)) ||
+	    (0 != iommu_pc_get_set_reg_val(iommu, 0, 0, 0, &val2, false)) ||
 	    (val != val2)) {
 		pr_err("AMD-Vi: Unable to write to IOMMU perf counter.\n");
 		amd_iommu_pc_present = false;
@@ -2283,22 +2287,15 @@ u8 amd_iommu_pc_get_max_counters(u16 devid)
 }
 EXPORT_SYMBOL(amd_iommu_pc_get_max_counters);
 
-int amd_iommu_pc_get_set_reg_val(u16 devid, u8 bank, u8 cntr, u8 fxn,
+static int iommu_pc_get_set_reg_val(struct amd_iommu *iommu,
+				    u8 bank, u8 cntr, u8 fxn,
 				    u64 *value, bool is_write)
 {
-	struct amd_iommu *iommu;
 	u32 offset;
 	u32 max_offset_lim;
 
-	/* Make sure the IOMMU PC resource is available */
-	if (!amd_iommu_pc_present)
-		return -ENODEV;
-
-	/* Locate the iommu associated with the device ID */
-	iommu = amd_iommu_rlookup_table[devid];
-
 	/* Check for valid iommu and pc register indexing */
-	if (WARN_ON((iommu == NULL) || (fxn > 0x28) || (fxn & 7)))
+	if (WARN_ON((fxn > 0x28) || (fxn & 7)))
 		return -ENODEV;
 
 	offset = (u32)(((0x40|bank) << 12) | (cntr << 8) | fxn);
@@ -2322,3 +2319,16 @@ int amd_iommu_pc_get_set_reg_val(u16 devid, u8 bank, u8 cntr, u8 fxn,
 	return 0;
 }
 EXPORT_SYMBOL(amd_iommu_pc_get_set_reg_val);
+
+int amd_iommu_pc_get_set_reg_val(u16 devid, u8 bank, u8 cntr, u8 fxn,
+				    u64 *value, bool is_write)
+{
+	struct amd_iommu *iommu = amd_iommu_rlookup_table[devid];
+
+	/* Make sure the IOMMU PC resource is available */
+	if (!amd_iommu_pc_present || iommu == NULL)
+		return -ENODEV;
+
+	return iommu_pc_get_set_reg_val(iommu, bank, cntr, fxn,
+					value, is_write);
+}
-- 
1.8.4.5

      parent reply	other threads:[~2016-02-23 12:12 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-11  9:15 [PATCH V4 0/6] perf/amd/iommu: Enable multi-IOMMU support Suravee Suthikulpanit
2016-02-11  9:15 ` [PATCH V4 3/6] iommu/amd: Introduce amd_iommu_get_num_iommus() Suravee Suthikulpanit
     [not found] ` <1455182127-17551-1-git-send-email-Suravee.Suthikulpanit-5C7GfCeVMHo@public.gmane.org>
2016-02-11  9:15   ` [PATCH V4 1/6] perf/amd/iommu: Consolidate and move perf_event_amd_iommu header Suravee Suthikulpanit
2016-02-11  9:15   ` [PATCH V4 2/6] perf/amd/iommu: Modify functions to query max banks and counters Suravee Suthikulpanit
2016-02-18 11:11     ` Borislav Petkov
     [not found]       ` <20160218111116.GE3694-fF5Pk5pvG8Y@public.gmane.org>
2016-02-22  4:55         ` Suravee Suthikulpanit
2016-02-11  9:15   ` [PATCH V4 4/6] perf/amd/iommu: Introduce get_iommu_bnk_cnt_evt_idx Suravee Suthikulpanit
     [not found]     ` <1455182127-17551-5-git-send-email-Suravee.Suthikulpanit-5C7GfCeVMHo@public.gmane.org>
2016-02-18 11:45       ` Borislav Petkov
2016-02-11  9:15   ` [PATCH V4 5/6] perf/amd/iommu: Enable support for multiple IOMMUs Suravee Suthikulpanit
2016-02-18 13:18     ` Peter Zijlstra
     [not found]       ` <20160218131853.GU6357-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2016-02-22  8:00         ` Suravee Suthikulpanit
2016-02-22 14:07           ` Peter Zijlstra
     [not found]             ` <20160222140741.GH6357-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2016-02-23  5:12               ` Suravee Suthikulpanit
     [not found]                 ` <56CBEA4A.8070001-5C7GfCeVMHo@public.gmane.org>
2016-02-23  5:24                   ` Alex Williamson
     [not found]                     ` <20160222222457.2824f7e0-1yVPhWWZRC1BDLzU/O5InQ@public.gmane.org>
2016-02-23  9:56                       ` Suravee Suthikulpanit
     [not found]     ` <1455182127-17551-6-git-send-email-Suravee.Suthikulpanit-5C7GfCeVMHo@public.gmane.org>
2016-02-18 13:21       ` Borislav Petkov
2016-02-11  9:15   ` [PATCH V4 6/6] perf/amd/iommu: Clean up print messages pr_debug Suravee Suthikulpanit
     [not found]     ` <1455182127-17551-7-git-send-email-Suravee.Suthikulpanit-5C7GfCeVMHo@public.gmane.org>
2016-02-18 13:22       ` Borislav Petkov
2016-02-18  2:30   ` [PATCH V4 0/6] perf/amd/iommu: Enable multi-IOMMU support Suravee Suthikulpanit
2016-02-23 11:04   ` Joerg Roedel
     [not found]     ` <20160223110406.GA22747-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2016-02-23 11:27       ` Suravee Suthikulpanit
     [not found]         ` <56CC422E.7050905-5C7GfCeVMHo@public.gmane.org>
2016-02-23 11:39           ` Suravee Suthikulpanit
     [not found]             ` <56CC44D8.4080604-5C7GfCeVMHo@public.gmane.org>
2016-02-23 12:12               ` Joerg Roedel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160223121215.GA31151@8bytes.org \
    --to=joro-zlv9swrftaidnm+yrofe0a@public.gmane.org \
    --cc=Suravee.Suthikulpanit-5C7GfCeVMHo@public.gmane.org \
    --cc=acme-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=andihartmann-KuiJ5kEpwI6ELgA04lAiVw@public.gmane.org \
    --cc=bp-Gina5bIWoIWzQB+pC5nmwQ@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).