Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp478021lqp; Mon, 10 Jun 2024 09:35:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVXUWk5OYCW3p8HtNT24FdNx8aYr9z0SR6D+ak3iZ/MasYGVvdHWSZQMlMRwdE2kisG/1CjnHzJEnrF5BAbRvvLCjHBGR3rhI21ctxDbQ== X-Google-Smtp-Source: AGHT+IFakpzg8ZRVgNYvr/d8pxQtDw8maS11h+YQvYgeOOSm4XVwxe2caT2gYny7LtNdSKFqyUZc X-Received: by 2002:a05:6358:3a1c:b0:199:2a1a:19d5 with SMTP id e5c5f4694b2df-19f1fe292d4mr1236140655d.9.1718037313512; Mon, 10 Jun 2024 09:35:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718037313; cv=pass; d=google.com; s=arc-20160816; b=HVoW4CNC2yD2aKOsDcwa/QqbHHO2qfglgPp8rL9ljsp2HQ8GAzBfs7etF200njUK88 nO7o5h1gaTRx/GxeaTrNBo2W4hljeaNtBT3BDwnu+xNseIAtVrMy2vD/Ov5WR1A+nBTK fxqrdhu4TLAf19qQ1NLOuI5amR3aPr7Rs6Ypy73dDVw3oKX9DnmkRDkX8kSJRUYLef6M dV78meTB6pczbg3gE996xu4+zpCVVh3ggLGeI1WXIIBCZLuiBtFv8ag8ScGgir/ifIW0 efadls5zrMo76bvl+jGa1gUBWE5Xl4T9hmAHVaeQNi7AG3wskLQXvNEmku46dl/n4U+a p9xQ== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=CdEGwknpt6j5kG31vNM/i4XLOP29o/m2+0ipuUdQRag=; fh=/aA3ikCzdHUoND1NkELyjjOlZC31bXhfya5LgPc2Wj8=; b=wvGSZO9Idmfk/iYxWmtxe710NnVdlngRgNEUHrD6DOLe53xYJz3hgaYz1PhIUDnOrT LV9SDEG3vX/h484WsYIeX1ul8vubxubDieSKN3AGQrcOHOoJtQpPXBoQki3t8CTWeH1x bXNEBKbfnkjP+QrprGaQJAjNugWkytWmRX4hpYh5tltzgGijWoCKWZBClVVfMtGV6SS1 ZyWxcoeXpsVEbIMH7YxFdpnWEB6Xmufai3qXXljCWkI3cZJV/9AQuRd4u1XESbGqZbSA 8yp9tBnDWZZUU3bCv6X8jpyta4K8uVj7F9VLCcucLO+oKaVf+g1LJQm2T5bk/geiuGFD +Qwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=X5wiXsE7; 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-208531-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208531-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6ea8bc2c59csi3364840a12.863.2024.06.10.09.35.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 09:35:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208531-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=X5wiXsE7; 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-208531-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208531-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 5CE3DB2958F for ; Mon, 10 Jun 2024 16:11:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CF1D8142E78; Mon, 10 Jun 2024 16:11:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="X5wiXsE7" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 0A38B1DFF7 for ; Mon, 10 Jun 2024 16:11:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718035905; cv=none; b=IKKmKwBiJyCz71usN2okMiJYm/C/cRfZxL1jeQ/4a7V4kuErm7bVOWumqPyARf0AtEDVuD42CmCFqGsRfr2qE1OiLsonr5TPQdLsXHHwcUYCiZJtj4WWlyrr/F/g2Ms+fmfws8AeYCs+zalUWX+YJ3gXCj5r3xKB1dXMSYDt07k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718035905; c=relaxed/simple; bh=dUsYAftJt41T6AuchTSoENgGxAhOCwtjhSihLZcmOfc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=rCGwoexnTDGBQrvIjZhr9yR5DAEgs9ZJVfjKnNZ8HQRzSkAGCyhLuZvfu+yGKMT9Zue0+3gAGx9gFU9I7ZfCYiw5OYEmYjtM395o3szaixeMtT5tK2m75Kk0vqtOxK1dVyg/OJpkAuc0wXOjTd2mfF2YxJC7hVte5qkuTWirlWM= 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=X5wiXsE7; arc=none smtp.client-ip=198.175.65.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=1718035904; x=1749571904; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=dUsYAftJt41T6AuchTSoENgGxAhOCwtjhSihLZcmOfc=; b=X5wiXsE79d2qlmv2Yt02kjCeDactcgpj0fMueBq1nDanwEqeNUo7tyfI l4Ma55SPq2OmH8d3ExsCdzImCZnlamtp8INNYC7twz6K4QbHxcy+G9RTs Oz7hyRNWAKwEC+TUulneXw9gqQLptqE7xsA2BfMGxasEptuFpQ/hngP3X wwGJrbTsNN7CRZhgqdabyWLTFD3GVFZhjQkrj9pfpFbm4WaN/chApdrJD 10o9OKLyU12MuIXpcVyNOWEzCh+3Z8/F8lmqDhfpHBbk0jtkAmE72TcM6 j0kla77vlwl6ptciBg7U8jSLDOedHP9n/zGLaouPSQ6SI1FhpH0dIJrJK Q==; X-CSE-ConnectionGUID: eiE6JXtvQWiiZadmrpJiYw== X-CSE-MsgGUID: l/ZSC/sKTKik0j4GauOGhg== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="32193224" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="32193224" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 09:11:44 -0700 X-CSE-ConnectionGUID: sFwIUny1Q6mhDb/Iw9s7xQ== X-CSE-MsgGUID: omu3LHhJTbCWC/icr8pezQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="62281508" Received: from josouza-mobl2.bz.intel.com ([10.87.243.88]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 09:11:41 -0700 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 v5 1/2] devcoredump: Add dev_coredumpm_timeout() Date: Mon, 10 Jun 2024 09:11:32 -0700 Message-ID: <20240610161133.156566-1-jose.souza@intel.com> X-Mailer: git-send-email 2.45.2 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. For Xe driver usage, current 5 minutes timeout may be too short for users to search and understand what needs to be done to capture coredump to report bugs. We have plans to automate(distribute a udev script) it but at the end will be up to distros and users to pack it so having a option to increase the timeout is a safer option. v2: - replace dev_coredump_timeout_set() by dev_coredumpm_timeout() (Mukesh) v3: - make dev_coredumpm() static inline (Johannes) v5: - rename DEVCOREDUMP_TIMEOUT -> DEVCD_TIMEOUT to avoid redefinition in include/net/bluetooth/coredump.h 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..e3de1e545a4a5 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 DEVCD_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, + DEVCD_TIMEOUT); +} + #endif /* __DEVCOREDUMP_H */ -- 2.45.2