Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1879316lqg; Mon, 4 Mar 2024 06:40:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV8xasmcOGvymmRB4ZQvOYdYIQ7vbPSJY+tOEq64z8tOMf30gZIhWHooLQGMOEQqJ0Cwj5DF3k15K2rsLEDaQ+elHX7Qa9JKJ4oF1oWlg== X-Google-Smtp-Source: AGHT+IG1tiY/lv3QaZn2AzwKAxhp7GYoH+eHGg5zbNOVfowY4YnI2kuuyAShmuQ+t+W7DGaMwQD4 X-Received: by 2002:a17:906:8c6:b0:a3e:9aa3:7024 with SMTP id o6-20020a17090608c600b00a3e9aa37024mr6188464eje.34.1709563217430; Mon, 04 Mar 2024 06:40:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709563217; cv=pass; d=google.com; s=arc-20160816; b=dUz6qUumlNOqMkUhAghTernDJglCLWhf/jZGhh+suib9eVflVZK76BkEEIgcIm6lGm Tvwgz8zPha2wS8xO1C/uSNrlW4sqRYlcYSmy/ZI+yugvNgp2a79pi3fKwFqZ18RU4K1Y DIE1Pu6hxneDI151skAW8676VFJKGbSY84Z6MLO0GHUjWLrRAVOtFB9oYEcOjzElyEYD DhBtRPgkziieHViEVXFA2IKvmr4pHPmgW2YxExrQ4unALQomHe+eXGpiPJ8Ss5MZo6aY wXZ3Tm+OhHXRviKhhfQvWOEFmkmhnr1+MLfS5/DlgGYuaB0X0yVtvMhNiPJRQ1DbS966 LHrA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Dk393IN1jxoXMUA5gtF3S7SqJlqtfwTkt4nljwNJMmo=; fh=/aA3ikCzdHUoND1NkELyjjOlZC31bXhfya5LgPc2Wj8=; b=BTUkVkwvUfeJ1hhWdCG3V3QZUDndAJ9palOYYoxhIcZl3S+IioHu2smFyD//9vFLmo dKKy+068cyvcXWdLfVSrEKmEUvXN9nhZelWqTrS2W3yFgg03f+CfiTL11VQ4MjEgE45V b9DGepXoRA0yEqrpWoTr0+lGkcfF/JkOXmkrghnCvTSD33uxE00FHJEfYthGwC5qDS7M LzP1UsgMmU/hsWfUMzBuonFaf6UMOEx7jFBipwf4KtxlX+bG237T149t2lRgODwExzMU 0P1zsLwlV6rQ/s2E49aSF0LPqY5S/aXSbDDF7UbUIYiUvpwrR18AEWgDI1BVhOmmEXK1 27dQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gkfeS39F; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-90744-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90744-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id qk19-20020a1709077f9300b00a44d54b6317si2193665ejc.345.2024.03.04.06.40.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 06:40:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90744-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gkfeS39F; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-90744-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90744-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5BA1C1F247A1 for ; Mon, 4 Mar 2024 14:39:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D2B0C46450; Mon, 4 Mar 2024 14:39:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gkfeS39F" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD5AF3CF6D for ; Mon, 4 Mar 2024 14:39:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709563158; cv=none; b=Ie5c1f9rV8eqKkk0Ul1c/SqzweEFdK8DCWz7gbccqu9Sv/+sYPi1USAnVPn1w4GwOeFDowHjd8f0PMlBk1PtxhUDytnxxJZkCfcrNS7sgv9iQnTEQEdhZI63LX1ORi+euT4HfEgC12Fb4/RpRt5mHJTeWsRpdRlYs2jL9JGWJyk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709563158; c=relaxed/simple; bh=lmw9xOoiQDklyw261pt95/gZg8tQiKm6KXYJNlcrwdM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LsvgZwtOgr4KtY0ieywmjm2VhSExyT+/rt5Ltf8+SVD3cwBETtHJI2c2C2X6hBpLlZJUQvlb7gWDJrfGA/eAuwZLz4Q/lGwaKzPUmGFtAAjUshL/mlBeOKnRh7qA7g21p/UXfnIgna6BJa5NWBxQoULcpCyrP7ExH+reMXiRG0E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=gkfeS39F; arc=none smtp.client-ip=192.198.163.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709563157; x=1741099157; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lmw9xOoiQDklyw261pt95/gZg8tQiKm6KXYJNlcrwdM=; b=gkfeS39F5zxh5DqDu18NlhPENneflJhlt99UlcBIhB3oBj9W/ftb4vLA chg495AbLyG7RhmlyRrbwO0rOZqblNGusBf0HzWVDEyvqqIzcFTmAG56E Akkfx4u+R3E82XP7a8M5GSJdcSQRVNKTNL9RdzAhC1KUXvK+G5PEIYtyW PWnG4smusVGDDOOmI72VSPCq5i/Gyqj2Lghr2/4fj21FdmEmVFereHuFj wPuYOTmNsiogE2qYmW/iBjVoCzWrCuOf/60fQWxQtyw02K9Z00D9wjnQm P8ZVAgJ2ZvSS/RXYAQ4klpth1cdVCRr5plyMsgzQczQxkji8pXfhJ7tqT A==; X-IronPort-AV: E=McAfee;i="6600,9927,11002"; a="15464634" X-IronPort-AV: E=Sophos;i="6.06,203,1705392000"; d="scan'208";a="15464634" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2024 06:39:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,203,1705392000"; d="scan'208";a="9162540" Received: from josouza-mobl2.bz.intel.com ([10.87.243.88]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2024 06:39:14 -0800 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= To: linux-kernel@vger.kernel.org, intel-xe@lists.freedesktop.org Cc: Rodrigo Vivi , Mukesh Ojha , Johannes Berg , Jonathan Cavitt , =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Subject: [PATCH v3 2/4] devcoredump: Add dev_coredumpm_timeout() Date: Mon, 4 Mar 2024 06:39:03 -0800 Message-ID: <20240304143905.52740-2-jose.souza@intel.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240304143905.52740-1-jose.souza@intel.com> References: <20240304143905.52740-1-jose.souza@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add function to set a custom coredump timeout. Current 5-minute timeout may be too short for users to search and understand what needs to be done to capture coredump to report bugs. v2: - replace dev_coredump_timeout_set() by dev_coredumpm_timeout() (Mukesh) v3: - make dev_coredumpm() static inline (Johannes) Cc: Rodrigo Vivi Cc: Mukesh Ojha Cc: Johannes Berg Cc: Jonathan Cavitt Acked-by: Jonathan Cavitt Signed-off-by: José Roberto de Souza --- drivers/base/devcoredump.c | 23 ++++++++-------- include/linux/devcoredump.h | 54 ++++++++++++++++++++++++++++--------- 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/drivers/base/devcoredump.c b/drivers/base/devcoredump.c index 82aeb09b3d1b5..c795edad1b969 100644 --- a/drivers/base/devcoredump.c +++ b/drivers/base/devcoredump.c @@ -18,9 +18,6 @@ static struct class devcd_class; /* global disable flag, for security purposes */ static bool devcd_disabled; -/* if data isn't read by userspace after 5 minutes then delete it */ -#define DEVCD_TIMEOUT (HZ * 60 * 5) - struct devcd_entry { struct device devcd_dev; void *data; @@ -328,7 +325,8 @@ void dev_coredump_put(struct device *dev) EXPORT_SYMBOL_GPL(dev_coredump_put); /** - * dev_coredumpm - create device coredump with read/free methods + * dev_coredumpm_timeout - create device coredump with read/free methods with a + * custom timeout. * @dev: the struct device for the crashed device * @owner: the module that contains the read/free functions, use %THIS_MODULE * @data: data cookie for the @read/@free functions @@ -336,17 +334,20 @@ EXPORT_SYMBOL_GPL(dev_coredump_put); * @gfp: allocation flags * @read: function to read from the given buffer * @free: function to free the given buffer + * @timeout: time in jiffies to remove coredump * * Creates a new device coredump for the given device. If a previous one hasn't * been read yet, the new coredump is discarded. The data lifetime is determined * by the device coredump framework and when it is no longer needed the @free * function will be called to free the data. */ -void dev_coredumpm(struct device *dev, struct module *owner, - void *data, size_t datalen, gfp_t gfp, - ssize_t (*read)(char *buffer, loff_t offset, size_t count, - void *data, size_t datalen), - void (*free)(void *data)) +void dev_coredumpm_timeout(struct device *dev, struct module *owner, + void *data, size_t datalen, gfp_t gfp, + ssize_t (*read)(char *buffer, loff_t offset, + size_t count, void *data, + size_t datalen), + void (*free)(void *data), + unsigned long timeout) { static atomic_t devcd_count = ATOMIC_INIT(0); struct devcd_entry *devcd; @@ -403,7 +404,7 @@ void dev_coredumpm(struct device *dev, struct module *owner, dev_set_uevent_suppress(&devcd->devcd_dev, false); kobject_uevent(&devcd->devcd_dev.kobj, KOBJ_ADD); INIT_DELAYED_WORK(&devcd->del_wk, devcd_del); - schedule_delayed_work(&devcd->del_wk, DEVCD_TIMEOUT); + schedule_delayed_work(&devcd->del_wk, timeout); mutex_unlock(&devcd->mutex); return; put_device: @@ -414,7 +415,7 @@ void dev_coredumpm(struct device *dev, struct module *owner, free: free(data); } -EXPORT_SYMBOL_GPL(dev_coredumpm); +EXPORT_SYMBOL_GPL(dev_coredumpm_timeout); /** * dev_coredumpsg - create device coredump that uses scatterlist as data diff --git a/include/linux/devcoredump.h b/include/linux/devcoredump.h index c8f7eb6cc1915..56e606eb4640b 100644 --- a/include/linux/devcoredump.h +++ b/include/linux/devcoredump.h @@ -12,6 +12,9 @@ #include #include +/* if data isn't read by userspace after 5 minutes then delete it */ +#define DEVCOREDUMP_TIMEOUT (HZ * 60 * 5) + /* * _devcd_free_sgtable - free all the memory of the given scatterlist table * (i.e. both pages and scatterlist instances) @@ -50,16 +53,17 @@ static inline void _devcd_free_sgtable(struct scatterlist *table) kfree(delete_iter); } - #ifdef CONFIG_DEV_COREDUMP void dev_coredumpv(struct device *dev, void *data, size_t datalen, gfp_t gfp); -void dev_coredumpm(struct device *dev, struct module *owner, - void *data, size_t datalen, gfp_t gfp, - ssize_t (*read)(char *buffer, loff_t offset, size_t count, - void *data, size_t datalen), - void (*free)(void *data)); +void dev_coredumpm_timeout(struct device *dev, struct module *owner, + void *data, size_t datalen, gfp_t gfp, + ssize_t (*read)(char *buffer, loff_t offset, + size_t count, void *data, + size_t datalen), + void (*free)(void *data), + unsigned long timeout); void dev_coredumpsg(struct device *dev, struct scatterlist *table, size_t datalen, gfp_t gfp); @@ -72,12 +76,13 @@ static inline void dev_coredumpv(struct device *dev, void *data, vfree(data); } -static inline void -dev_coredumpm(struct device *dev, struct module *owner, - void *data, size_t datalen, gfp_t gfp, - ssize_t (*read)(char *buffer, loff_t offset, size_t count, - void *data, size_t datalen), - void (*free)(void *data)) +void dev_coredumpm_timeout(struct device *dev, struct module *owner, + void *data, size_t datalen, gfp_t gfp, + ssize_t (*read)(char *buffer, loff_t offset, + size_t count, void *data, + size_t datalen), + void (*free)(void *data), + unsigned long timeout) { free(data); } @@ -92,4 +97,29 @@ static inline void dev_coredump_put(struct device *dev) } #endif /* CONFIG_DEV_COREDUMP */ +/** + * dev_coredumpm - create device coredump with read/free methods + * @dev: the struct device for the crashed device + * @owner: the module that contains the read/free functions, use %THIS_MODULE + * @data: data cookie for the @read/@free functions + * @datalen: length of the data + * @gfp: allocation flags + * @read: function to read from the given buffer + * @free: function to free the given buffer + * + * Creates a new device coredump for the given device. If a previous one hasn't + * been read yet, the new coredump is discarded. The data lifetime is determined + * by the device coredump framework and when it is no longer needed the @free + * function will be called to free the data. + */ +static inline void dev_coredumpm(struct device *dev, struct module *owner, + void *data, size_t datalen, gfp_t gfp, + ssize_t (*read)(char *buffer, loff_t offset, size_t count, + void *data, size_t datalen), + void (*free)(void *data)) +{ + dev_coredumpm_timeout(dev, owner, data, datalen, gfp, read, free, + DEVCOREDUMP_TIMEOUT); +} + #endif /* __DEVCOREDUMP_H */ -- 2.44.0