Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1325184pxb; Sun, 11 Apr 2021 15:48:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+sNFwS3aisarhXxftfCStQ9uaKvt10WTnNmbfVyFzXvNPbmdFKWETEFFQKm6QrAKcc4b4 X-Received: by 2002:a17:902:a5c6:b029:e5:df57:e156 with SMTP id t6-20020a170902a5c6b02900e5df57e156mr23361976plq.71.1618181325783; Sun, 11 Apr 2021 15:48:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618181325; cv=none; d=google.com; s=arc-20160816; b=gZdb9OowWWa966tT0J7zDrVSzgoEFD+jyIcgwU/ayeUMk/XHpP8E3JEq2m+CYbfVw1 F4gkSPtkrW4jFJxr8IOKMaYrVsikRAQ7oc6W3me67pAlIlqxyoVrN6QQ8Kcl29hE6eFW iYV25nRggtG6E/OrIOETJp1Lf/u8umj7ZbjouZ9tFQ6bDVpNvj0OSLLlfHaLipPkqJvZ GOjqWLycDmJTAJVnfzIBodtcD4uBHi6jLWwxcvo55RkbjHV/kC+lNj4an2A7NLO+F76F awNbrFLTNN9fgqgSndU/asjAjUglSY1xfZSS5UPrUdYK0awrpoS58bpphdIqycQLuBaS EeUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=xZhcd/R/Ca3jxjbfzedo6jlwVks7zUx67xoOlhLkvTM=; b=j4nBwoOzUjfqC3EF2pbVVtU6MJ/UI46dxpWV+9ELRgZ6za+yyRj7IvqIIQhdepmeIA ZA2THo9HdGwMoeHyGhPzTok/5AN1Iop56uNNvabNG6xHaBw9aH+xZi0TDlyV9Qux6I4H Ta5jaCjOVT+zxhLwu90HzvBjIqd1L8gtuAd4CCltacUe4V2wWWh3KAUxLLbSqDNVUw1m b5JQAtnSDLY80Aq93awdFoa8vQNB5kXUxsNMb6wLNpukDbTbgs2BcKQ4WWybt7eNMw33 n+e89vFdJig1wSQCAGkvkteOj477uOK3uWeZ9BTqUwbihk8jkKgWcHcZ0B5rDm/Z+f/S Oh2w== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g6si11627310pfo.58.2021.04.11.15.48.32; Sun, 11 Apr 2021 15:48:45 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235894AbhDKWWK (ORCPT + 99 others); Sun, 11 Apr 2021 18:22:10 -0400 Received: from smtprelay0128.hostedemail.com ([216.40.44.128]:53684 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235005AbhDKWWJ (ORCPT ); Sun, 11 Apr 2021 18:22:09 -0400 Received: from omf04.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id 3B5EF1801A773; Sun, 11 Apr 2021 22:21:52 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf04.hostedemail.com (Postfix) with ESMTPA id 2902BD1513; Sun, 11 Apr 2021 22:21:51 +0000 (UTC) Message-ID: <0362ad3912473d24e5927c0b54ed8fd3648c68a9.camel@perches.com> Subject: Re: [PATCH v2] iommu/amd: Fix extended features logging From: Joe Perches To: Alexander Monakov , linux-kernel@vger.kernel.org Cc: Paul Menzel , Joerg Roedel , Suravee Suthikulpanit , iommu@lists.linux-foundation.org Date: Sun, 11 Apr 2021 15:21:49 -0700 In-Reply-To: <20210411211330.2252-1-amonakov@ispras.ru> References: <20210411211330.2252-1-amonakov@ispras.ru> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.38.1-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspamout03 X-Rspamd-Queue-Id: 2902BD1513 X-Spam-Status: No, score=0.10 X-Stat-Signature: 9q8g74u5wmyjuhdqzmu6sgk8n19m8uoo X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX19fWofgnuzzhGoeM7lXW+imT0hmBDHhTow= X-HE-Tag: 1618179711-799595 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2021-04-12 at 00:13 +0300, Alexander Monakov wrote: > 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 > > Fixes: 9a295ff0ffc9 ("iommu/amd: Print extended features in one line to fix divergent log levels") > Link: https://lore.kernel.org/lkml/alpine.LNX.2.20.13.2104112326460.11104@monopod.intra.ispras.ru > Signed-off-by: Alexander Monakov > Cc: Paul Menzel > Cc: Joerg Roedel > Cc: Suravee Suthikulpanit > Cc: iommu@lists.linux-foundation.org > --- > > 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(-) > > diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c > index 596d0c413473..62913f82a21f 100644 > --- a/drivers/iommu/amd/init.c > +++ b/drivers/iommu/amd/init.c > @@ -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]); 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(-) diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 321f5906e6ed..0d219044726e 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -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) {