Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1287165pxb; Thu, 28 Jan 2021 12:27:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwML0UdLFS2T4YSXf3PytzQu/v55hRRWvHGi/kuBqLKJM9MPQDXl7aG08wJ3A5Nopx0wxyy X-Received: by 2002:a05:6402:c9:: with SMTP id i9mr1536695edu.123.1611865646190; Thu, 28 Jan 2021 12:27:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611865646; cv=none; d=google.com; s=arc-20160816; b=xL097a+yXr61x3mVsODzwMWTaXhe7424ip5P9Csptp04IoAEL45kQHavBPgEqPYT2J URU0lOwQH74IGZKkvjFNTBJi4xsEaxD5tzUXVsU9qICanG0wsbp2eF3GLHHn/bVaJG+0 syrFs3re0oO2/5km9XfQJJMJdBOZ7QT+VIMQDMqidDte5QXrKUCMMAKEyh8r3r/CdZt3 P65dOFDIgdkvPimm8tTgwqrxWUcUCZ18lWTkab/FBzoB7G7EPCsTTyNqqUOAqwfmKKvd rE3QcDTBz07u7miXcjoWxj6FPNQSdHzHz5FrQT5mYaI3Ial6+qnUze4wXU3NNx1BDMnj 1BQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date; bh=q7L9iutnOIsaLbi09TuebHI8Anf6UeqkWk9t0PVU44w=; b=iONPVNPBiHPDr5EJ/AgiSwddF/fnpS35gn6afNZ5Q/kqBcBjnLcg9AaI5Gk9Yec7VB q1bdTq5G3MHbNFlwgfDfhD8duLZGJtCiqqGbnyK5ZeDvRC/TkHSu4h5v0T7awXuZJ+bb JgxS1GUxlx2GCoLifJHNduQWZI7C4EZxNQZIaXrDBBwgvaYEKCqEN0T0ajPIURCRiQzE Voe+2jsDxwy5vcN2TibzlokU99R6TJGVP/brZYfvOVtNOZxQmPKn2zamqxnduLXmzKjW UIZZEEcDy91mTIrBAWyYKhss4pojeBlBE7JUShSFbiu6elCIJ0yrivbMxhHN/7alGAT0 4IuA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ga15si3520597ejc.7.2021.01.28.12.27.01; Thu, 28 Jan 2021 12:27:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231201AbhA1UYP convert rfc822-to-8bit (ORCPT + 99 others); Thu, 28 Jan 2021 15:24:15 -0500 Received: from lithops.sigma-star.at ([195.201.40.130]:47986 "EHLO lithops.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229825AbhA1UYM (ORCPT ); Thu, 28 Jan 2021 15:24:12 -0500 Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 036DC6083270; Thu, 28 Jan 2021 21:23:30 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id wydx1ZZ3JqXG; Thu, 28 Jan 2021 21:23:29 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 8E6986083271; Thu, 28 Jan 2021 21:23:29 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id nM_5qrai2wzW; Thu, 28 Jan 2021 21:23:29 +0100 (CET) Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lithops.sigma-star.at (Postfix) with ESMTP id 6A9DA6083270; Thu, 28 Jan 2021 21:23:29 +0100 (CET) Date: Thu, 28 Jan 2021 21:23:29 +0100 (CET) From: Richard Weinberger To: Tomas Winkler Cc: Miquel Raynal , Vignesh Raghavendra , linux-mtd , linux-kernel Message-ID: <1363048722.339069.1611865409332.JavaMail.zimbra@nod.at> In-Reply-To: <10c2e98c393a486cab3bc953e9926e38@intel.com> References: <20210127200319.662842-1-tomas.winkler@intel.com> <1776363776.325713.1611782270873.JavaMail.zimbra@nod.at> <1665542284.336646.1611820031174.JavaMail.zimbra@nod.at> <20210128100032.5eb542c6@xps13> <10c2e98c393a486cab3bc953e9926e38@intel.com> Subject: Re: [PATCH] mtd: use refcount to prevent corruption MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT X-Originating-IP: [195.201.40.130] X-Mailer: Zimbra 8.8.12_GA_3807 (ZimbraWebClient - FF78 (Linux)/8.8.12_GA_3809) Thread-Topic: use refcount to prevent corruption Thread-Index: AQHW9OeD00Da249Jw0qJn6+VIZAeUao7z7AAgAAh5BBxoBSOfPxzntFAEGBJdu//fSiMQP//4NkAAA+XK+AnHY02HQ== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tomas, ----- Ursprüngliche Mail ----- >> As Richard was saying, we are really open to enhance MTD refcounting. >> >> However, the issue you are facing is, IMHO, not related to MTD but to MFD. >> There should be a way to avoid MFD to vanish by taking a reference of it >> through mtd->_get_device(). I don't think addressing the case where MFD >> vanishes while MTD (as a user) is still active is the right approach. > > I think it won't work because MFD sub-driver remove() is called and it must > succeed because the main device is not accessible unlike glueubi which just > returns -EBUSY. Well, the trick in glubi (and other MTDs with "hotplug" support) is not to reject removal of the sub-device. ->_put_device() is of return type void. The key is grabbing a reference on the sub-device in ->_get_device() such that the layer below doesn't even try to remove while the MTD is in use. > so we postpone the mtd unregister to mtd_info->_put_device() but it that state > we have nothing to hold > on as the device is gone in remove() > User will fail anyway, as the underlying device is not functional in that state. > Anyway I've tried your suggestion, the kernel is crashing, hope I haven't done > some silly bug. Can you point us to the affected code? This would help a lot to understand the issue better. I'm sure we can find a solution. Thanks, //richard