From nobody Sun Nov 24 17:02:54 2024 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 F21941C68F for ; Tue, 5 Nov 2024 01:06:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730768777; cv=none; b=ZyFCr+XSI1ymzHLDl+bsdk1xKnJcgEFgYtWXhHpip8MMvjS+6HkN3/+DyOa3QWTF6+sBvjhwHxD6P7igKqUViosRs9U5TeBRB+LC9EkujXA8iNWkYGX28FkTDxhVTavgDtsTVfztG+6PrdFsAaDkFPJ1OX0M1ftUi102rQuUB9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730768777; c=relaxed/simple; bh=uPJS3mnhiD5KP+r9032K22WkeGASPpslcji7zDxZohg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=uuohcdZluwIjIQHHyHNqihFSzufh/q0kG76pW8GAM6bs1Fdjw7bDrKHJsjZNZvZR/UqIHe0T483GfwYFfLGR9GXpiHmIhOc3yOV4bd5dBhCXI77x+s8AI/DWw9rKrMFdrz6ZoM9WQZDtJ3nU4eYo5pcFSmgNC1JowjPt7Xselqg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dionnaglaze.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=0dJId63t; arc=none smtp.client-ip=209.85.210.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--dionnaglaze.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0dJId63t" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-71e49ae1172so4785232b3a.2 for ; Mon, 04 Nov 2024 17:06:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730768775; x=1731373575; 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=C69aGsOp2lpKUTUJIlKoxOdLcqIbpxWjUksMkIqKMLQ=; b=0dJId63txokrQGmNz9Je3Oe62KdedauQfHfEJajl01nR7g4CwXmxhLhfWr5dCep2BT lIDTW9r25YM0YFTfV8hvzo4uIT3FiaRXo0BO29jeFTcnheACXeq5DKl1GQzsSqhCYJjM sAIh5MXYkAIlaPKRzxijykyXoY/RvecLx46uCW5TjmDh4N/1ouKo5jdQ+32c09PdgRRT TXkfqV25bsvFHr8LqO7yVLY78vjswb6C+jNOEN6qAz7R7P8la1vq2vsJjH/pQoH8lzei TIvPwQqfp8XGV+7zUpzkikKJ6JUANTAwpmfiu/1JMVZNPP6cRwEGKyblCnQRNgDcJHRi 4y6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730768775; x=1731373575; 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=C69aGsOp2lpKUTUJIlKoxOdLcqIbpxWjUksMkIqKMLQ=; b=tyAYt3iXJcV5+Ow2lgs6VTyurKApVLGhVJgSuEfk15E42x30Y3PjP5i43wkN8cL1Nn eyomAv0BZWvF59Jbmsyd7tdWB4ffTO0NqCJalQwSKJxd6oy4FZ7Npgku732fVIPIJCYq yZuppA5lKOQF/CBPz7+6eH+o4PJv6DU/XUyKGtLkcMyFbQv7SKk3I7H+bLgasVClqNw+ E/R/lvnLsTlHvrxiMhdN2qm/tbHYhSdxtk+KEQ6Yyh9RYlJo4T519fZ7SbM9N7MhXcGA qSZZKi3pPfEP58jk9XzVIZZIj4UynvwURtpDrBCkJrKQYO6mHzrJRXevX06o+4lfwcvk NtMw== X-Forwarded-Encrypted: i=1; AJvYcCVy1y1ujF7TF+iZxNV2Il8bsIn/wFQ5NxPYWgKG4SkC6fRF2rX3uOTaZRwE9OoWi8wtTqJu5lWG1zCimK8=@vger.kernel.org X-Gm-Message-State: AOJu0YxnjlYKJ3C3jv8zjrOOEx6w2kubOcVwFmlvj1Bf179j2LUsKJBd q+UhhtR0X+4DBiImF0/4P6uiRJgy5o++Y1+3p9VjPNlz5cWIR2xYUVgwvZVUT7jQ5nBQpryla5V 6fSwrELsigezIC1mlctIJAQ== X-Google-Smtp-Source: AGHT+IEYcurUyDuk6UGh/vVlH4wPfYFJTLCfkxulUr59pdPf9DO6uq1RjaNDS0c4qAJxzK6f+CrS5V5OEHQDpLthYQ== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:36:e7b8:ac13:c9e8]) (user=dionnaglaze job=sendgmr) by 2002:a62:e708:0:b0:71e:5580:f456 with SMTP id d2e1a72fcca58-7206306de0fmr86607b3a.3.1730768775293; Mon, 04 Nov 2024 17:06:15 -0800 (PST) Date: Tue, 5 Nov 2024 01:05:49 +0000 In-Reply-To: <20241105010558.1266699-1-dionnaglaze@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241105010558.1266699-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241105010558.1266699-3-dionnaglaze@google.com> Subject: [PATCH v4 2/6] firmware_loader: Move module refcounts to allow unloading From: Dionna Glaze To: x86@kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain , Russ Weight , Danilo Krummrich , Greg Kroah-Hartman , "Rafael J. Wysocki" , Tianfei zhang Cc: Dionna Glaze , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Ashish Kalra , Tom Lendacky , John Allen , Herbert Xu , "David S. Miller" , Michael Roth , Alexey Kardashevskiy , Russ Weight Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If a kernel module registers a firmware upload API ops set, then it's unable to be moved due to effectively a cyclic reference that the module depends on the upload which depends on the module. Instead, only require the try_module_get when an upload is requested to disallow unloading a module only while the upload is in progress. Fixes: 97730bbb242c ("firmware_loader: Add firmware-upload support") CC: Sean Christopherson CC: Paolo Bonzini CC: Thomas Gleixner CC: Ingo Molnar CC: Borislav Petkov CC: Dave Hansen CC: Ashish Kalra CC: Tom Lendacky CC: John Allen CC: Herbert Xu CC: "David S. Miller" CC: Michael Roth CC: Luis Chamberlain CC: Russ Weight CC: Danilo Krummrich CC: Greg Kroah-Hartman CC: "Rafael J. Wysocki" CC: Tianfei zhang CC: Alexey Kardashevskiy Tested-by: Ashish Kalra Reviewed-by: Russ Weight Signed-off-by: Dionna Glaze --- drivers/base/firmware_loader/sysfs_upload.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/base/firmware_loader/sysfs_upload.c b/drivers/base/fir= mware_loader/sysfs_upload.c index 829270067d163..7d9c6aef7720a 100644 --- a/drivers/base/firmware_loader/sysfs_upload.c +++ b/drivers/base/firmware_loader/sysfs_upload.c @@ -204,6 +204,7 @@ static void fw_upload_main(struct work_struct *work) fwlp->ops->cleanup(fwl); =20 putdev_exit: + module_put(fwlp->module); put_device(fw_dev->parent); =20 /* @@ -239,6 +240,9 @@ int fw_upload_start(struct fw_sysfs *fw_sysfs) } =20 fwlp =3D fw_sysfs->fw_upload_priv; + if (!try_module_get(fwlp->module)) /* released in fw_upload_main */ + return -EFAULT; + mutex_lock(&fwlp->lock); =20 /* Do not interfere with an on-going fw_upload */ @@ -310,13 +314,10 @@ firmware_upload_register(struct module *module, struc= t device *parent, return ERR_PTR(-EINVAL); } =20 - if (!try_module_get(module)) - return ERR_PTR(-EFAULT); - fw_upload =3D kzalloc(sizeof(*fw_upload), GFP_KERNEL); if (!fw_upload) { ret =3D -ENOMEM; - goto exit_module_put; + goto exit_err; } =20 fw_upload_priv =3D kzalloc(sizeof(*fw_upload_priv), GFP_KERNEL); @@ -358,7 +359,7 @@ firmware_upload_register(struct module *module, struct = device *parent, if (ret) { dev_err(fw_dev, "%s: device_register failed\n", __func__); put_device(fw_dev); - goto exit_module_put; + goto exit_err; } =20 return fw_upload; @@ -372,8 +373,7 @@ firmware_upload_register(struct module *module, struct = device *parent, free_fw_upload: kfree(fw_upload); =20 -exit_module_put: - module_put(module); +exit_err: =20 return ERR_PTR(ret); } @@ -387,7 +387,6 @@ void firmware_upload_unregister(struct fw_upload *fw_up= load) { struct fw_sysfs *fw_sysfs =3D fw_upload->priv; struct fw_upload_priv *fw_upload_priv =3D fw_sysfs->fw_upload_priv; - struct module *module =3D fw_upload_priv->module; =20 mutex_lock(&fw_upload_priv->lock); if (fw_upload_priv->progress =3D=3D FW_UPLOAD_PROG_IDLE) { @@ -403,6 +402,5 @@ void firmware_upload_unregister(struct fw_upload *fw_up= load) =20 unregister: device_unregister(&fw_sysfs->dev); - module_put(module); } EXPORT_SYMBOL_GPL(firmware_upload_unregister); --=20 2.47.0.199.ga7371fff76-goog