iommu/amd: Fix extended features logging
Subsystems (2)
PATCH v2 1/1 iommu/amd: Fix extended features logging
print_iommu_info prints the EFR register and then the decoded list of features on a separate line:
pci 0000:00:00.2: AMD-Vi: Extended features (0x206d73ef22254ade):
PPR X2APIC NX GT IA GA PC GA_vAPIC
The second line is emitted via 'pr_cont', which causes it to have a different ('warn') loglevel compared to the previous line ('info').
Commit 9a295ff0ffc9 attempted to rectify this by removing the newline from the pci_info format string, but this doesn't work, as pci_info calls implicitly append a newline anyway.
Printing the decoded features on the same line would make it quite long. Instead, change pci_info() to pr_info() to omit PCI bus location info, which is shown in the preceding message anyway. This results in:
pci 0000:00:00.2: AMD-Vi: Found IOMMU cap 0x40
AMD-Vi: Extended features (0x206d73ef22254ade): PPR X2APIC NX GT IA GA PC GA_vAPIC
AMD-Vi: Interrupt remapping enabled
---
v2: avoid pr_info(""), change pci_info() to pr_info() for a nicer solution
drivers/iommu/amd/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/amd/init.c +2 -2
@@ -1929,8 +1929,8 @@ static void print_iommu_info(void)pci_info (pdev,"Found IOMMU cap 0x%hx\n" , iommu->cap_ptr);if (iommu->cap & (1 <<IOMMU_CAP_EFR )) { -pci_info (pdev,"Extended features (%#llx):" , - iommu->features); +pr_info ("Extended features (%#llx):" , iommu->features); +for (i =0 ; i <ARRAY_SIZE (feat_str); ++i) {if (iommu_feature (iommu, (1ULL << i)))pr_cont (" %s" , feat_str[i]);
Signature · 1 line
2.30.0
Quoted 49 lines · Alexander Monakov
print_iommu_infoprints the EFR register and then the decoded list of features on a separate line:pci 0000:00:00.2: AMD-Vi: Extended features (
0x206d73ef22254ade):
PPR X2APIC NX GT IA GA PCGA_vAPICThe second line is emitted via '
pr_cont', which causes it to have a different ('warn') loglevel compared to the previous line ('info').Commit
9a295ff0ffc9attempted to rectify this by removing the newline from thepci_infoformat string, but this doesn't work, aspci_infocalls implicitly append a newline anyway.Printing the decoded features on the same line would make it quite long. Instead, change
pci_info()topr_info()to omit PCI bus location info, which is shown in the preceding message anyway. This results in:pci 0000:00:00.2: AMD-Vi: Found IOMMU cap
0x40
AMD-Vi: Extended features (0x206d73ef22254ade): PPR X2APIC NX GT IA GA PCGA_vAPIC
AMD-Vi: Interrupt remapping enabledFixes 9a295ff0ffc9 ("iommu/amd: Print extended features in one line to fix divergent log levels")Signed-off-by Alexander Monakov <[email protected]>Cc Paul Menzel <[email protected]>Cc Joerg Roedel <[email protected]>Cc Suravee Suthikulpanit <[email protected]>---
v2: avoid
pr_info(""), changepci_info()topr_info()for a nicer solutiondrivers/iommu/amd/init.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)drivers/iommu/amd/init.c +0
-0@@ -1929,8 +1929,8 @@ static void print_iommu_info(void) pci_info(pdev, "Found IOMMU cap 0x%hx\n", iommu->cap_ptr);if (
iommu->cap& (1 <<IOMMU_CAP_EFR)) {drivers/iommu/amd/init.c +2
-2-pci_info (pdev,"Extended features (%#llx):" , - iommu->features); +pr_info ("Extended features (%#llx):" , iommu->features); +
Quoted 3 lines
for (i = 0; i <
ARRAY_SIZE(feat_str); ++i) { if (iommu_feature(iommu, (1ULL << i)))pr_cont(" %s", feat_str[i]);
How about avoiding all of this by using a temporary buffer and a single pci_info.
Miscellanea:
o Move the feat_str and i declarations into the if block for locality
--- drivers/iommu/amd/init.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
drivers/iommu/amd/init.c +18 -11
@@ -1943,30 +1943,37 @@ static int __init iommu_init_pci(struct amd_iommu *iommu)static void print_iommu_info (void ) { -static const char *const feat_str[] = { -"PreF" ,"PPR" ,"X2APIC" ,"NX" ,"GT" ,"[5]" , -"IA" ,"GA" ,"HE" ,"PC" - };struct amd_iommu *iommu;for_each_iommu (iommu) {struct pci_dev *pdev = iommu->dev; -int i;pci_info (pdev,"Found IOMMU cap 0x%x\n" , iommu->cap_ptr);if (iommu->cap & (1 <<IOMMU_CAP_EFR )) { -pci_info (pdev,"Extended features (%#llx):" , - iommu->features); +static const char *const feat_str[] = { +"PreF" ,"PPR" ,"X2APIC" ,"NX" ,"GT" ,"[5]" , +"IA" ,"GA" ,"HE" ,"PC" + }; +int i; +char features[128 ] ="" ; +int len =0 ; +for (i =0 ; i <ARRAY_SIZE (feat_str); ++i) { -if (iommu_feature (iommu, (1ULL << i))) -pr_cont (" %s" , feat_str[i]); +if (!iommu_feature (iommu,BIT_ULL (i))) +continue ; + len +=scnprintf (features + len, +sizeof (features) - len, +" %s" , feat_str[i]); }if (iommu->features &FEATURE_GAM_VAPIC ) -pr_cont (" GA_vAPIC" ); + len +=scnprintf (features + len, +sizeof (features) - len, +" %s" ,"GA_vPIC" ); -pr_cont ("\n" ); +pci_info (pdev,"Extended features (%#llx):%s\n" , + iommu->features, features); } }if (irq_remapping_enabled) {
Quoted 14 lines · Joe Perches
Quoted 14 lines
v2: avoid
pr_info(""), changepci_info()topr_info()for a nicer solutiondrivers/iommu/amd/init.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)drivers/iommu/amd/init.c +0
-0@@ -1929,8 +1929,8 @@ static void print_iommu_info(void) pci_info(pdev, "Found IOMMU cap 0x%hx\n", iommu->cap_ptr);
Quoted 11 lines
Quoted 8 lines
if (
iommu->cap& (1 <<IOMMU_CAP_EFR)) {drivers/iommu/amd/init.c +2
-2-pci_info (pdev,"Extended features (%#llx):" , - iommu->features); +pr_info ("Extended features (%#llx):" , iommu->features); +for (i = 0; i <
ARRAY_SIZE(feat_str); ++i) { if (iommu_feature(iommu, (1ULL << i)))pr_cont(" %s", feat_str[i]);How about avoiding all of this by using a temporary buffer and a single
pci_info.
I think it is mostly up to the maintainers, but from my perspective, it's not good to conflate such a simple bugfix with the substantial rewrite you are proposing (which also increases code complexity).
My two-line patch is a straightforward fix to a bug that people already agreed needs to be fixed (just the previous attempt turned out to be insufficient). If there's a desire to eliminate pr_cont calls (which I wouldn't support in this instance), the rewrite can go in separately from the bugfix.
A major problem with landing a simple bugfix together with a rewrite in a big patch is that if a rewrite causes a problem, the whole patch gets reverted and we end up without a trivial bugfix.
And, once again: can we please not emit the feature list via pci_info, the line is long enough already even without the pci bus location info.
Joerg, are you satisfied with my v2 patch, are you waiting for anything before picking it up?
Alexander
Quoted 54 lines
Miscellanea:
o Move thefeat_strand i declarations into the if block for locality--- drivers/iommu/amd/init.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)drivers/iommu/amd/init.c +13
-10@@ -1943,30 +1943,37 @@ static int __init iommu_init_pci(struct amd_iommu *iommu)static void print_iommu_info (void ) { -static const char *const feat_str[] = { -"PreF" ,"PPR" ,"X2APIC" ,"NX" ,"GT" ,"[5]" , -"IA" ,"GA" ,"HE" ,"PC" - };struct amd_iommu *iommu;for_each_iommu (iommu) {struct pci_dev *pdev = iommu->dev; -int i;pci_info (pdev,"Found IOMMU cap 0x%x\n" , iommu->cap_ptr);if (iommu->cap & (1 <<IOMMU_CAP_EFR )) { -pci_info (pdev,"Extended features (%#llx):" , - iommu->features); +static const char *const feat_str[] = { +"PreF" ,"PPR" ,"X2APIC" ,"NX" ,"GT" ,"[5]" , +"IA" ,"GA" ,"HE" ,"PC" + }; +int i; +char features[128 ] ="" ; +int len =0 ; +for (i =0 ; i <ARRAY_SIZE (feat_str); ++i) { -if (iommu_feature (iommu, (1ULL << i))) -pr_cont (" %s" , feat_str[i]); +if (!iommu_feature (iommu,BIT_ULL (i))) +continue ; + len +=scnprintf (features + len, +sizeof (features) - len, +" %s" , feat_str[i]); }if (iommu->features &FEATURE_GAM_VAPIC ) -pr_cont (" GA_vAPIC" );
drivers/iommu/amd/init.c static int __init iommu_init_pci(struct amd_iommu *iommu) · line 1979
Quoted 10 lines
drivers/iommu/amd/init.c +5
-1+ len +=scnprintf (features + len, +sizeof (features) - len, +" %s" ,"GA_vPIC" ); -pr_cont ("\n" ); +pci_info (pdev,"Extended features (%#llx):%s\n" , + iommu->features, features); } }if (irq_remapping_enabled) {
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 28 lines · Alexander Monakov
Quoted 14 lines · Joe Perches
Quoted 14 lines
v2: avoid
pr_info(""), changepci_info()topr_info()for a nicer solutiondrivers/iommu/amd/init.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)drivers/iommu/amd/init.c +0
-0@@ -1929,8 +1929,8 @@ static void print_iommu_info(void) pci_info(pdev, "Found IOMMU cap 0x%hx\n", iommu->cap_ptr);Quoted 11 lines
Quoted 8 lines
if (
iommu->cap& (1 <<IOMMU_CAP_EFR)) {drivers/iommu/amd/init.c +2
-2-pci_info (pdev,"Extended features (%#llx):" , - iommu->features); +pr_info ("Extended features (%#llx):" , iommu->features); +for (i = 0; i <
ARRAY_SIZE(feat_str); ++i) { if (iommu_feature(iommu, (1ULL << i)))pr_cont(" %s", feat_str[i]);How about avoiding all of this by using a temporary buffer and a single
pci_info.
Quoted 3 lines
I think it is mostly up to the maintainers, but from my perspective, it's not good to conflate such a simple bugfix with the substantial rewrite you are proposing (which also increases code complexity).
You and I have _significant_ differences in the definition of substantial.
Buffering the output is the preferred code style in preference to pr_cont.
Do remember pr_cont should _only_ be used when absolutely necessary as interleaving of other messages from other processes/threads can and does occur.