Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1617737rdb; Mon, 2 Oct 2023 15:48:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGlaHWUfybKXWOjVGpOGPYa11okiXJNcnkVU3xvoY9lFdtDfWZ+F8wRzkwvZ/nEmKw7HsBe X-Received: by 2002:a05:6a20:1592:b0:138:92ef:78f9 with SMTP id h18-20020a056a20159200b0013892ef78f9mr12845229pzj.6.1696286889498; Mon, 02 Oct 2023 15:48:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696286889; cv=none; d=google.com; s=arc-20160816; b=tQlmFXIPpYW90yRZujGBn/Ww44zdTtPF1IkGvyE38LLxRptIzrMLvROMiv3W9DV48/ 6xFiqLnWioMYost7TuzBosS1Q7Jw84jyxxyyuYnoEhkh+0cmimlOJJIu4mzmqiNrp6Ch EEcTMNQNRSQ1aU7Wzzz1jd8OJoLssjtT7fC6JuMPvPmH0n3i1lw7ePLZca96bEz2D59y Z9AM9jvZh7qr1enlGSoKSSpnX94b8aEcn7UpBMp+O5F709WpySn3OoXrO2KuNMhe86Cg WedS8nOYoNiND/ZYzZwzbojdyaQyCvNLq48RAQgkX6tZu/9pby1m3pQJAF65wCaTLBW+ IBvg== 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:subject:cc:to:from :message-id:date:content-transfer-encoding:mime-version :dkim-signature; bh=X8/MXIKvwpn2KC9EjaEYk9Qz9uBh0IrEkGIBgRZ+eqQ=; fh=nOrggBTNhRh2QnG9zOkWFM4+aibiwiCfCrBZEO/sDBQ=; b=0frZiqOkR2u49zu9AcYBlcu2edtTCsmBqujbRAWD0NazZOlR+vQahJmfvk5GQrcflY zX/IE+DW7m86pJ6TXWjO9U4UrzBL/wI7vh1Ac8PfmC2ID5KslZ4Lqeiwxr7a45hBhkdH xtiJHQ8vvnbD6+MH6KLva8OkbbVFILQANJdSOSl1G1BzSy1AFkHc7KXTDSVhZAoQfeBd L71Lu/FJfVzEaA00tztB2aU8pC1RTfINlasi/dRn1rmD4oeYPZFemVemhxjkTAGvfXYa FJLm+BnyGo0rHpBZFQjSF05flcZBu9Ph+jNj2MKXyuA5NoCP6akiRAoEc6aGXGtxXZoS 0SqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=G+iHZLhJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id f5-20020a170902ce8500b001c446f12975si25317833plg.447.2023.10.02.15.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 15:48:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=G+iHZLhJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 25741801B81E; Mon, 2 Oct 2023 15:48:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236188AbjJBWrr (ORCPT + 99 others); Mon, 2 Oct 2023 18:47:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229879AbjJBWrq (ORCPT ); Mon, 2 Oct 2023 18:47:46 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A819E93; Mon, 2 Oct 2023 15:47:43 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCF62C433C7; Mon, 2 Oct 2023 22:47:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696286863; bh=28kekbe9MiZUa316MRCxUdXRzkm3hMRvIjbqD7/s5i8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=G+iHZLhJB3/4FRAtEYCyZESHh0hPip6cxNlaTyjXlB6JYTzF8XN6GnvnEk+sPOnSm EgcYdfR98TPQmwnGiIBHyR7rHh0pum6Pz3DEk2uRauB6/NXkm9eGn2HUU8eWoJyhBS OqGCwnfoEIiynY5pYtO+ox5GojUkfifjoel/vsx0voArid8oyFQOIeOgAXNnXrbfeP FQhd0vD8qdpeo/X3D3MPmGaNwDGjCI/XQCO7uPlE+fwDZWzfqZYq1dJJ+LZeYC+o9E YCLtoYK6YxY9E2PXxUP3Mbrne+8OEO66b7EzCl75bFVE3amH0ZgCY5bAK/gRx88PWC 7SBTDwOmNOtAw== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 03 Oct 2023 01:47:34 +0300 Message-Id: From: "Jarkko Sakkinen" To: "Haitao Huang" , , , , , , , , , , , Cc: , , , , , , Subject: Re: [PATCH v5 01/18] cgroup/misc: Add per resource callbacks for CSS events 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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 02 Oct 2023 15:48:07 -0700 (PDT) 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 defined > >> > 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 instan= ce > >> as const at minimum. > >> > >> Then there is no need for dynamic assigment of ops and all that is in > >> rodata. This is improves both security and also allows static analysis > >> 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. > Thanks > Haitao BR, Jarkko