From nobody Sun Nov 24 22:51:08 2024 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 C99411CEAA7 for ; Fri, 1 Nov 2024 18:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730484951; cv=none; b=JjSe8qcBSFle0FknW3pXa27gSqRk9ko2mtE4eaT1HXD0n5PvHvwJGO9bqrEH0jt7vdDlmJRhlpN+bLyUsdfTc89xeDPBEbMsX+V1b///nkPorZytY9g6OsxtRWlYS6tDZG2mvdPq6Aaln5f5DiDGBKBySLfKB+NjUlcju7DL+64= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730484951; c=relaxed/simple; bh=CRLaBJcbgMnRwxlma4TtUjkzI9nzDDegqxb4hAOa1II=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LHDCoWg9IPbNzv+YfCvyzeVl+SZOxoCxdybaKcgvoWSzaRhzJ3NHkZmaT/1HYk/mseV+O5IRdCfYu9nXWmwMVbkZBsURgOGjjA9ZSUMIt2xphp7038Ax+QWLPv2IhJJi3VaCA2+S4xnkVpTSiI4QrXyuZJ3Jv5IPRS4Y2EImcuI= 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=uEM4odJ3; arc=none smtp.client-ip=209.85.210.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--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="uEM4odJ3" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-71e467c39a4so2822043b3a.3 for ; Fri, 01 Nov 2024 11:15:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730484949; x=1731089749; 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=A+HgrFNy1S3okvh+7az30cmRtXI+hsD3EQs9truFaNI=; b=uEM4odJ3R4z0Htq5/g82UZahx1T7Iioim9lSIE1t3pREdbfXhvRP6b1hNWnB+EP1t8 BcwCl/Oa6DTFLprkXws/5ovIgvdh0pCObTEpD2KfHiCjE54Y/U4ATXQtz6AkAX8QL8Q1 +4nbQq3zpfhTD/XFk4vxHt1Ah8DQR/FvSn+H8bfkXc1SQ5xyK3Tca42BkNyrMHOnabwb H5/fecZDTiFmOE+PVJ/0DyMUYRLx5bZMAxNubFCK9Cz1EkPcPXb93YtddKQFuuG1FqQk iYllhl1dMLa44zfjUywTdjn8wluROg69RCitNZOwAzv9jk1vruNj9aZ8gl6MAfI2ZbBO 6Png== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730484949; x=1731089749; 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=A+HgrFNy1S3okvh+7az30cmRtXI+hsD3EQs9truFaNI=; b=H7lLA7mKBCdRZJfgRhSKS4Nrl0PqsLTZNxW2aBcVS/eeYFBM75jQNHwfm5GgYVVyq4 gTy5uMAic+ZAZPMuxiv/20e1TkZ6vK3zuMAaGYn+Pq3/3EXk1qfSlKR393iIdJaNlrAH LUTduXjMoi8/ygZ+NVBX+gkfgzZrxb/JStXrrA8p7bt1TEkv2Y6f+BLFA/ZadYxX1UOK IB8dcILS11NoL6g2chDK1CTQwO1EKG8SUd8YBsOuIJE4+hXUO8z3SO5Ze5EmA6YrvTUB GSrR65lS+/1Uq5BnMrvsMKNcqTLrMKVsb6blMr4QWvBG4A6lASxv9SqdoA/AdqKiTPRz T7qA== X-Gm-Message-State: AOJu0YwPma5w3NygKEBbLaOq9hcSLcfHh9LwSFHILB526mp24YTbqlvr 4ve+R+seTOGayU8TFvJDXUHr7iGRbJcW21GU5u0tJDITTTMswcHYZS4k2tEwTXOBad1JfRN76fJ Zt7pG1q7uOQdRb/nNFh/I0NOpMpqfskHxLj8qtTSWDaYI+OdVYO/0ksIelnD5WBan9cCzgMwAUq /qT1mS5TQtJFgb7vfiXsAzJQlA+qJLFYyQpjmRz+f6nd1hfFNcAcW2MDqpWkd99XPHwK8= X-Google-Smtp-Source: AGHT+IG7wmlIzLfxL2ty/OwpieTnV1d/2VRca3whn85OUbmznjoBhH3JCc6Z4h0bptq/5GHwpF6DK0NJGNc1d6wq/Q== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:36:e7b8:ac13:c9e8]) (user=dionnaglaze job=sendgmr) by 2002:a05:6a00:8581:b0:720:2db7:c7e3 with SMTP id d2e1a72fcca58-720b9a200fbmr50184b3a.0.1730484948657; Fri, 01 Nov 2024 11:15:48 -0700 (PDT) Date: Fri, 1 Nov 2024 18:15:27 +0000 In-Reply-To: <20241101181533.1976040-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: <20241101181533.1976040-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241101181533.1976040-3-dionnaglaze@google.com> Subject: [PATCH v2 2/4] firmware_loader: Move module refcounts to allow unloading From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@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 , 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 Tested-by: Ashish Kalra Signed-off-by: Dionna Glaze Reviewed-by: Russ Weight --- 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.163.g1226f6d8fa-goog