Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1620302rdb; Mon, 2 Oct 2023 15:55:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG41vgVCufXxIOTsme1qeCP7CfvBOYkwjofhZkdUGSZgFfsf4NKtQaXXgE9Ri7nrDPUO+MT X-Received: by 2002:a05:6830:1bc7:b0:6bc:b6a6:24f4 with SMTP id v7-20020a0568301bc700b006bcb6a624f4mr14250990ota.34.1696287348008; Mon, 02 Oct 2023 15:55:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696287347; cv=none; d=google.com; s=arc-20160816; b=OWMZI8VxZBjKtm+memCHdr/8WosV7m6jKazm+1kUBmD9mf2f6gMBZ9JfuCY3h2anR4 vtpKp35f7seLas1TNmsZRHlvGPngXlCBWpG1fLLj4sQByv1VqmkdHNdSXidq4oLIGw/e qU/8TvQKrBFki1fBJE9wcgAF2AOnNkEuMSsBkpp0miYX/XyZgwsqtQmFooqYrb1N9FVd 96gm7wSJxsXSevNUUu/m2RuM5DltfSWMP1rX76D2azLZmK37Pe7tSrfx6BKtGRSNvI7u FGNuPWZxntyrPuWF3gdFYTvth/i4HYR4xBin7ba9aliwrTmgOqMVzd+MlqXX6rikCNqQ iSBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:references:to:from:subject:cc :message-id:date:content-transfer-encoding:mime-version :dkim-signature; bh=mkoGSji0f0Geh+ZuwwvnOz/tabixHnzAmnU17+58KTU=; fh=Q/YsNiQBXT4K8k64Eehk/D5IRzjL6qiu6SxLJNuHZMw=; b=OFO4FPvAp+LJ4m2LvoWiP6rzrBZMjjNMEOpdcQa4uiRnOvIeLktMHVoFO+KHuyyh0W eKVxIDWVKDgMUIL1dqIoPirARNBunwE91hKp39vUOXq8XdH+MVbhAgawzhtGgp5qqxXr Yt8lg539qI4f+lWb8zuafWAW2jGAcmeWEiX2HtE5TY5G9UrkZhAE9si4Y3fTmCoYJvUg j+j23z0idqO9XhQ1RLYoQTpD/qVEMt65INq1Th7ctrUWECMrKT8WBM6d5XhgxhA2i6w3 /tdAqscedOJy2L2Y5b96qZ206p+/8ZwwYn0RPkdlTFDmrdU0Jbp/pbw3ocrufOsBXGwk bT+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="EjB/Tpuf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id az1-20020a056a02004100b00565aa20a07asi27968669pgb.683.2023.10.02.15.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 15:55:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="EjB/Tpuf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 2315A804AF75; Mon, 2 Oct 2023 15:55:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236211AbjJBWz2 (ORCPT + 99 others); Mon, 2 Oct 2023 18:55:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229753AbjJBWz2 (ORCPT ); Mon, 2 Oct 2023 18:55:28 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16F84B4; Mon, 2 Oct 2023 15:55:25 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B25CDC433C8; Mon, 2 Oct 2023 22:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696287324; bh=gmdRKizE3oTVXTlKcTqPrbSyT6DkwUQHbEcrgV5Lbik=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=EjB/Tpuf7nIqhQQh1mNjV42RYxAVimZmhMyTZPwNPVZsZM52f4N0/PEqZJd6YeeRO R3ROXTVmszEzYthyI/NuSVmaFAGOlpF0y2mUJ+vGRDkRn07HlFlLnhBTS3OwcCfS5q +ZFRxpWiwsxEI2Cjni5hE3PgB7lFAg8LM0Aki/ZR4bAMXxa6RKJ1BcoFEKV2OiRWgF tHEQF01FW7oS4Th1d7urGTxmJZhv5rFb2lcNDiln2GRLYKBuidRlI5BqD5gudQi55U 3HdUCcsB4wZyFMFfzxKz8tw4DHPCZlwK/Cajw38vdHzl0oq1m1acl6wJpEFL7HXya8 oc5FUEsIgAb2Q== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 03 Oct 2023 01:55:14 +0300 Message-Id: Cc: , , , , , , Subject: Re: [PATCH v5 01/18] cgroup/misc: Add per resource callbacks for CSS events From: "Jarkko Sakkinen" To: "Jarkko Sakkinen" , "Haitao Huang" , , , , , , , , , , , X-Mailer: aerc 0.14.0 References: <20230923030657.16148-1-haitao.huang@linux.intel.com> <20230923030657.16148-2-haitao.huang@linux.intel.com> In-Reply-To: X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 02 Oct 2023 15:55:43 -0700 (PDT) On Tue Oct 3, 2023 at 1:47 AM EEST, Jarkko Sakkinen wrote: > On Wed Sep 27, 2023 at 4:56 AM EEST, Haitao Huang wrote: > > On Tue, 26 Sep 2023 08:13:18 -0500, Jarkko Sakkinen = =20 > > wrote: > > > > ... > > >> > >> /** > > >> > >> @@ -410,7 +429,14 @@ misc_cg_alloc(struct cgroup_subsys_state > > >> > >> *parent_css) > > >> > >> */ > > >> > >> static void misc_cg_free(struct cgroup_subsys_state *css) > > >> > >> { > > >> > >> - kfree(css_misc(css)); > > >> > >> + struct misc_cg *cg =3D css_misc(css); > > >> > >> + enum misc_res_type i; > > >> > >> + > > >> > >> + for (i =3D 0; i < MISC_CG_RES_TYPES; i++) > > >> > >> + if (cg->res[i].free) > > >> > >> + cg->res[i].free(cg); > > >> > >> + > > >> > >> + kfree(cg); > > >> > >> } > > >> > >> > > >> > >> /* Cgroup controller callbacks */ > > >> > >> -- > > >> > >> 2.25.1 > > >> > > > > >> > > Since the only existing client feature requires all callbacks, = =20 > > >> should > > >> > > this not have that as an invariant? > > >> > > > > >> > > I.e. it might be better to fail unless *all* ops are non-nil (e.= g. =20 > > >> to > > >> > > catch issues in the kernel code). > > >> > > > > >> > > > >> > These callbacks are chained from cgroup_subsys, and they are defin= ed > > >> > separately so it'd be better follow the same pattern. Or change = =20 > > >> together > > >> > with cgroup_subsys if we want to do that. Reasonable? > > >> > > >> I noticed this one later: > > >> > > >> It would better to create a separate ops struct and declare the inst= ance > > >> as const at minimum. > > >> > > >> Then there is no need for dynamic assigment of ops and all that is i= n > > >> rodata. This is improves both security and also allows static analys= is > > >> bit better. > > >> > > >> Now you have to dynamically trace the struct instance, e.g. in case = of > > >> a bug. If this one done, it would be already in the vmlinux. > > >I.e. then in the driver you can have static const struct declaration > > > with *all* pointers pre-assigned. > > > > > > Not sure if cgroups follows this or not but it is *objectively* > > > better. Previous work is not always best possible work... > > > > > > > IIUC, like vm_ops field in vma structs. Although function pointers in = =20 > > vm_ops are assigned statically, but you still need dynamically assign = =20 > > vm_ops for each instance of vma. > > > > So the code will look like this: > > > > if (parent_cg->res[i].misc_ops && parent_cg->res[i].misc_ops->alloc) > > { > > ... > > } > > > > I don't see this is the pattern used in cgroups and no strong opinion = =20 > > either way. > > > > TJ, do you have preference on this? > > I do have strong opinion on this. In the client side we want as much > things declared statically as we can because it gives more tools for > statical analysis. > > I don't want to see dynamic assignments in the SGX driver, when they > are not actually needed, no matter things are done in cgroups. I.e. I don't really even care what crazy things cgroups subsystem might do or not do. It's not my problem. All I care is that we *do not* have any use for assigning those pointers at run-time. So do whatever you want with cgroups side as long as this is not the case. BR, Jarkko