Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp921688pxb; Tue, 9 Feb 2021 16:46:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJzaivitvS6y2UiIj7aWfEVziVupVJt0aN4DWfzMiP/p8ncHGOP3FGWivSHc6J14iLTrWXCH X-Received: by 2002:a17:906:86cf:: with SMTP id j15mr384337ejy.194.1612918004355; Tue, 09 Feb 2021 16:46:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612918004; cv=none; d=google.com; s=arc-20160816; b=UbgVRfnK7T5cjzs2W1WIPrl4Ds2FLIlScqj1u0jf7YxE8EBQIpP1+EFE0nLDYHgM1Y 2nodwxCsOIQz9iJnBlLUqKqYvs4htL5K7XyJBLjlvIAzCKzStPOhkozoB7atBPJ9TOjW Mr2sBBg+NBW5gjJpanNPOge9tE+48lPf27m0sBgJUVW0I0aniQEdyHh1aVHSzn8WA4bX heK4ZmjSNWGH14Q0DSAqkpChk9HGCmvBZ9vA/34QMp5WibWrIR1wAw3oh7gtj7mcPkqg jj3pFlz6x4kCZlJBQDzCyXArzZNeCktcEjsgmsF2vmBTylIte5h7F/uxY3rX8VsKrB/4 CKeg== 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:sender:dkim-signature; bh=ieB/biVTY4vKrZAPByaxJHrLYUL6onrueziYKauUuSU=; b=h1rc5cIlqef6KeV8FxoXcH1zNmZsxVZSJWV1t3xy+VFEmJWTBxbmwU4NUqWdj8QpK9 S4PaS2z0w3oKJIw2TkC0J+rN/sOlKfSdujRArs8F7i2BvxSm+b54fbZO5NeTTA4h5Otr jaFlA0BlbKB0sMB39GtSKQdrUnchs2GMMaLnwhUv8jVsiJAR6ef4wlZz2DtHetQLcCXn cySbzFmxchnFuNmZb55+iz0KE32vaHZaO3Me7VwDY3JiV2KQLuzLtkA9MZfDM1onybfv W+9a9dDUt4T0A9VYQK5Po7W9rhI+y8dGYNPozyRjJQK2TKravAEP5a49NOF20paG9uNU VySw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tZyzAnPr; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v12si184563ejy.529.2021.02.09.16.46.21; Tue, 09 Feb 2021 16:46:44 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tZyzAnPr; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234200AbhBJAnc (ORCPT + 99 others); Tue, 9 Feb 2021 19:43:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233236AbhBIVOO (ORCPT ); Tue, 9 Feb 2021 16:14:14 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7CF5C06174A for ; Tue, 9 Feb 2021 13:13:20 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id e9so2438783pjj.0 for ; Tue, 09 Feb 2021 13:13:20 -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=bOx8LqTbQEbAmvCTSSMXQxccdKnfcf+EoYP0iF3qFibKuyPZJlNvJt2jz5DbcIGnIP VUGIW7290FfU8+0ImnKT5g/fTjp7K/Kn2JPz/Nyed7TaOld57xvJ1uuWuYlYn4W5zoPz EMpXWHYzeymYJjR74uIH0yVvZXNHZkxYSCK9d7ftj05qYjniDJyhieXu4Z7hg3w8u61M XRu3b1JM/8/f0cXEvElpY87Z67VpXzxiqayF7mxH3SSU+A2/F6YjE6tBVo9xalEUc4KX dtpk58dw2aWtzioe3oxTn+lMOQIJLMvY6krLYdNpwZAexws8kaIC5Jk2W/1b3V7Yg69I WgzA== X-Gm-Message-State: AOAM53224ICKiqC4qfjQ4/6MP6UrDlPSIhRFMevVYW9DFYWbp9iU50c9 q7fUhpApqMU9SWrsKP3RE6o= 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) Sender: Minchan Kim 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 */ };