Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Souza, Jose" <jose.souza@intel.com>
To: "Vivi, Rodrigo" <rodrigo.vivi@intel.com>,
	"De Marchi, Lucas" <lucas.demarchi@intel.com>
Cc: "intel-xe@lists.freedesktop.org" <intel-xe@lists.freedesktop.org>,
	"igt-dev@lists.freedesktop.org" <igt-dev@lists.freedesktop.org>,
	"maarten.lankhorst@linux.intel.com"
	<maarten.lankhorst@linux.intel.com>
Subject: Re: [PATCH i-g-t 2/3] lib/igt_kmod: drop devcoredump before a PCI module unload
Date: Fri, 5 Apr 2024 17:42:54 +0000	[thread overview]
Message-ID: <4be0c16d91e0974cc689db3a78ec5dab6f603723.camel@intel.com> (raw)
In-Reply-To: <zwrpstbmzbpkhbu6k7rjv5lm2a6wjvjs5t7msosmhhl5mtk2pq@4agb7ra6ceqf>

On Fri, 2024-04-05 at 12:36 -0500, Lucas De Marchi wrote:
> On Wed, Apr 03, 2024 at 11:14:08AM -0400, Rodrigo Vivi wrote:
> > devcoredump holds a module reference, blocking the module removal.
> > 
> > It is intentional from the devcoredump perspective to keep the
> > log available even after the unbind/unprobe. However it blocks
> > our module removal here.

'devcoredump: Add dev_coredump_put()' was reviewed by devcoredump maintainers, so we can remove devcoredump before unload Xe.
So I don't think we will need this patch.

It is still pending on getting pushed but we could add to the topic branches to unblock CI if needed.

> > 
> > v2: Accepting many suggestions from Lucas.
> > 
> > Cc: Lucas De Marchi <lucas.demarchi@intel.com>
> > Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> > Cc: José Roberto de Souza <jose.souza@intel.com>
> > Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> > ---
> > lib/igt_kmod.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 55 insertions(+)
> > 
> > diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
> > index cc242838f..14d51f4f6 100644
> > --- a/lib/igt_kmod.c
> > +++ b/lib/igt_kmod.c
> > @@ -323,6 +323,59 @@ static int igt_kmod_unload_r(struct kmod_module *kmod, unsigned int flags)
> > 	return err;
> > }
> > 
> > +static void igt_drop_devcoredump(const char *driver)
> > +{
> > +	char sysfspath[PATH_MAX];
> > +	DIR *dir;
> > +	char *devcoredump;
> > +	FILE *data;
> > +	struct dirent *entry;
> > +	int len, ret;
> > +
> > +	len = snprintf(sysfspath, sizeof(sysfspath),
> > +		       "/sys/bus/pci/drivers/%s", driver);
> > +
> > +	igt_assert(len < sizeof(sysfspath));
> > +
> > +	 /* Not a PCI module */
> > +	if (access(sysfspath, F_OK))
> > +		return;
> > +
> > +	devcoredump = sysfspath + len;
> > +
> > +	dir = opendir(sysfspath);
> > +	igt_assert(dir);
> > +
> > +	while ((entry = readdir(dir)) != NULL) {
> > +		if (entry->d_type != DT_LNK ||
> > +		    strcmp(entry->d_name, ".") == 0 ||
> > +		    strcmp(entry->d_name, "..") == 0)
> > +			continue;
> > +
> > +		ret = snprintf(devcoredump, sizeof(sysfspath) - len,
> > +			       "/%s/devcoredump", entry->d_name);
> 
> I  think this could be simplified a little bit further
> 
> 		ret = snprintf(devcoredump, sizeof(sysfspath) - len,
> 			       "/%s/devcoredump/data", entry->d_name);
> 		igt_assert(ret < sizeof(sysfspath) - len);
> 
> 		data = fopen(sysfspath, "w");
> 		if (data) {
> 			igt_info("Removing devcoredump before module unload: %s\n",
> 				 sysfspath);
> 
> 			/*
> 			 * Write anything to devcoredump/data to
> 			 * force its deletion
> 			 */
> 			fprintf(data, "1\n");
> 			fclose(data);
> 		}
> 
> so it drops the TOCTOU of access()/open() and make it shorter.
> ... but totally optional. And untested).
> 
> 
> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
> 
> Lucas De Marchi


  reply	other threads:[~2024-04-05 17:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03 15:14 [PATCH i-g-t 1/3] tests/intel/xe_pm: Fix runtime_pm tests Rodrigo Vivi
2024-04-03 15:14 ` [PATCH i-g-t 2/3] lib/igt_kmod: drop devcoredump before a PCI module unload Rodrigo Vivi
2024-04-05 17:36   ` Lucas De Marchi
2024-04-05 17:42     ` Souza, Jose [this message]
2024-04-03 15:14 ` [PATCH i-g-t 3/3] tests/intel/xe_wedged: Introduce a new test for Xe device wedged state Rodrigo Vivi
2024-04-03 17:21 ` ✗ CI.Patch_applied: failure for series starting with [i-g-t,1/3] tests/intel/xe_pm: Fix runtime_pm tests Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4be0c16d91e0974cc689db3a78ec5dab6f603723.camel@intel.com \
    --to=jose.souza@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=lucas.demarchi@intel.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=rodrigo.vivi@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox