From patchwork Wed Mar 19 08:40:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Pan-Doh X-Patchwork-Id: 14022273 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F01AD211484 for ; Wed, 19 Mar 2025 08:41:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742373667; cv=none; b=e2JvJ6TcwRh8zB0AQjuJHSiSpq+u39PkAd1qTtMTwYwekjS5VLTRnI3bKaOE9e5jGPTMifoBkYmPgocJBK7U9xusLqQV/HNJOB6QS25jdyEovZZuQ/gGP3tRjUdpl5S0laQJyiRwSdlEZYsfTFgvQh1pTaFOo1fNDha2NUKkkPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742373667; c=relaxed/simple; bh=GOG0WE76MB9baa1tT4VsAXQzEz+JjzrCTqFeJ0u+3X0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MqMoJNKviJRB2ekOGuGahy29/gChvjBWG4ln08+P3WJq7ZOs0BSBhXvdONs1WPkKnEd7440tdHgVgrWQzsrnnL0utWeNJBlrOprbJQTqcIW1qH+j0V/ZjubduZ/RHONOO8gqufXbNzILoq6cL67eTQAdILbcKrD51Af6XsFQSwA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--pandoh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=VGHNnbfM; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--pandoh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="VGHNnbfM" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2241aad40f3so108901595ad.1 for ; Wed, 19 Mar 2025 01:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742373665; x=1742978465; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=74C5WvFIkJT1ruLlg2wdf4z0XA1NMV1P5buaVGuxgpo=; b=VGHNnbfMxR0SwNtlflpsW45gDWPRbIacnaZPDG3cWgKp+fr5DpZsSUgkU4LSFIB+kC awjiORPiT626VB/ppFvMpnbkODdwv2XVngmc/aXLUSxqF9swPC21pMsqfGxvhQ4ML5wY ipVKepb4A7OrX6n5Aj8LboW9XvmXjKJl63LGWB0KmiCW9u1ZzGWi/3FD4GXDv+AB/o/o EOLlXG3QNXB/ujUWzuGpF82o5TeqH8zNNvCjud20yBuunJlUU896U/yKiqqe1KYdUY3o AE5dQ9KnaQsd/qzNe0Uj/oBSV8NAPAWip7WgUg18r/qRf0n+hks/OsmtZLMWodpvn/uG PxIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742373665; x=1742978465; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=74C5WvFIkJT1ruLlg2wdf4z0XA1NMV1P5buaVGuxgpo=; b=THSqBTuTs5WZoFJE7HjoF0a9w3iP3+tfQ/M2MwhAt/IZQKJFUcT1tgByWf+rnb7b0B rzoGhT6AmRSeuTUbDb72VQvcufAZ/AninkrBDu1as8ezV/4CWFtDf5J1BMoXwRiMm62W HAKK0tmDfXk8Wjir6cMGzjL5ZwetX4FJVkIfvqwrJ+lUzd2eAgxc9LE7aolGknysuvFv ZeXWzRCpEwbmQc2+cpaujYIUT3oHJdrqgnRp2CpJkVVfcsHJHfLdYes7lhOBJRXCMMin MVTGJqIKe7JHceECuIcApCf851/eXHIYxQ+dKZ0X4PFpBWJ5Je/n2d9ALM6GEeWEE3+N Yj2Q== X-Gm-Message-State: AOJu0YzEy9xQz5xtS8/75GtU0pDqzSLFEsAlBJstdfcMleC1L1g/JFsQ jfLLeIguk03wjqB4PO3OyAyki1iLKfqWBmUTwQ/gZoVJDgbvrScEw1xlRNgFO00YmZIUm4GOtXr wog== X-Google-Smtp-Source: AGHT+IE7Q8r8bZJCF+ez0ZNtOr5Dliyosd4DiLp7F+KjSCijKS98ZeDQ0Xy+Q8aUOaQm0m32r1vHOnuoi4E= X-Received: from pllo22.prod.google.com ([2002:a17:902:7796:b0:223:5693:a4e9]) (user=pandoh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1ce:b0:223:4c09:20b8 with SMTP id d9443c01a7336-22649c8f3a7mr23464275ad.37.1742373665017; Wed, 19 Mar 2025 01:41:05 -0700 (PDT) Date: Wed, 19 Mar 2025 01:40:42 -0700 In-Reply-To: <20250319084050.366718-1-pandoh@google.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319084050.366718-1-pandoh@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Message-ID: <20250319084050.366718-2-pandoh@google.com> Subject: [PATCH v3 1/8] PCI/AER: Check log level once and propagate down From: Jon Pan-Doh To: Bjorn Helgaas , Karolina Stolarek Cc: linux-pci@vger.kernel.org, Martin Petersen , Ben Fuller , Drew Walton , Anil Agrawal , Tony Luck , " =?utf-8?q?Ilpo_J=C3=A4rvinen?= " , Sathyanarayanan Kuppuswamy , Lukas Wunner , Jonathan Cameron , Terry Bowman , Jon Pan-Doh From: Karolina Stolarek When reporting an AER error, we check its type multiple times to determine the log level for each message. Do this check only in the top-level functions (aer_isr_one_error(), pci_print_aer()) and propagate the result down the call chain. Signed-off-by: Karolina Stolarek Signed-off-by: Jon Pan-Doh Reviewed-by: Jon Pan-Doh Reviewed-by: Kuppuswamy Sathyanarayanan --- drivers/pci/pci.h | 2 +- drivers/pci/pcie/aer.c | 37 ++++++++++++++++++++----------------- drivers/pci/pcie/dpc.c | 2 +- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index b8911d1e10dc..75985b96ecc1 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -551,7 +551,7 @@ struct aer_err_info { }; int aer_get_device_error_info(struct pci_dev *dev, struct aer_err_info *info); -void aer_print_error(struct pci_dev *dev, struct aer_err_info *info); +void aer_print_error(struct pci_dev *dev, struct aer_err_info *info, const char *level); int pcie_read_tlp_log(struct pci_dev *dev, int where, int where2, unsigned int tlp_len, bool flit, diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index 9cff7069577e..cc9c80cd88f3 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -670,20 +670,18 @@ static void pci_rootport_aer_stats_incr(struct pci_dev *pdev, } static void __aer_print_error(struct pci_dev *dev, - struct aer_err_info *info) + struct aer_err_info *info, + const char *level) { const char **strings; unsigned long status = info->status & ~info->mask; - const char *level, *errmsg; + const char *errmsg; int i; - if (info->severity == AER_CORRECTABLE) { + if (info->severity == AER_CORRECTABLE) strings = aer_correctable_error_string; - level = KERN_WARNING; - } else { + else strings = aer_uncorrectable_error_string; - level = KERN_ERR; - } for_each_set_bit(i, &status, 32) { errmsg = strings[i]; @@ -696,11 +694,11 @@ static void __aer_print_error(struct pci_dev *dev, pci_dev_aer_stats_incr(dev, info); } -void aer_print_error(struct pci_dev *dev, struct aer_err_info *info) +void aer_print_error(struct pci_dev *dev, struct aer_err_info *info, + const char *level) { int layer, agent; int id = pci_dev_id(dev); - const char *level; if (!info->status) { pci_err(dev, "PCIe Bus Error: severity=%s, type=Inaccessible, (Unregistered Agent ID)\n", @@ -711,8 +709,6 @@ void aer_print_error(struct pci_dev *dev, struct aer_err_info *info) layer = AER_GET_LAYER_ERROR(info->severity, info->status); agent = AER_GET_AGENT(info->severity, info->status); - level = (info->severity == AER_CORRECTABLE) ? KERN_WARNING : KERN_ERR; - aer_printk(level, dev, "PCIe Bus Error: severity=%s, type=%s, (%s)\n", aer_error_severity_string[info->severity], aer_error_layer[layer], aer_agent_string[agent]); @@ -720,7 +716,7 @@ void aer_print_error(struct pci_dev *dev, struct aer_err_info *info) aer_printk(level, dev, " device [%04x:%04x] error status/mask=%08x/%08x\n", dev->vendor, dev->device, info->status, info->mask); - __aer_print_error(dev, info); + __aer_print_error(dev, info, level); if (info->tlp_header_valid) pcie_print_tlp_log(dev, &info->tlp, dev_fmt(" ")); @@ -765,15 +761,18 @@ void pci_print_aer(struct pci_dev *dev, int aer_severity, { int layer, agent, tlp_header_valid = 0; u32 status, mask; + const char *level; struct aer_err_info info; if (aer_severity == AER_CORRECTABLE) { status = aer->cor_status; mask = aer->cor_mask; + level = KERN_WARNING; } else { status = aer->uncor_status; mask = aer->uncor_mask; tlp_header_valid = status & AER_LOG_TLP_MASKS; + level = KERN_ERR; } layer = AER_GET_LAYER_ERROR(aer_severity, status); @@ -786,7 +785,7 @@ void pci_print_aer(struct pci_dev *dev, int aer_severity, info.first_error = PCI_ERR_CAP_FEP(aer->cap_control); pci_err(dev, "aer_status: 0x%08x, aer_mask: 0x%08x\n", status, mask); - __aer_print_error(dev, &info); + __aer_print_error(dev, &info, level); pci_err(dev, "aer_layer=%s, aer_agent=%s\n", aer_error_layer[layer], aer_agent_string[agent]); @@ -1257,14 +1256,15 @@ int aer_get_device_error_info(struct pci_dev *dev, struct aer_err_info *info) return 1; } -static inline void aer_process_err_devices(struct aer_err_info *e_info) +static inline void aer_process_err_devices(struct aer_err_info *e_info, + const char *level) { int i; /* Report all before handle them, not to lost records by reset etc. */ for (i = 0; i < e_info->error_dev_num && e_info->dev[i]; i++) { if (aer_get_device_error_info(e_info->dev[i], e_info)) - aer_print_error(e_info->dev[i], e_info); + aer_print_error(e_info->dev[i], e_info, level); } for (i = 0; i < e_info->error_dev_num && e_info->dev[i]; i++) { if (aer_get_device_error_info(e_info->dev[i], e_info)) @@ -1282,6 +1282,7 @@ static void aer_isr_one_error(struct aer_rpc *rpc, { struct pci_dev *pdev = rpc->rpd; struct aer_err_info e_info; + const char *level; pci_rootport_aer_stats_incr(pdev, e_src); @@ -1292,6 +1293,7 @@ static void aer_isr_one_error(struct aer_rpc *rpc, if (e_src->status & PCI_ERR_ROOT_COR_RCV) { e_info.id = ERR_COR_ID(e_src->id); e_info.severity = AER_CORRECTABLE; + level = KERN_WARNING; if (e_src->status & PCI_ERR_ROOT_MULTI_COR_RCV) e_info.multi_error_valid = 1; @@ -1300,11 +1302,12 @@ static void aer_isr_one_error(struct aer_rpc *rpc, aer_print_port_info(pdev, &e_info); if (find_source_device(pdev, &e_info)) - aer_process_err_devices(&e_info); + aer_process_err_devices(&e_info, level); } if (e_src->status & PCI_ERR_ROOT_UNCOR_RCV) { e_info.id = ERR_UNCOR_ID(e_src->id); + level = KERN_ERR; if (e_src->status & PCI_ERR_ROOT_FATAL_RCV) e_info.severity = AER_FATAL; @@ -1319,7 +1322,7 @@ static void aer_isr_one_error(struct aer_rpc *rpc, aer_print_port_info(pdev, &e_info); if (find_source_device(pdev, &e_info)) - aer_process_err_devices(&e_info); + aer_process_err_devices(&e_info, level); } } diff --git a/drivers/pci/pcie/dpc.c b/drivers/pci/pcie/dpc.c index df42f15c9829..9e4c9ac737a7 100644 --- a/drivers/pci/pcie/dpc.c +++ b/drivers/pci/pcie/dpc.c @@ -289,7 +289,7 @@ void dpc_process_error(struct pci_dev *pdev) else if (reason == PCI_EXP_DPC_STATUS_TRIGGER_RSN_UNCOR && dpc_get_aer_uncorrect_severity(pdev, &info) && aer_get_device_error_info(pdev, &info)) { - aer_print_error(pdev, &info); + aer_print_error(pdev, &info, KERN_ERR); pci_aer_clear_nonfatal_status(pdev); pci_aer_clear_fatal_status(pdev); } From patchwork Wed Mar 19 08:40:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jon Pan-Doh X-Patchwork-Id: 14022274 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8552B211484 for ; Wed, 19 Mar 2025 08:41:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742373670; cv=none; b=Nj/rIRPX4oax7FhXSZ4s6w8rojE6xuNJcaXHFexJQD0WmgUVNGVO48oGnPpea2wmleeHPA4mOX43yv32vVioysdEK6kQTO733tLX6IPY2lyT8arTw9FuHqHY6DTM74AXRKPXgiONhBvyP7cp0j+CovgjGVNhBlTDz+VkFvqR5m4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742373670; c=relaxed/simple; bh=MwEATReO8imz4GoKPAFiBiNDctI15TMlRL06/TVa40M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mAxMXgih5iJEyNWW6PdG92lH2XVE3GMci5r0G/XbLy+JJyj4u771bIPm3ZClh1hsj53+aRrb8Q/dUpnLpuwyBuJVeILwkop4NjyZA6wiBfcTCSGY677YCCRb6QJM0etRGSFegxl9z674sNPwkL1BbYe7svAOBkhfsPsjoNU7emQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--pandoh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wGY+gECu; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--pandoh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wGY+gECu" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-22412127fd7so84335755ad.0 for ; Wed, 19 Mar 2025 01:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742373669; x=1742978469; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=H9AxGwy1IhUwP8hXGISKWkuM3ZklYPzsVZdfo4nULSY=; b=wGY+gECuEcidQ900nArEMb97ZsajuvkjI3wPKEZowgS4B5gTzGiiY5M4/qr3Nej1Qt RYFG+G0b/PqZFvpRddspBwbYJ70ojyCbQDG80qRNoPqtA9Xsy+2884RihW24MXTt4eXp fksKjc0YrhAOPclK2AQDLqj+8TVvfCXbRlwdUhNGLvW5z5TODRrLL9XGzx/DTzZG1X4p FmGvqFSoWnApnBUxMM0hATWZOau9bXda/3sbYOj7GczHpHYkLCtz1NEHCd32frYxGj1O uauX76HmEHD5F1g5VGY4O9CMKWkRkwEMmrD8jK0Q/wieXJ2e/+Cf0XQJlFzNZMXG47RI /FTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742373669; x=1742978469; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=H9AxGwy1IhUwP8hXGISKWkuM3ZklYPzsVZdfo4nULSY=; b=lCBuDUkWKsllso85LaRYLCuHu6DHzl041Mxab+JhlsEbV0FtM32OWZqdkYjBKxFQ3j YMGAOpSmaWRJFYL6lNFwdkUPSrOfu9oEcumORlD2swNCGOZelhm1QpDCChjfJKFaMQEs rgfZe7AgESt30034idd5jdRqKmNSXubMw7J2ASn6aQbQrTAl1G+WHNhgyLWT0PsrBspM ITFenu6hc2P1n+hxr/r6RqxWvD5k70E6+JUCEkwzQHJ4msgMDDqoAzIW/lD6oZvs/71+ z7oPOo8YCdMTWV/hq7AEbJifp8sk6z0fVRbnYB7X6bC67en+C1JLQ7TKfm0cei5YjMti f9/g== X-Gm-Message-State: AOJu0YzjWClDMUalT9aoQ97XMRGJvswezOBk73dh0drkSxp01FvUd0wh 2aEgfatdVYsl0iWXUZL40mrV3CATIGIlgdv1E26I6GtExGyJh156wYfmsKC9Ie8WNGiqFnPJc56 zNA== X-Google-Smtp-Source: AGHT+IFCu6a9ZK9xBCnJ2jlKnyBDnng8eNVjKexlSoToTJPVsU3/B6u6SEIjmcgQgHRFOR7D3TRTP/HVh0U= X-Received: from pjk8.prod.google.com ([2002:a17:90b:5588:b0:2fc:ccfe:368]) (user=pandoh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f68e:b0:224:2a6d:55ae with SMTP id d9443c01a7336-22649a6a8f8mr32820175ad.48.1742373668797; Wed, 19 Mar 2025 01:41:08 -0700 (PDT) Date: Wed, 19 Mar 2025 01:40:43 -0700 In-Reply-To: <20250319084050.366718-1-pandoh@google.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319084050.366718-1-pandoh@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Message-ID: <20250319084050.366718-3-pandoh@google.com> Subject: [PATCH v3 2/8] PCI/AER: Make all pci_print_aer() log levels depend on error type From: Jon Pan-Doh To: Bjorn Helgaas , Karolina Stolarek Cc: linux-pci@vger.kernel.org, Martin Petersen , Ben Fuller , Drew Walton , Anil Agrawal , Tony Luck , " =?utf-8?q?Ilpo_J=C3=A4rvinen?= " , Sathyanarayanan Kuppuswamy , Lukas Wunner , Jonathan Cameron , Terry Bowman , Jon Pan-Doh From: Karolina Stolarek Some existing logs in pci_print_aer() log with error severity by default. Convert them to depend on error type (consistent with rest of AER logging). Signed-off-by: Karolina Stolarek Signed-off-by: Jon Pan-Doh Reviewed-by: Ilpo Järvinen Reviewed-by: Kuppuswamy Sathyanarayanan --- drivers/pci/pcie/aer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index cc9c80cd88f3..7eeaad917134 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -784,14 +784,14 @@ void pci_print_aer(struct pci_dev *dev, int aer_severity, info.mask = mask; info.first_error = PCI_ERR_CAP_FEP(aer->cap_control); - pci_err(dev, "aer_status: 0x%08x, aer_mask: 0x%08x\n", status, mask); + aer_printk(level, dev, "aer_status: 0x%08x, aer_mask: 0x%08x\n", status, mask); __aer_print_error(dev, &info, level); - pci_err(dev, "aer_layer=%s, aer_agent=%s\n", - aer_error_layer[layer], aer_agent_string[agent]); + aer_printk(level, dev, "aer_layer=%s, aer_agent=%s\n", + aer_error_layer[layer], aer_agent_string[agent]); if (aer_severity != AER_CORRECTABLE) - pci_err(dev, "aer_uncor_severity: 0x%08x\n", - aer->uncor_severity); + aer_printk(level, dev, "aer_uncor_severity: 0x%08x\n", + aer->uncor_severity); if (tlp_header_valid) pcie_print_tlp_log(dev, &aer->header_log, dev_fmt(" ")); From patchwork Wed Mar 19 08:40:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Pan-Doh X-Patchwork-Id: 14022275 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B678D15A85A for ; Wed, 19 Mar 2025 08:41:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742373674; cv=none; b=F1MxYU0uWtftqD7tEvppYzIbpYiRjwk6umJemn33xoIhv5pwhS5xzdHTjyOEa8ayc3P4ZOi9mU4tAVDiTXFV2QXnPq1aq2I+/cnFSmbKyZqTSwzix5ZC6NvJ0iprhZIh4SlojrJc6GIeEBjMYDjpNuaD8L72uqKxp5VOrLNITOY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742373674; c=relaxed/simple; bh=8v1Wu/st9YoPC4LuMevzXS+s4VlldbD4VWj4yFviFSk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hemUF1BNDAiBRmZ93duiBYrqBbNLAmJcx6WGyY5A4OkKP4acr7J/r0yGVrBSZ5cxTRx+3AthKulnm+QclDw3ddtVY5yI6WFa5OkTsg9BkuCkE4BDIo89cyIPVDon6QxFNuDKZQRipiUoWCH0snIq+zUd4h0blOylSeuo5lejWZg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--pandoh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YZLRoqX7; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--pandoh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YZLRoqX7" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ff58318acaso11523425a91.0 for ; Wed, 19 Mar 2025 01:41:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742373672; x=1742978472; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=i08StNHvG5KNUx/4IydE/l4KY3QQy5TNH3wrC1N9nos=; b=YZLRoqX7w/iPYXo+L0/YHf9uQ6x0sr/xOYm/ZpiVWgi5//QbK5ByPpuRq9B9OQMWDt GyzNlmdTYrDZEXhrY95bxxliUiVlkkbO9/2R0Wi1ehXjivkPwGcA/3JcA0XFogd3yJw7 9IePxSowNTAiqNbHUbaFgs92kVv1EFDoH/sxo/cscovnvsqb0xXgojQxAvuog5xPi0IE 2aoSAP0HDcgiyzu8i1tyuWMRj5szPcBXqKWXSH82SR77Z1cxyEyq6H0c5Qx9E9ctFlNK YmiV6iBsgi3y7AO/r/LyhAtxV1MYbfg2nEhmoLp8304PvBsOWDkLo8ah4exN3t9OOegV JkuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742373672; x=1742978472; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=i08StNHvG5KNUx/4IydE/l4KY3QQy5TNH3wrC1N9nos=; b=EdihQEpP6Gzu6ufqo+EQrMkThpqOFmEFYErLs/s3K0KrhV8TJsaVEDuGlwW0YHnrni AC4o15A4BX/+0PZ8UI672ork8L0tdMxxgMV9WEJ4nXD2MvB5FUV6nDWffYQj/IygflYw YB2YfLorl8snVClnXBaDm3y7DSRfC89J7GjoF1Hxj6+AbH618vH30cCn0pSvo8cfBzA0 9nwu4QfPQZ7UtGXlukW56XjJjkJWiRJBAFMX00648iY5xfMf/6DjZheaDd36uG+gL7FF 8uiO6ZsjbI30pIHFR6Ju/1qYuRc2vOdVZb+Kq57F5uUXpz2rdFK3d6MuzctST27gZVfP LzYQ== X-Gm-Message-State: AOJu0YwO15aX/Xth0S6/ZoYG7adJFOThInQon467UTtJuQFcZ+62ObOC LcN60ucHSFxFDWe+GlPF0LqApZj+f73PYNvxqPiKp2XknNtjKQcRh+c7+HizvVv6w2jYEapEXSJ 2Rg== X-Google-Smtp-Source: AGHT+IH9a0Rp2kbXCzu6xOHT+uEzhNCnn8gfGcW1brCjZ22NIHwtCRsGc3b2sogK9iziISmY9hnQHXAsZt4= X-Received: from pjwx12.prod.google.com ([2002:a17:90a:c2cc:b0:2fc:2c9c:880]) (user=pandoh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4b02:b0:2ff:5016:7fd2 with SMTP id 98e67ed59e1d1-301be1f8cc0mr3277154a91.24.1742373671971; Wed, 19 Mar 2025 01:41:11 -0700 (PDT) Date: Wed, 19 Mar 2025 01:40:44 -0700 In-Reply-To: <20250319084050.366718-1-pandoh@google.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319084050.366718-1-pandoh@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Message-ID: <20250319084050.366718-4-pandoh@google.com> Subject: [PATCH v3 3/8] PCI/AER: Move AER stat collection out of __aer_print_error() From: Jon Pan-Doh To: Bjorn Helgaas , Karolina Stolarek Cc: linux-pci@vger.kernel.org, Martin Petersen , Ben Fuller , Drew Walton , Anil Agrawal , Tony Luck , " =?utf-8?q?Ilpo_J=C3=A4rvinen?= " , Sathyanarayanan Kuppuswamy , Lukas Wunner , Jonathan Cameron , Terry Bowman , Jon Pan-Doh Decouple stat collection from internal AER print functions. AERs from ghes or cxl drivers have stat collection in pci_print_aer() as that is where aer_err_info is populated. Signed-off-by: Jon Pan-Doh --- drivers/pci/pci.h | 1 + drivers/pci/pcie/aer.c | 10 ++++++---- drivers/pci/pcie/dpc.c | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 75985b96ecc1..9d63d32f041c 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -551,6 +551,7 @@ struct aer_err_info { }; int aer_get_device_error_info(struct pci_dev *dev, struct aer_err_info *info); +void pci_dev_aer_stats_incr(struct pci_dev *pdev, struct aer_err_info *info); void aer_print_error(struct pci_dev *dev, struct aer_err_info *info, const char *level); int pcie_read_tlp_log(struct pci_dev *dev, int where, int where2, diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index 7eeaad917134..8e4d4f9326e1 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -617,8 +617,7 @@ const struct attribute_group aer_stats_attr_group = { .is_visible = aer_stats_attrs_are_visible, }; -static void pci_dev_aer_stats_incr(struct pci_dev *pdev, - struct aer_err_info *info) +void pci_dev_aer_stats_incr(struct pci_dev *pdev, struct aer_err_info *info) { unsigned long status = info->status & ~info->mask; int i, max = -1; @@ -691,7 +690,6 @@ static void __aer_print_error(struct pci_dev *dev, aer_printk(level, dev, " [%2d] %-22s%s\n", i, errmsg, info->first_error == i ? " (First)" : ""); } - pci_dev_aer_stats_incr(dev, info); } void aer_print_error(struct pci_dev *dev, struct aer_err_info *info, @@ -784,6 +782,8 @@ void pci_print_aer(struct pci_dev *dev, int aer_severity, info.mask = mask; info.first_error = PCI_ERR_CAP_FEP(aer->cap_control); + pci_dev_aer_stats_incr(dev, &info); + aer_printk(level, dev, "aer_status: 0x%08x, aer_mask: 0x%08x\n", status, mask); __aer_print_error(dev, &info, level); aer_printk(level, dev, "aer_layer=%s, aer_agent=%s\n", @@ -1263,8 +1263,10 @@ static inline void aer_process_err_devices(struct aer_err_info *e_info, /* Report all before handle them, not to lost records by reset etc. */ for (i = 0; i < e_info->error_dev_num && e_info->dev[i]; i++) { - if (aer_get_device_error_info(e_info->dev[i], e_info)) + if (aer_get_device_error_info(e_info->dev[i], e_info)) { + pci_dev_aer_stats_incr(e_info->dev[i], e_info); aer_print_error(e_info->dev[i], e_info, level); + } } for (i = 0; i < e_info->error_dev_num && e_info->dev[i]; i++) { if (aer_get_device_error_info(e_info->dev[i], e_info)) diff --git a/drivers/pci/pcie/dpc.c b/drivers/pci/pcie/dpc.c index 9e4c9ac737a7..81cd6e8ff3a4 100644 --- a/drivers/pci/pcie/dpc.c +++ b/drivers/pci/pcie/dpc.c @@ -289,6 +289,7 @@ void dpc_process_error(struct pci_dev *pdev) else if (reason == PCI_EXP_DPC_STATUS_TRIGGER_RSN_UNCOR && dpc_get_aer_uncorrect_severity(pdev, &info) && aer_get_device_error_info(pdev, &info)) { + pci_dev_aer_stats_incr(pdev, &info); aer_print_error(pdev, &info, KERN_ERR); pci_aer_clear_nonfatal_status(pdev); pci_aer_clear_fatal_status(pdev); From patchwork Wed Mar 19 08:40:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Pan-Doh X-Patchwork-Id: 14022276 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9EDE15A85A for ; Wed, 19 Mar 2025 08:41:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742373678; cv=none; b=GpBo/tBAViZXgDPgw+QHgwjeRxUIyVibtlSUBE+489saspGNtMooQ+RIhPJqs1BHg9mJ7kPQLLsAut2uM+5k47HY/PN0x8sQlSbNeKKk7awwukrtrqL6pF/OXtyFBZgn/Ioj3VykWJy3EKZP+oxbjVM2IvNj1K3u3LMFLtjAWac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742373678; c=relaxed/simple; bh=D52k/V2+ySBp35k3r/sRpXOjOyawcpoPAzRXcEaRxTA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rfgHQpXqT6oINM856GEffjEi9FWjTTaIn1SbXNXRU/HlPWnKIua5tkJRxX4IzjJynF+vZf9DEBFDRyZhShZY2ImYPsFnrML2bgtSnpljgZNNSApbewKOC5wspeRfmZpPAORGTZGiyF1d0Vi/Xi1Z3mPJL0VPel4SxHuThUSDE7g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--pandoh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NK9BOLlk; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--pandoh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NK9BOLlk" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2241ae15dcbso145307965ad.0 for ; Wed, 19 Mar 2025 01:41:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742373675; x=1742978475; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ylRFZdS+00GELz/E0NJuN4dLw4/VfSWwgK2tlYwfNAQ=; b=NK9BOLlkNgpgdk3B3AA0wX+jWKJNJn3y00WYhFo7ZsGCtpDhi99NzcAE9qf9dX8nal R9vE/pY472QMa23H+XZD+E9x44kKbbpZWcotN0rPEYgISQwVmsiWvmqqo5ObLWYtZFND K1VzaKKxtldasEWuiGP1D5FHyJIaYGBv28rKumUVJkbtL9AebTUI120kzut9Q+qI2uSa Ad7zWSR7vIVCT/gLMjtvAzpXnx7fhwaj4BaFf0DpX4Dp4GfXEloLPY/0nvIwiKHzWRUj GDbEYYhWAS3RNQyp1PiwqDdOmL1tKFpWzam0YTJc3RCIPa1Vfd4NRLfMn2vJI9c1QQdO nFsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742373675; x=1742978475; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ylRFZdS+00GELz/E0NJuN4dLw4/VfSWwgK2tlYwfNAQ=; b=UblEbAJK7olrKUNQLuoj0JWsMOmekf5cWWTAZ4mf5MteTcXiO3Y0a0O/0zIh/oFumz xtnwJJott8i4GrknOPxyl8VlpdZ6h2Gs5aElOBhwGsVVz+ojLURP6aXG9mr6Zz3r/UnQ Dypo8nKRWESAK48xXf04wjr4GjNGNYGXYbvuCFRD49cMk25j1Yp1TOUz5bE+2RKq33Kb 2cyr+QObpHkPN76xMZUmMdoxXTG2e0GK81Bh1jbVBWINxLS9dvK10MRxA7NyRtb+ZkPL oUh8B+fOsG7ot+NthNEh5hoZszRX71ECCFLbOZVLJngIa1cS9s3tvjJaOSWvJMjeVO3E sNzA== X-Gm-Message-State: AOJu0Yzalb/eNl64A9FZIWgu5PcTnQk/fgZ9DzxVVxnU/yIyJ+Bg7ju+ vtVdiU680zVko9UhFHG7lONleOiOsT+aLBLASoUBnmMXx3H8G8ffRHwUd2nIxmnMsV9KwGs7282 q7A== X-Google-Smtp-Source: AGHT+IGEKT1sevi4fpK2NcNRqNySKuy0ss1KXf2MvZO+d1ckoTJCmGWl7S+vPpPHNdqiBNKiU3uFw0XnctA= X-Received: from pfbna11.prod.google.com ([2002:a05:6a00:3e0b:b0:730:4672:64ac]) (user=pandoh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3d4a:b0:736:a77d:5412 with SMTP id d2e1a72fcca58-7376d633ae0mr2718307b3a.12.1742373675149; Wed, 19 Mar 2025 01:41:15 -0700 (PDT) Date: Wed, 19 Mar 2025 01:40:45 -0700 In-Reply-To: <20250319084050.366718-1-pandoh@google.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319084050.366718-1-pandoh@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Message-ID: <20250319084050.366718-5-pandoh@google.com> Subject: [PATCH v3 4/8] PCI/AER: Rename struct aer_stats to aer_report From: Jon Pan-Doh To: Bjorn Helgaas , Karolina Stolarek Cc: linux-pci@vger.kernel.org, Martin Petersen , Ben Fuller , Drew Walton , Anil Agrawal , Tony Luck , " =?utf-8?q?Ilpo_J=C3=A4rvinen?= " , Sathyanarayanan Kuppuswamy , Lukas Wunner , Jonathan Cameron , Terry Bowman , Jon Pan-Doh Update name to reflect the broader definition of structs/variables that are stored (e.g. ratelimits). Signed-off-by: Karolina Stolarek Signed-off-by: Jon Pan-Doh Reviewed-by: Karolina Stolarek --- drivers/pci/pcie/aer.c | 50 +++++++++++++++++++++--------------------- include/linux/pci.h | 2 +- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index 8e4d4f9326e1..3a12980f7dd7 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -54,11 +54,11 @@ struct aer_rpc { DECLARE_KFIFO(aer_fifo, struct aer_err_source, AER_ERROR_SOURCES_MAX); }; -/* AER stats for the device */ -struct aer_stats { +/* AER report for the device */ +struct aer_report { /* - * Fields for all AER capable devices. They indicate the errors + * Stats for all AER capable devices. They indicate the errors * "as seen by this device". Note that this may mean that if an * end point is causing problems, the AER counters may increment * at its link partner (e.g. root port) because the errors will be @@ -80,7 +80,7 @@ struct aer_stats { u64 dev_total_nonfatal_errs; /* - * Fields for Root ports & root complex event collectors only, these + * Stats for Root ports & root complex event collectors only, these * indicate the total number of ERR_COR, ERR_FATAL, and ERR_NONFATAL * messages received by the root port / event collector, INCLUDING the * ones that are generated internally (by the rootport itself) @@ -377,7 +377,7 @@ void pci_aer_init(struct pci_dev *dev) if (!dev->aer_cap) return; - dev->aer_stats = kzalloc(sizeof(struct aer_stats), GFP_KERNEL); + dev->aer_report = kzalloc(sizeof(*dev->aer_report), GFP_KERNEL); /* * We save/restore PCI_ERR_UNCOR_MASK, PCI_ERR_UNCOR_SEVER, @@ -398,8 +398,8 @@ void pci_aer_init(struct pci_dev *dev) void pci_aer_exit(struct pci_dev *dev) { - kfree(dev->aer_stats); - dev->aer_stats = NULL; + kfree(dev->aer_report); + dev->aer_report = NULL; } #define AER_AGENT_RECEIVER 0 @@ -537,10 +537,10 @@ static const char *aer_agent_string[] = { { \ unsigned int i; \ struct pci_dev *pdev = to_pci_dev(dev); \ - u64 *stats = pdev->aer_stats->stats_array; \ + u64 *stats = pdev->aer_report->stats_array; \ size_t len = 0; \ \ - for (i = 0; i < ARRAY_SIZE(pdev->aer_stats->stats_array); i++) {\ + for (i = 0; i < ARRAY_SIZE(pdev->aer_report->stats_array); i++) {\ if (strings_array[i]) \ len += sysfs_emit_at(buf, len, "%s %llu\n", \ strings_array[i], \ @@ -551,7 +551,7 @@ static const char *aer_agent_string[] = { i, stats[i]); \ } \ len += sysfs_emit_at(buf, len, "TOTAL_%s %llu\n", total_string, \ - pdev->aer_stats->total_field); \ + pdev->aer_report->total_field); \ return len; \ } \ static DEVICE_ATTR_RO(name) @@ -572,7 +572,7 @@ aer_stats_dev_attr(aer_dev_nonfatal, dev_nonfatal_errs, char *buf) \ { \ struct pci_dev *pdev = to_pci_dev(dev); \ - return sysfs_emit(buf, "%llu\n", pdev->aer_stats->field); \ + return sysfs_emit(buf, "%llu\n", pdev->aer_report->field); \ } \ static DEVICE_ATTR_RO(name) @@ -599,7 +599,7 @@ static umode_t aer_stats_attrs_are_visible(struct kobject *kobj, struct device *dev = kobj_to_dev(kobj); struct pci_dev *pdev = to_pci_dev(dev); - if (!pdev->aer_stats) + if (!pdev->aer_report) return 0; if ((a == &dev_attr_aer_rootport_total_err_cor.attr || @@ -622,25 +622,25 @@ void pci_dev_aer_stats_incr(struct pci_dev *pdev, struct aer_err_info *info) unsigned long status = info->status & ~info->mask; int i, max = -1; u64 *counter = NULL; - struct aer_stats *aer_stats = pdev->aer_stats; + struct aer_report *aer_report = pdev->aer_report; - if (!aer_stats) + if (!aer_report) return; switch (info->severity) { case AER_CORRECTABLE: - aer_stats->dev_total_cor_errs++; - counter = &aer_stats->dev_cor_errs[0]; + aer_report->dev_total_cor_errs++; + counter = &aer_report->dev_cor_errs[0]; max = AER_MAX_TYPEOF_COR_ERRS; break; case AER_NONFATAL: - aer_stats->dev_total_nonfatal_errs++; - counter = &aer_stats->dev_nonfatal_errs[0]; + aer_report->dev_total_nonfatal_errs++; + counter = &aer_report->dev_nonfatal_errs[0]; max = AER_MAX_TYPEOF_UNCOR_ERRS; break; case AER_FATAL: - aer_stats->dev_total_fatal_errs++; - counter = &aer_stats->dev_fatal_errs[0]; + aer_report->dev_total_fatal_errs++; + counter = &aer_report->dev_fatal_errs[0]; max = AER_MAX_TYPEOF_UNCOR_ERRS; break; } @@ -652,19 +652,19 @@ void pci_dev_aer_stats_incr(struct pci_dev *pdev, struct aer_err_info *info) static void pci_rootport_aer_stats_incr(struct pci_dev *pdev, struct aer_err_source *e_src) { - struct aer_stats *aer_stats = pdev->aer_stats; + struct aer_report *aer_report = pdev->aer_report; - if (!aer_stats) + if (!aer_report) return; if (e_src->status & PCI_ERR_ROOT_COR_RCV) - aer_stats->rootport_total_cor_errs++; + aer_report->rootport_total_cor_errs++; if (e_src->status & PCI_ERR_ROOT_UNCOR_RCV) { if (e_src->status & PCI_ERR_ROOT_FATAL_RCV) - aer_stats->rootport_total_fatal_errs++; + aer_report->rootport_total_fatal_errs++; else - aer_stats->rootport_total_nonfatal_errs++; + aer_report->rootport_total_nonfatal_errs++; } } diff --git a/include/linux/pci.h b/include/linux/pci.h index e4bf67bf8172..900edb6f8f62 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -346,7 +346,7 @@ struct pci_dev { u8 hdr_type; /* PCI header type (`multi' flag masked out) */ #ifdef CONFIG_PCIEAER u16 aer_cap; /* AER capability offset */ - struct aer_stats *aer_stats; /* AER stats for this device */ + struct aer_report *aer_report; /* AER report for this device */ #endif #ifdef CONFIG_PCIEPORTBUS struct rcec_ea *rcec_ea; /* RCEC cached endpoint association */ From patchwork Wed Mar 19 08:40:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Pan-Doh X-Patchwork-Id: 14022277 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E98E2512CA for ; Wed, 19 Mar 2025 08:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742373679; cv=none; b=YACYsZzKME8pw68fcG6iL399wr4y5HFEP5VLA8+bPS8f174EaqGksc04bhpq9saH2XJt6KToXE1WK8KrqDNQKMtE8qs58TgWmBbDWlpEVtQra+7rqfPRnpizcG44e0RTiUYjW4q3vT8qANvNulqIjXLokgR+rVflbalUGS4CiYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742373679; c=relaxed/simple; bh=4BqYa0/0oXdc6SPaifaRtyqnxny/BmNJJ7mbfCOVHP0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ae0ZcCNVkTyMVqF8iAhHGTIw2zjGXkFXMdm7uFD0Q6i3TrezeF3PRlCWo21S/KQUvkOvyaNl95MfvkzkCH8ix6MdEt6DW7RMS5Z/v05eUKm25IFLzxhKTNpu2CUlNxdJ+ll+OIAxfX+SrhN++Ou4Xp5DhHuFWR7maDeErYENME8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--pandoh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ouQFgVTM; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--pandoh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ouQFgVTM" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ff78bd3026so6659640a91.1 for ; Wed, 19 Mar 2025 01:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742373677; x=1742978477; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sLzk6ISOkNU8YIV8p78bs7GVSG1SmH6Q9dWTWI4n6qA=; b=ouQFgVTMCn3u7Uzb3Or/xhYemx6BGmwQlcTo6VOlD3u4tbiGHh6VcBjnAhm07yC4OX iLayZIrmdZk5hqsDQstnf6eBq/WxBx+QvpE2L0S84+Smnu5DownTf+cOZu5Ik83O7KbQ SySuz/tAeacCag1a1hhkq44vAaRaNvGaRBLtPo2Xj0Mq6jsH4DwcSqmriMXQLGhNV8vS s6BdpvTfXkrzg9QJMy/IJT4edt1qOruwBAjIiYh/vJgs+wJKVrDpi2wj4wJqBmBqnljb E+3eXsTiUhwoR8pyjpTzhFbDUTLfCzhxtwWEKjQ/tRPxgQppO1i1mF/801V0rPBj8VZW bbuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742373677; x=1742978477; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sLzk6ISOkNU8YIV8p78bs7GVSG1SmH6Q9dWTWI4n6qA=; b=I4hz6kvQe86ZKcGTvc7TO0LSDA9OgLB3/MoVkQti27Y9OzXrHfYao8wWoM9GOkS3vh MQk4ojTT3vG82aQi8+8DEh2YDIx6HB7C7ZlOuveU6+ju25UD1QsTyZTpFz7Y2was5mna e0uPebPKi54gTMOH2PssHAtFQJA7w8UOLqROpka5yAGzbw/a3el2tMmh84oAdoTMfMRd IPXTp1eDsX09nA/Ls8pvSo1N6StNQX5RvggQ1a5CVu1PHVTsW7f7s3MYkt5VipyspUXv FP2NZQHBRS9j3wTQDgrmqRA4KSi5KOdICD9CX869TCeMhNvhuMTDFdMxWJwLGflC6qiK QRPQ== X-Gm-Message-State: AOJu0Ywr9ndxOZemkpoBKgJJ8iGYkr9MjRjTQ40o/2FGL5xqfCOa0+wm cVexJBKeTmhammFLfRjyvopQMNxQzhE36UxrSffphMjbgm7mLsNUl3rtQHnCrxdBd3hHCIWeCNN tJg== X-Google-Smtp-Source: AGHT+IFGOiJdDZA3OIo7vckkOXp5z6xoBNcsDNMWbpjR4pKJdk5V2KFe13GjIjaTSAOxnI+19EGml+ryRpc= X-Received: from pjbnd6.prod.google.com ([2002:a17:90b:4cc6:b0:2ea:aa56:49c]) (user=pandoh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:ec8f:b0:2ee:d433:7c50 with SMTP id 98e67ed59e1d1-301be1fff3bmr2512307a91.23.1742373677720; Wed, 19 Mar 2025 01:41:17 -0700 (PDT) Date: Wed, 19 Mar 2025 01:40:46 -0700 In-Reply-To: <20250319084050.366718-1-pandoh@google.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319084050.366718-1-pandoh@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Message-ID: <20250319084050.366718-6-pandoh@google.com> Subject: [PATCH v3 5/8] PCI/AER: Introduce ratelimit for error logs From: Jon Pan-Doh To: Bjorn Helgaas , Karolina Stolarek Cc: linux-pci@vger.kernel.org, Martin Petersen , Ben Fuller , Drew Walton , Anil Agrawal , Tony Luck , " =?utf-8?q?Ilpo_J=C3=A4rvinen?= " , Sathyanarayanan Kuppuswamy , Lukas Wunner , Jonathan Cameron , Terry Bowman , Jon Pan-Doh Spammy devices can flood kernel logs with AER errors and slow/stall execution. Add per-device ratelimits for AER correctable and uncorrectable errors that use the kernel defaults (10 per 5s). Tested using aer-inject[1]. Sent 11 AER errors. Observed 10 errors logged while AER stats (cat /sys/bus/pci/devices//aer_dev_correctable) show true count of 11. [1] https://git.kernel.org/pub/scm/linux/kernel/git/gong.chen/aer-inject.git Signed-off-by: Jon Pan-Doh Reviewed-by: Karolina Stolarek --- drivers/pci/pcie/aer.c | 76 +++++++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 15 deletions(-) diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index 3a12980f7dd7..0bd20c4993d4 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -88,6 +89,10 @@ struct aer_report { u64 rootport_total_cor_errs; u64 rootport_total_fatal_errs; u64 rootport_total_nonfatal_errs; + + /* Ratelimits for errors */ + struct ratelimit_state cor_log_ratelimit; + struct ratelimit_state uncor_log_ratelimit; }; #define AER_LOG_TLP_MASKS (PCI_ERR_UNC_POISON_TLP| \ @@ -379,6 +384,15 @@ void pci_aer_init(struct pci_dev *dev) dev->aer_report = kzalloc(sizeof(*dev->aer_report), GFP_KERNEL); + /* + * Ratelimits are doubled as a given error produces 2 logs (root port + * and endpoint) that should be under same ratelimit. + */ + ratelimit_state_init(&dev->aer_report->cor_log_ratelimit, + DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST * 2); + ratelimit_state_init(&dev->aer_report->uncor_log_ratelimit, + DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST * 2); + /* * We save/restore PCI_ERR_UNCOR_MASK, PCI_ERR_UNCOR_SEVER, * PCI_ERR_COR_MASK, and PCI_ERR_CAP. Root and Root Complex Event @@ -697,6 +711,7 @@ void aer_print_error(struct pci_dev *dev, struct aer_err_info *info, { int layer, agent; int id = pci_dev_id(dev); + struct ratelimit_state *ratelimit; if (!info->status) { pci_err(dev, "PCIe Bus Error: severity=%s, type=Inaccessible, (Unregistered Agent ID)\n", @@ -704,6 +719,17 @@ void aer_print_error(struct pci_dev *dev, struct aer_err_info *info, goto out; } + if (info->severity == AER_CORRECTABLE) + ratelimit = &dev->aer_report->cor_log_ratelimit; + else + ratelimit = &dev->aer_report->uncor_log_ratelimit; + + trace_aer_event(dev_name(&dev->dev), (info->status & ~info->mask), + info->severity, info->tlp_header_valid, &info->tlp); + + if (!__ratelimit(ratelimit)) + return; + layer = AER_GET_LAYER_ERROR(info->severity, info->status); agent = AER_GET_AGENT(info->severity, info->status); @@ -722,21 +748,33 @@ void aer_print_error(struct pci_dev *dev, struct aer_err_info *info, out: if (info->id && info->error_dev_num > 1 && info->id == id) pci_err(dev, " Error of this Agent is reported first\n"); - - trace_aer_event(dev_name(&dev->dev), (info->status & ~info->mask), - info->severity, info->tlp_header_valid, &info->tlp); } static void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info) { u8 bus = info->id >> 8; u8 devfn = info->id & 0xff; + struct ratelimit_state *ratelimit; + struct pci_dev *endpoint; + int i; - pci_info(dev, "%s%s error message received from %04x:%02x:%02x.%d\n", - info->multi_error_valid ? "Multiple " : "", - aer_error_severity_string[info->severity], - pci_domain_nr(dev->bus), bus, PCI_SLOT(devfn), - PCI_FUNC(devfn)); + /* extract endpoint device ratelimit */ + for (i = 0; i < info->error_dev_num; i++) { + endpoint = info->dev[i]; + if (info->id == pci_dev_id(endpoint)) + break; + } + if (info->severity == AER_CORRECTABLE) + ratelimit = &endpoint->aer_report->cor_log_ratelimit; + else + ratelimit = &endpoint->aer_report->uncor_log_ratelimit; + + if (__ratelimit(ratelimit)) + pci_info(dev, "%s%s error message received from %04x:%02x:%02x.%d\n", + info->multi_error_valid ? "Multiple " : "", + aer_error_severity_string[info->severity], + pci_domain_nr(dev->bus), bus, PCI_SLOT(devfn), + PCI_FUNC(devfn)); } #ifdef CONFIG_ACPI_APEI_PCIEAER @@ -761,12 +799,15 @@ void pci_print_aer(struct pci_dev *dev, int aer_severity, u32 status, mask; const char *level; struct aer_err_info info; + struct ratelimit_state *ratelimit; if (aer_severity == AER_CORRECTABLE) { + ratelimit = &dev->aer_report->cor_log_ratelimit; status = aer->cor_status; mask = aer->cor_mask; level = KERN_WARNING; } else { + ratelimit = &dev->aer_report->uncor_log_ratelimit; status = aer->uncor_status; mask = aer->uncor_mask; tlp_header_valid = status & AER_LOG_TLP_MASKS; @@ -784,6 +825,12 @@ void pci_print_aer(struct pci_dev *dev, int aer_severity, pci_dev_aer_stats_incr(dev, &info); + trace_aer_event(dev_name(&dev->dev), (status & ~mask), + aer_severity, tlp_header_valid, &aer->header_log); + + if (!__ratelimit(ratelimit)) + return; + aer_printk(level, dev, "aer_status: 0x%08x, aer_mask: 0x%08x\n", status, mask); __aer_print_error(dev, &info, level); aer_printk(level, dev, "aer_layer=%s, aer_agent=%s\n", @@ -795,9 +842,6 @@ void pci_print_aer(struct pci_dev *dev, int aer_severity, if (tlp_header_valid) pcie_print_tlp_log(dev, &aer->header_log, dev_fmt(" ")); - - trace_aer_event(dev_name(&dev->dev), (status & ~mask), - aer_severity, tlp_header_valid, &aer->header_log); } EXPORT_SYMBOL_NS_GPL(pci_print_aer, "CXL"); @@ -1301,10 +1345,11 @@ static void aer_isr_one_error(struct aer_rpc *rpc, e_info.multi_error_valid = 1; else e_info.multi_error_valid = 0; - aer_print_port_info(pdev, &e_info); - if (find_source_device(pdev, &e_info)) + if (find_source_device(pdev, &e_info)) { + aer_print_port_info(pdev, &e_info); aer_process_err_devices(&e_info, level); + } } if (e_src->status & PCI_ERR_ROOT_UNCOR_RCV) { @@ -1321,10 +1366,11 @@ static void aer_isr_one_error(struct aer_rpc *rpc, else e_info.multi_error_valid = 0; - aer_print_port_info(pdev, &e_info); - if (find_source_device(pdev, &e_info)) + if (find_source_device(pdev, &e_info)) { + aer_print_port_info(pdev, &e_info); aer_process_err_devices(&e_info, level); + } } } From patchwork Wed Mar 19 08:40:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Pan-Doh X-Patchwork-Id: 14022278 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA1F92512CA for ; Wed, 19 Mar 2025 08:41:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742373683; cv=none; b=hDr7A28xz7JHvz3iJLuVyuZYZQkVfL4z92wTziMQgzv9Uxc8UF/pswCyW3tl66zkaKLX0DK5PyoYL8Xz84hfhCV3pmNX58Z1bQ5isaYoqF1UZ653nzaQjNypr1RBsgao1oAldLTtU4w767LfX8IzX5ZeBW9b1ucZwaYr+lIdYJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742373683; c=relaxed/simple; bh=yoUiQSYGpSGekAoG2O4E8f17ta3m6ARia8UOtVAr6JI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=I6f02U/KqbMVIJUudqRuP/Hc6iE/UuWbt87bqiUI5DzIXLcQGIW4JmvKiR0JSUH74zChr//TGSTUYfoef+T4qoqrD3TQc7Ht+r+82nwWP4YS3NsLFfR+DFfs7pXEsC1w+GiUi1jkr91vJyVqIOT2o1faAwe+EIDb/wytHXnLEmY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--pandoh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wihvgUXP; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--pandoh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wihvgUXP" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ff7cf599beso9829703a91.0 for ; Wed, 19 Mar 2025 01:41:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742373681; x=1742978481; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Pqyah9gjao8rMiwTqNmziiGpp43wpvz0+2z6DdoovpM=; b=wihvgUXPjjnWu2BMZ1ZQtQGjjk2wnpumw9ZLBUNx8gI05D71ERRB9C/LBl8tKVhq/w 8no4nsVY//+/o7VCPUNIw35Jvpq4334HKXQWxTlo8F3YGOvF1qext81VviUH6mQakG2E YmolBuQ8ECgWgx9dFmP2F3zCyVs3mptc0P3vekmNIRuek4hd4lz6RMKxLpNRhZLSX5Ve mH/iuQq/Cots5D+eJoPosE+ZkSvQeCciKxZDgxdesLkMuCz7fD7Z8gCZ+QuMOfuliYG9 +K67AV56yIuilGQKENpZiOuDBoHAMocQlEbso/q8mkj2OMWlbPjpLr5JNZ+c6vk/BNEX GZCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742373681; x=1742978481; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Pqyah9gjao8rMiwTqNmziiGpp43wpvz0+2z6DdoovpM=; b=khckQaUaMFweBIlo+F5mjIGkSckajMIzoz3wt7Rb2UaG2KSzLE5V57BLSGXMaB12bl aV2NAQfMe08z2C+2ei80S2R/HyKtRBdF3fNN7E8K0x8QEJ1XUzx/JqmukdyFew6gj8tp 24pP3sLkiFXfI717ZHLjSUCegtD4jTa7Kl/1c0orJijQ4oTu/Qnx3p/u9Uw34OlQ6znl EAzOqNp6k1i0Lf04casnt5as/aGgqtjwdubcltk5Hkwl8mdLRcO5vCNKVm2379OZjQjC cK8pp09xdwXn5brSjz2+wuARH8zc/QM1kmVs2RRyu0DgzJoEsv3fwhkjoIG9WAw2HOgA nKWA== X-Gm-Message-State: AOJu0Yzz3nNIfPgcoG0D5dB09EvTyMdx+IrwADaCM2j/9KIEyiWftVph Je26SkbcURqdtgYsr+kz0scRnwlNq0cyNFmDIUdn+owUzhdo8CgmD/pyZthZLZcD3/bbTiqYFlC JRw== X-Google-Smtp-Source: AGHT+IEHDNjxg+Ne8KvSr5xhxzIPz/jxzhh1ftjlAiACeDyNjb2JUvc0aF+MknYSfBxTHb8uVrjYcIwRFak= X-Received: from pgcp23.prod.google.com ([2002:a63:7417:0:b0:af5:fb05:d856]) (user=pandoh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:2d26:b0:1f3:32c1:cc5d with SMTP id adf61e73a8af0-1fbeba90c16mr3302848637.21.1742373681021; Wed, 19 Mar 2025 01:41:21 -0700 (PDT) Date: Wed, 19 Mar 2025 01:40:47 -0700 In-Reply-To: <20250319084050.366718-1-pandoh@google.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319084050.366718-1-pandoh@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Message-ID: <20250319084050.366718-7-pandoh@google.com> Subject: [PATCH v3 6/8] PCI/AER: Add ratelimits to PCI AER Documentation From: Jon Pan-Doh To: Bjorn Helgaas , Karolina Stolarek Cc: linux-pci@vger.kernel.org, Martin Petersen , Ben Fuller , Drew Walton , Anil Agrawal , Tony Luck , " =?utf-8?q?Ilpo_J=C3=A4rvinen?= " , Sathyanarayanan Kuppuswamy , Lukas Wunner , Jonathan Cameron , Terry Bowman , Jon Pan-Doh Add ratelimits section for rationale and defaults. Signed-off-by: Karolina Stolarek Signed-off-by: Jon Pan-Doh --- Documentation/PCI/pcieaer-howto.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/PCI/pcieaer-howto.rst b/Documentation/PCI/pcieaer-howto.rst index f013f3b27c82..896d2a232a90 100644 --- a/Documentation/PCI/pcieaer-howto.rst +++ b/Documentation/PCI/pcieaer-howto.rst @@ -85,6 +85,17 @@ In the example, 'Requester ID' means the ID of the device that sent the error message to the Root Port. Please refer to PCIe specs for other fields. +AER Ratelimits +-------------- + +Since error messages can be generated for each transaction, we may see +large volumes of errors reported. To prevent spammy devices from flooding +the console/stalling execution, messages are throttled by device and error +type (correctable vs. uncorrectable). + +AER uses the default ratelimit of DEFAULT_RATELIMIT_BURST (10 events) over +DEFAULT_RATELIMIT_INTERVAL (5 seconds). + AER Statistics / Counters ------------------------- From patchwork Wed Mar 19 08:40:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Pan-Doh X-Patchwork-Id: 14022279 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6986E2512CA for ; Wed, 19 Mar 2025 08:41:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742373686; cv=none; b=TYZ/q0dkMnk5QMsWfmvfx+CK+IG/Uq8kC4bqqXKxB3xXT3lkvms4+SuhUAsfU6KPb4Nkd7wB1efY3zQ/MIOkjIiZ3M1OQYgykyIedzmGkEuBBKr3YC2ItXpSJKHhyLeXPXLOlCBjNBUhe7VSKPlfYIW5w6Swn2whsivOzgD/06U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742373686; c=relaxed/simple; bh=TeZWUSpOCB32n9u2riK5ylRB52pVDGMKNkNlCeSVlKg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=t7hmiEK3ilPDit6TU+geQLWGZ5v34dpGheI8fUDFll/SNjNzAk1Up8Nr1Wzy74w0U55t5Siw/Koikl6SxOIvgXGvL27Hcn+KQqW/Thw+8WwjsMrFSEZ+thNWqX/Zhj/rfdhjq6zW93lXMEueJ3a9HbI10CZWVDXp2IujcmO5beQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--pandoh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=P+/SJRPX; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--pandoh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="P+/SJRPX" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ff7cf599beso9829798a91.0 for ; Wed, 19 Mar 2025 01:41:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742373683; x=1742978483; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6nCretJnBS2nY1fAHRYQJG5aABzBDIWxITv1PzKj408=; b=P+/SJRPXsmDwNiwI4Yvd10OhTcUMCQSCdCtfj42REK9dsdWrxJctCyERkT8OWjBOtF Noz+iOf0JgxHdN8DHeYIPDwHMQp2eaMZ7yDT6Vw3xIrjlqPTsmFmphSxAP+qkz+IQ5aA /Lu9sK9C0pqlrnbIw6dQUi3T802T5tB+ctPHaeM+Usos8rqcxN44ekfGVXtVHkOYpfne 4DrnQSLsIIqffCZM3BlDxSmAalnCb/lqr6ywgXOEIcmDhlgRPd4HgwxgjkXGJM5RNC5Y hhAQlCS6sQ5N8ezhW1N3LGRmBB4iKL08TbxhRGnqM6v+4hO3uWGC7aisJD8Vx79ixBOe 5D8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742373683; x=1742978483; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6nCretJnBS2nY1fAHRYQJG5aABzBDIWxITv1PzKj408=; b=tjX6REdv9mp3yUkR/6KJmbcAzFpUgyHqGVlep+hvDhsHSFGIRkJ91gpxrxRBCxwo2I KO07GFrUF1lvCjff3zeOmatxKNp00/tlWnxGjL/n898G5zF0ovEGA34wQ+Nd3mxo1G/+ Wg/YoBM70ivUhEdmpQp5hVPzRkYiX+dhmYRi98tpZDstlHVLPMNSoeeCIlv1BCHuSRdb kFeRS24HmDeyEZJsWPYzLXQMQoXg+eTbjr94fKpzCHmR69CFAvyYqGLI7rk48lcWawEw G01scEOBk/kDW5k3QcW66qkb3SXaW0fUSMwXicV1ao1UsoivH9FaH/bfjaRX11WbmhVo GFOQ== X-Gm-Message-State: AOJu0Yw3hBj5i1y6TmtVg+Ew0Vb/fKZ2lUE0TunT+vQZOZDEMLEnL6JB zNraVytITaKWF7XWAVCybPwkIX/MHMjaK5zCl/3JohN0TZ6JHZX0JOX+ED+/Rij2BwacbVTtRjX /9w== X-Google-Smtp-Source: AGHT+IHwiKQl2w0+23EJxQRXLKrhn47bFKCcSOG31ydtjbQtLc987QyphmoyXLRf3p/hjzwCjGEmU23AtmI= X-Received: from pgbcp13.prod.google.com ([2002:a05:6a02:400d:b0:af5:6a6:3cfd]) (user=pandoh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:594:b0:1f5:7b6f:f8e8 with SMTP id adf61e73a8af0-1fbeae9141bmr3327172637.6.1742373683624; Wed, 19 Mar 2025 01:41:23 -0700 (PDT) Date: Wed, 19 Mar 2025 01:40:48 -0700 In-Reply-To: <20250319084050.366718-1-pandoh@google.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319084050.366718-1-pandoh@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Message-ID: <20250319084050.366718-8-pandoh@google.com> Subject: [PATCH v3 7/8] PCI/AER: Add sysfs attributes for log ratelimits From: Jon Pan-Doh To: Bjorn Helgaas , Karolina Stolarek Cc: linux-pci@vger.kernel.org, Martin Petersen , Ben Fuller , Drew Walton , Anil Agrawal , Tony Luck , " =?utf-8?q?Ilpo_J=C3=A4rvinen?= " , Sathyanarayanan Kuppuswamy , Lukas Wunner , Jonathan Cameron , Terry Bowman , Jon Pan-Doh Allow userspace to read/write log ratelimits per device (including enable/disable). Create aer/ sysfs directory to store them and any future aer configs. Tested using aer-inject[1]. Configured correctable log ratelimit to 5. Sent 6 AER errors. Observed 5 errors logged while AER stats (cat /sys/bus/pci/devices//aer_dev_correctable) shows 6. Disabled ratelimiting and sent 6 more AER errors. Observed all 6 errors logged and accounted in AER stats (12 total errors). [1] https://git.kernel.org/pub/scm/linux/kernel/git/gong.chen/aer-inject.git Signed-off-by: Karolina Stolarek Signed-off-by: Jon Pan-Doh --- .../testing/sysfs-bus-pci-devices-aer_stats | 34 +++++++ Documentation/PCI/pcieaer-howto.rst | 3 + drivers/pci/pci-sysfs.c | 1 + drivers/pci/pci.h | 1 + drivers/pci/pcie/aer.c | 93 +++++++++++++++++++ 5 files changed, 132 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-pci-devices-aer_stats b/Documentation/ABI/testing/sysfs-bus-pci-devices-aer_stats index d1f67bb81d5d..4561653fdbde 100644 --- a/Documentation/ABI/testing/sysfs-bus-pci-devices-aer_stats +++ b/Documentation/ABI/testing/sysfs-bus-pci-devices-aer_stats @@ -117,3 +117,37 @@ Date: July 2018 KernelVersion: 4.19.0 Contact: linux-pci@vger.kernel.org, rajatja@google.com Description: Total number of ERR_NONFATAL messages reported to rootport. + +PCIe AER ratelimits +------------------- + +These attributes show up under all the devices that are AER capable. +They represent configurable ratelimits of logs per error type. + +See Documentation/PCI/pcieaer-howto.rst for more info on ratelimits. + +What: /sys/bus/pci/devices//aer/ratelimit_log_enable +Date: March 2025 +KernelVersion: 6.15.0 +Contact: linux-pci@vger.kernel.org, pandoh@google.com +Description: Writing 1/0 enables/disables AER log ratelimiting. Reading + gets whether or not AER is currently enabled. Enabled by + default. + +What: /sys/bus/pci/devices//aer/ratelimit_in_5secs_cor_log +Date: March 2025 +KernelVersion: 6.15.0 +Contact: linux-pci@vger.kernel.org, pandoh@google.com +Description: Ratelimit burst for correctable error logs. Writing a value + changes the number of errors (burst) allowed per interval + (5 second window) before ratelimiting. Reading gets the + current ratelimit burst. + +What: /sys/bus/pci/devices//aer/ratelimit_in_5secs_uncor_log +Date: March 2025 +KernelVersion: 6.15.0 +Contact: linux-pci@vger.kernel.org, pandoh@google.com +Description: Ratelimit burst for uncorrectable error logs. Writing a + value changes the number of errors (burst) allowed per + interval (5 second window) before ratelimiting. Reading + gets the current ratelimit burst. diff --git a/Documentation/PCI/pcieaer-howto.rst b/Documentation/PCI/pcieaer-howto.rst index 896d2a232a90..b45a2e18d1cf 100644 --- a/Documentation/PCI/pcieaer-howto.rst +++ b/Documentation/PCI/pcieaer-howto.rst @@ -96,6 +96,9 @@ type (correctable vs. uncorrectable). AER uses the default ratelimit of DEFAULT_RATELIMIT_BURST (10 events) over DEFAULT_RATELIMIT_INTERVAL (5 seconds). +Ratelimits are exposed in the form of sysfs attributes and configurable. +See Documentation/ABI/testing/sysfs-bus-pci-devices-aer_stats. + AER Statistics / Counters ------------------------- diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index b46ce1a2c554..16de3093294e 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1801,6 +1801,7 @@ const struct attribute_group *pci_dev_attr_groups[] = { &pcie_dev_attr_group, #ifdef CONFIG_PCIEAER &aer_stats_attr_group, + &aer_attr_group, #endif #ifdef CONFIG_PCIEASPM &aspm_ctrl_attr_group, diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 9d63d32f041c..34633fe12201 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -889,6 +889,7 @@ void pci_no_aer(void); void pci_aer_init(struct pci_dev *dev); void pci_aer_exit(struct pci_dev *dev); extern const struct attribute_group aer_stats_attr_group; +extern const struct attribute_group aer_attr_group; void pci_aer_clear_fatal_status(struct pci_dev *dev); int pci_aer_clear_status(struct pci_dev *dev); int pci_aer_raw_clear_status(struct pci_dev *dev); diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index 0bd20c4993d4..13227a94c9f9 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -631,6 +631,99 @@ const struct attribute_group aer_stats_attr_group = { .is_visible = aer_stats_attrs_are_visible, }; +/* + * Ratelimit enable toggle uses interval value of + * 0: disabled + * DEFAULT_RATELIMIT_INTERVAL: enabled + */ +static ssize_t ratelimit_log_enable_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct pci_dev *pdev = to_pci_dev(dev); + bool enable = pdev->aer_report->cor_log_ratelimit.interval != 0; + + return sysfs_emit(buf, "%d\n", enable); +} + +static ssize_t ratelimit_log_enable_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct pci_dev *pdev = to_pci_dev(dev); + bool enable; + int interval; + + if (kstrtobool(buf, &enable) < 0) + return -EINVAL; + + if (enable) + interval = DEFAULT_RATELIMIT_INTERVAL; + else + interval = 0; + + pdev->aer_report->cor_log_ratelimit.interval = interval; + pdev->aer_report->uncor_log_ratelimit.interval = interval; + return count; +} +static DEVICE_ATTR_RW(ratelimit_log_enable); + +/* + * Ratelimits are doubled as a given error produces 2 logs (root port + * and endpoint) that should be under same ratelimit. + */ +#define aer_ratelimit_burst_attr(name, ratelimit) \ + static ssize_t \ + name##_show(struct device *dev, struct device_attribute *attr, \ + char *buf) \ +{ \ + struct pci_dev *pdev = to_pci_dev(dev); \ + return sysfs_emit(buf, "%d\n", \ + pdev->aer_report->ratelimit.burst / 2); \ +} \ + \ + static ssize_t \ + name##_store(struct device *dev, struct device_attribute *attr, \ + const char *buf, size_t count) \ +{ \ + struct pci_dev *pdev = to_pci_dev(dev); \ + int burst; \ + \ + if (kstrtoint(buf, 0, &burst) < 0) \ + return -EINVAL; \ + \ + pdev->aer_report->ratelimit.burst = burst * 2; \ + return count; \ +} \ +static DEVICE_ATTR_RW(name) + +aer_ratelimit_burst_attr(ratelimit_in_5secs_cor_log, cor_log_ratelimit); +aer_ratelimit_burst_attr(ratelimit_in_5secs_uncor_log, uncor_log_ratelimit); + +static struct attribute *aer_attrs[] = { + &dev_attr_ratelimit_log_enable.attr, + &dev_attr_ratelimit_in_5secs_cor_log.attr, + &dev_attr_ratelimit_in_5secs_uncor_log.attr, + NULL +}; + +static umode_t aer_attrs_are_visible(struct kobject *kobj, + struct attribute *a, int n) +{ + struct device *dev = kobj_to_dev(kobj); + struct pci_dev *pdev = to_pci_dev(dev); + + if (!pdev->aer_report) + return 0; + return a->mode; +} + +const struct attribute_group aer_attr_group = { + .name = "aer", + .attrs = aer_attrs, + .is_visible = aer_attrs_are_visible, +}; + void pci_dev_aer_stats_incr(struct pci_dev *pdev, struct aer_err_info *info) { unsigned long status = info->status & ~info->mask; From patchwork Wed Mar 19 08:40:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Pan-Doh X-Patchwork-Id: 14022280 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3C74211484 for ; Wed, 19 Mar 2025 08:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742373688; cv=none; b=NIrH4kv6DpFtBFNExtbzKgw64HH51RX0f+oXurqrc0ztBD+QUvTQzH81nF2LdFFJYBNhTKDtExMz19Ze27PFTkY0jXLDn54/iaS+aNH1u1AbcBQYTwQfgLsMWFakd/Wwq+G8WngYaSflH2Gy2nWLJHv3R8VVyr34Fi4NN3CL4ZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742373688; c=relaxed/simple; bh=aPlde8woHV7SJa++l2GOra75ZVpTRhppXL0d3g+34BE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AxhOCyhziGUXhuEoCIUguqQoh0593fcYVAvyY/lCkQQJhKRkiASwiDhMRkE9zXu+FxX0n1p7LbnXFZ8B4r04zSTWxVfDGqn1KbUzDqyPN8dGrFfO8Q0xJtriF1Sg5jmgfVfeXT3xrPTiOTH2SZCpNuIZV8GYrylM//Vk7T4PtlQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--pandoh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Upe/rv32; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--pandoh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Upe/rv32" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ff854a2541so6779077a91.0 for ; Wed, 19 Mar 2025 01:41:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742373686; x=1742978486; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=3G6AS6LhHp49BAqWSgpAT7caVkxV4HX8oBMiv1eA1Uc=; b=Upe/rv324Gvww+JBSXC7S/47p1jj/hNu5K0UbnKtbtOxZmoucf3LD7RyMCQNLepuMD ocTPA9lrJwMbgL6X7xC9AdCg4dZRyb2z1SqEdUK5xxV/bGWkV2WthqS1/6mOIXl5MrcV qZf9ftxqUMDQfbDJW+04AJQjlpobV/A9mm2PEmLg8IQAcrNW+tZSU0mndb0k4djRnMhx f4moZMfF0eX/0GzxwP7g8R0HpDdck5DxHyJPQS2/c1SX2K1yvjYJPtNQaF3fkz+kjiwn Py8xBJXNHrFt95dsyX+1/nTCBSi6PG+rlaEfYoJIswflHO7AMC4OEqIOxPIuvpMafAC8 iNfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742373686; x=1742978486; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3G6AS6LhHp49BAqWSgpAT7caVkxV4HX8oBMiv1eA1Uc=; b=eNFii6SNSP1GFHprehb4jtBZF7YsH4b5M8P3dCRfU1lhkR05BRXJ0qTOHpX+xZNgwl UtQzgA+aEGwSwLXOIEPLkMlVh6mZ53shzQ9BQhUnr26gm4mCXgsN54YDpWkf1JORiUxw 6byucnYUSGUfl6YCWOMnAOw4/nSSZlC9kilrX6weOB2rvfqy3ch5IL5Zu4kD/6hOv97b aqSGxT4Ylu+3VA4T+rWthMq1vTOqtiF3cXT+PQlhNmAO7b4C342ukPGLCTgtu5u4wiCX zPsqmofxGuDQmr5HHtnrDjqdZ0q9mNQeQwM+BRX8NNNr59vVKh+1Xg2S02j2Yim8alSw /QNg== X-Gm-Message-State: AOJu0YxgmT/biXYsNMv/6yWYiF0ci3gg13JT91Quxx0fBPG+jyPQd910 zpxjECo4c2ackgWXwcAwq4VtIElggUkpw2RWBleur/DxOsrP/KxWXJr2/xRd10AZIQy73EvjEyD +Zw== X-Google-Smtp-Source: AGHT+IFNtICnzFQq/J6NoAFE4IJHd4+rL3ozRKFPa63yDKQ7KJsjUjSncsQZk7736fSpdcAeDmmx+Vvj4HI= X-Received: from pjbpl11.prod.google.com ([2002:a17:90b:268b:b0:2fc:13d6:b4cb]) (user=pandoh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4fc5:b0:2f8:4a3f:dd2d with SMTP id 98e67ed59e1d1-301bdf9364bmr3254019a91.15.1742373686183; Wed, 19 Mar 2025 01:41:26 -0700 (PDT) Date: Wed, 19 Mar 2025 01:40:49 -0700 In-Reply-To: <20250319084050.366718-1-pandoh@google.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319084050.366718-1-pandoh@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Message-ID: <20250319084050.366718-9-pandoh@google.com> Subject: [PATCH v3 8/8] PCI/AER: Update AER sysfs ABI filename From: Jon Pan-Doh To: Bjorn Helgaas , Karolina Stolarek Cc: linux-pci@vger.kernel.org, Martin Petersen , Ben Fuller , Drew Walton , Anil Agrawal , Tony Luck , " =?utf-8?q?Ilpo_J=C3=A4rvinen?= " , Sathyanarayanan Kuppuswamy , Lukas Wunner , Jonathan Cameron , Terry Bowman , Jon Pan-Doh Change Documentation/ABI/testing/sysfs-bus-pci-devices-aer_stats to Documentation/ABI/testing/sysfs-bus-pci-devices-aer to reflect the broader scope of AER sysfs attributes (e.g. stats and ratelimits). Signed-off-by: Jon Pan-Doh --- ...fs-bus-pci-devices-aer_stats => sysfs-bus-pci-devices-aer} | 0 Documentation/PCI/pcieaer-howto.rst | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename Documentation/ABI/testing/{sysfs-bus-pci-devices-aer_stats => sysfs-bus-pci-devices-aer} (100%) diff --git a/Documentation/ABI/testing/sysfs-bus-pci-devices-aer_stats b/Documentation/ABI/testing/sysfs-bus-pci-devices-aer similarity index 100% rename from Documentation/ABI/testing/sysfs-bus-pci-devices-aer_stats rename to Documentation/ABI/testing/sysfs-bus-pci-devices-aer diff --git a/Documentation/PCI/pcieaer-howto.rst b/Documentation/PCI/pcieaer-howto.rst index b45a2e18d1cf..043cdb3194be 100644 --- a/Documentation/PCI/pcieaer-howto.rst +++ b/Documentation/PCI/pcieaer-howto.rst @@ -97,14 +97,14 @@ AER uses the default ratelimit of DEFAULT_RATELIMIT_BURST (10 events) over DEFAULT_RATELIMIT_INTERVAL (5 seconds). Ratelimits are exposed in the form of sysfs attributes and configurable. -See Documentation/ABI/testing/sysfs-bus-pci-devices-aer_stats. +See Documentation/ABI/testing/sysfs-bus-pci-devices-aer. AER Statistics / Counters ------------------------- When PCIe AER errors are captured, the counters / statistics are also exposed in the form of sysfs attributes which are documented at -Documentation/ABI/testing/sysfs-bus-pci-devices-aer_stats +Documentation/ABI/testing/sysfs-bus-pci-devices-aer. Developer Guide ===============