Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4354245pxb; Tue, 2 Nov 2021 08:22:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+2/Gws+KZPYI8rtyCQaX2It6I8MHKPzFjGq2ieX/QYDsnMpWbG75SXDkglfd1KSuBj3Ey X-Received: by 2002:a05:6602:22d9:: with SMTP id e25mr26947500ioe.143.1635866558920; Tue, 02 Nov 2021 08:22:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635866558; cv=none; d=google.com; s=arc-20160816; b=ZchMfoZdRR+jKkQZnad5uFJteNHQjunD+VzDClBN5mRpkfTyBcemyqSTBxZmZwobo8 6Zycupmsrgn2jbxhcFPu4C29CKDqzBznZBgogkZcAGat4Sw3CPjumhsZpMyvl42L8Emd AnNmZvIqEEqEQKkn0mgK0YHpJzira/fIvCxjJoMBrTOHeQ8Ky4FjBttNa1i2VvGTChyZ BvGIOp8b5fHWM17F5jcE46IrewISnYNAYpw20yu8CeF9GRuZ0CLqYXcvV5Jp4VymcaUZ EAYyNa0c6BtRxMhF8rj9dapie3IWLh46Ux/hIjWZOy4beLmjkgc15+dQQkFZbxEPAsZT EwzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=YG2VGNtE+69cPxmqVydtAL5vxJZLZtIYVVth/K03gCo=; b=ot4nI1a+1HDNvg9ZWBhnPVMb2OOoEaaecNj8M1n49qHO+gC/ZoUKgumKeUNXYh0tOR 8W7g63kuNyZSFy76fJibYA5+FEAI69+q6MiAPmqt6QGpk7sNsOhpaNrWQ10t4xe032hG YKAaC779bq9BBWYT4i3GaJGEMvNgFs5P66gjGiRZ4IWAaMrtOwNgSbe5E3ZKGd0JMu7U NDyr/1wUB/+WE2fmqmBSr1LntodQ9qM8WJ0Oa7lvU8dYXTKfaB2W4yJAVT95XRp7PMtr DGHedRdFZRSFA5xr2NSmI2ejUMoAOH5x9MO8L2aWU/Msl85l81+eITxs+YQL76zDI5mG g7Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XSEhU5dX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n3si27667158jat.113.2021.11.02.08.22.26; Tue, 02 Nov 2021 08:22:38 -0700 (PDT) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XSEhU5dX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234158AbhKBO76 (ORCPT + 99 others); Tue, 2 Nov 2021 10:59:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29189 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234784AbhKBO7N (ORCPT ); Tue, 2 Nov 2021 10:59:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635864997; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YG2VGNtE+69cPxmqVydtAL5vxJZLZtIYVVth/K03gCo=; b=XSEhU5dXP0h3cXByjFo2RLYrWRcMFJRi7FT4KBugkHi0HxNJ7g7WJFcWJ0SThp5FCMk25k NS7G1jR/p9SnmhLC0Y7VLaAPdug6/aTfOVJqz1RxeKy5mRKViJaKiVlASjxzL6hUJB9G2T Z53cMEGkPIVdST+x2XxaLrKBvDAmCk4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-487-0K9G4ltAMemdXrbZ-quSRA-1; Tue, 02 Nov 2021 10:56:34 -0400 X-MC-Unique: 0K9G4ltAMemdXrbZ-quSRA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C01F810A8E07; Tue, 2 Nov 2021 14:56:30 +0000 (UTC) Received: from T590 (ovpn-8-19.pek2.redhat.com [10.72.8.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F3B2D60657; Tue, 2 Nov 2021 14:56:19 +0000 (UTC) Date: Tue, 2 Nov 2021 22:56:14 +0800 From: Ming Lei To: Petr Mladek Cc: Miroslav Benes , Luis Chamberlain , Benjamin Herrenschmidt , Paul Mackerras , tj@kernel.org, gregkh@linuxfoundation.org, akpm@linux-foundation.org, minchan@kernel.org, jeyu@kernel.org, shuah@kernel.org, bvanassche@acm.org, dan.j.williams@intel.com, joe@perches.com, tglx@linutronix.de, keescook@chromium.org, rostedt@goodmis.org, linux-spdx@vger.kernel.org, linux-doc@vger.kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, ming.lei@redhat.com Subject: Re: [PATCH v8 11/12] zram: fix crashes with cpu hotplug multistate Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 02, 2021 at 03:15:15PM +0100, Petr Mladek wrote: > On Tue 2021-10-26 23:37:30, Ming Lei wrote: > > On Tue, Oct 26, 2021 at 10:48:18AM +0200, Petr Mladek wrote: > > > Below are more details about the livepatch code. I hope that it will > > > help you to see if zram has similar problems or not. > > > > > > We have kobject in three structures: klp_func, klp_object, and > > > klp_patch, see include/linux/livepatch.h. > > > > > > These structures have to be statically defined in the module sources > > > because they define what is livepatched, see > > > samples/livepatch/livepatch-sample.c > > > > > > The kobject is used there to show information about the patch, patched > > > objects, and patched functions, in sysfs. And most importantly, > > > the sysfs interface can be used to disable the livepatch. > > > > > > The problem with static structures is that the module must stay > > > in the memory as long as the sysfs interface exists. It can be > > > solved in module_exit() callback. It could wait until the sysfs > > > interface is destroyed. > > > > > > kobject API does not support this scenario. The relase() callbacks > > > > kobject_delete() is for supporting this scenario, that is why we don't > > need to grab module refcnt before calling show()/store() of the > > kobject's attributes. > > > > kobject_delete() can be called in module_exit(), then any show()/store() > > will be done after kobject_delete() returns. > > I am a bit confused. I do not see kobject_delete() anywhere in kernel > sources. > > I see only kobject_del() and kobject_put(). AFAIK, they do _not_ > guarantee that either the sysfs interface was destroyed or > the release callbacks were called. For example, see > schedule_delayed_work(&kobj->release, delay) in kobject_release(). After kobject_del() returns, no one can call run into show()/store(), and all pending show()/store() are drained meantime. But yes, the release handler may still be called later, and the kobject has to be freed during or before module_exit(). https://lore.kernel.org/lkml/20211101112548.3364086-2-ming.lei@redhat.com/ > > By other words, anyone could still be using either the sysfs interface > or the related structures after kobject_del() or kobject_put() > returns. No, no one can do that after kobject_del() returns. > > IMHO, kobject API does not support static structures and module > removal. But so far klp_patch can only be defined as static instance, and it depends on the implementation, especially the release handler. Thanks, Ming