From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78153C433E0 for ; Tue, 9 Feb 2021 21:13:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E51E964E74 for ; Tue, 9 Feb 2021 21:13:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E51E964E74 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3CDC06B0005; Tue, 9 Feb 2021 16:13:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 37F6B6B006C; Tue, 9 Feb 2021 16:13:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 247516B006E; Tue, 9 Feb 2021 16:13:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0020.hostedemail.com [216.40.44.20]) by kanga.kvack.org (Postfix) with ESMTP id 0FF956B0005 for ; Tue, 9 Feb 2021 16:13:22 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C692318548EFD for ; Tue, 9 Feb 2021 21:13:21 +0000 (UTC) X-FDA: 77799980202.05.gun39_530846e2760a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id A3BA518549A8D for ; Tue, 9 Feb 2021 21:13:21 +0000 (UTC) X-HE-Tag: gun39_530846e2760a X-Filterd-Recvd-Size: 6055 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Feb 2021 21:13:21 +0000 (UTC) Received: by mail-pl1-f177.google.com with SMTP id 8so10480821plc.10 for ; Tue, 09 Feb 2021 13:13:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ieB/biVTY4vKrZAPByaxJHrLYUL6onrueziYKauUuSU=; b=tZyzAnPrQGc1sFSnWIDCRC0EgY3zJnF4QDlcn2s5oqdg9vyIvmZDz3Pu49Pbcc+sdk sVeLcMlzjNxwEakd6+kVHpACDecZUmJxmkS/4PFB3t37tVIA9KD8mIHWGJ/fUza211Ba PlvlwOBAlHvJZME0EVbA07AjcsHrDfq33F7oBAjHA2sVfMOpWhVU4dFhBe2m0Bz2SURA dqrUkYh4d7+XsEuehMC+Qcr7Qmq40DitzbnFCxXs9BP5+EJZrlgPVo4iJmwULEc2T1nb uaumwo1iLkrJuX9CR9YHAUkv1TGoqlpLfVrp6E+bvJsuYY49s6ob6WTrkjtilEW+Xwo6 +RXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=ieB/biVTY4vKrZAPByaxJHrLYUL6onrueziYKauUuSU=; b=VJrQ1+1gzRpSUV5a77581FNOMjKMiaBPZx3Vlzm6A221plCgAF6AIDO8HQIs+/+nPv F3dza4Wq3n0g+V/zylO5TS2wMhMhSaE7ztTJ3TDCo4g/3JPDHi5GayjH4lIJ9MYBsuSZ ACsDLLADJGvS0Ttjh1DhLGgPVfIDwnhejB/Thm0TnfkcW18LQNLYhr7vGSlcOWA4AqPP pn7jWU/wRl9h29Gc5hDtEK0xDYHo/77kNQbyUjV9LetZVnfG+tX8BGkaV0ro+FCNCKkj 49jhYZu4UmQTa8irg0UFJNBt5nvinoc5bWAvhjC/6ZcUrZgrM7JenF4pxZ+rjQw5kjgL mReA== X-Gm-Message-State: AOAM533jLJTqW4hFdQ90QQMueDYpitnbWYJD4ER4XIXdIk79w1SdlxeL NAADMGrKpA6gjbWhYdkO324= X-Google-Smtp-Source: ABdhPJw+i7IlVhVSpYlxESYFw3ZKOS7c/pZzlfqzzXVHQ5uOP/aFC9oaDeHKCjREo1S5a5Pzzl6j5g== X-Received: by 2002:a17:902:464:b029:e2:ebb4:9251 with SMTP id 91-20020a1709020464b02900e2ebb49251mr7812750ple.29.1612905200252; Tue, 09 Feb 2021 13:13:20 -0800 (PST) Received: from google.com ([2620:15c:211:201:d107:fbfb:a7c8:913e]) by smtp.gmail.com with ESMTPSA id b15sm160998pfi.38.2021.02.09.13.13.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Feb 2021 13:13:19 -0800 (PST) Date: Tue, 9 Feb 2021 13:13:17 -0800 From: Minchan Kim To: John Hubbard Cc: Greg KH , Andrew Morton , linux-mm , LKML , surenb@google.com, joaodias@google.com, willy@infradead.org Subject: Re: [PATCH v2] mm: cma: support sysfs Message-ID: References: <43cd6fc4-5bc5-50ec-0252-ffe09afd68ea@nvidia.com> <7cc229f4-609c-71dd-9361-063ef1bf7c73@nvidia.com> <09e60732-6a46-dd00-f9d5-4ef17ee685c8@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <09e60732-6a46-dd00-f9d5-4ef17ee685c8@nvidia.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Feb 09, 2021 at 12:11:20PM -0800, John Hubbard wrote: > On 2/9/21 9:49 AM, Greg KH wrote: > > > > That's fine if you want to add it to the parent. If so, then the > > > > kobject controls the lifetime of the structure, nothing else can. > > > > > > The problem was parent object(i.e., struct cma cma_areas) is > > > static arrary so kobj->release function will be NULL or just > > > dummy. Is it okay? I thought it was one of the what you wanted > > > to avoid it. > > > > No, that is not ok. > > > > > > Either is fine with me, what is "forbidden" is having a kobject and > > > > somehow thinking that it does not control the lifetime of the structure. > > > > > > Since parent object is static arrary, there is no need to control the > > > lifetime so I am curious if parent object approach is okay from kobject > > > handling point of view. > > > > So the array is _NEVER_ freed? If not, fine, don't provide a release > > function for the kobject, but ick, just make a dynamic kobject I don't > > see the problem for something so tiny and not very many... > > > > Yeah, I wasn't trying to generate so much discussion, I initially thought it > would be a minor comment: "just use an embedded struct and avoid some extra > code", at first. > > > I worry that any static kobject might be copied/pasted as someone might > > think this is an ok thing to do. And it's not an ok thing to do. > > > > Overall, then, we're seeing that there is a small design hole: in order > to use sysfs most naturally, you either much provide a dynamically allocated > item for it, or you must use the static kobject, and the second one sets a > bad example. > > I think we should just use a static kobject, with a cautionary comment to > would-be copy-pasters, that explains the design constraints above. That way, > we still get a nice, less-code implementation, a safe design, and it only > really costs us a single carefully written comment. > > thanks, Agreed. How about this for the warning part? + +/* + * note: kobj_type should provide a release function to free dynamically + * allocated object since kobject is responsible for controlling lifespan + * of the object. However, cma_area is static object so technially, it + * doesn't need release function. It's very exceptional case so pleaes + * do not follow this model. + */ static struct kobj_type cma_ktype = { .sysfs_ops = &kobj_sysfs_ops, .default_groups = cma_groups + .release = NULL, /* do not follow. See above */ };