Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2333546rdh; Tue, 26 Sep 2023 22:15:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHcw8ydbcuXU8ypyiJsXLhXN/gWiu5BSDgcDMf7+kyDx34qI7F/e3aHz96eh90Nah8cWqe3 X-Received: by 2002:a05:6808:905:b0:3a8:f3e7:d696 with SMTP id w5-20020a056808090500b003a8f3e7d696mr1199709oih.45.1695791704151; Tue, 26 Sep 2023 22:15:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695791704; cv=none; d=google.com; s=arc-20160816; b=OVX0ftVfyjbXmz05CmukuhBU+/J3fvcgwIW8UKqq5yiorx/mkZYH63wTH/1ZsO6+ry /1bZUJDLx5UNvoyUoaxR9sT+1ruPre14j5IOLTUh3IY4aYlXWebSvrQ1gJVVNJChzCrL g2GjoAB5V3wEa1OeU2z4RMwH+7lqzZhittfGAZbh361L/Hyuef1N1h3suUSWvCVw7Q1o PuWFejrQ3/E0IO36oSxH54YwvnVMrEC/qkOL7Y/jeqtinuZBfRMbves7Cvha/Ae548Ks 2PrrCWQTEWDMIqGKsPBT0fYbOZVGqKT7QWE7weIeSyUXX9KdVfCKGG4Fue831J4cP+X7 d6DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:message-id:organization :from:content-transfer-encoding:mime-version:date:references:subject :cc:to:dkim-signature; bh=K1Yh3nDG2g4QB5OAzmsGSJpI1hCbQI0Q27Pln9I+ijA=; fh=PyDTOu7I5kONiQp8h3+sBxf/BVglOAAFgWhURZ1sb+w=; b=k1jr4weFrQ0/0GHIOBawZXQt2Lq8X+44mZCWtj3+GK+BL7p+m+ocLrIffAw5tgV3Bb cVXsK7fEjHdPykMTl7zW1CqpWzCfANx2PDzWa+rTglynSECi2ycnGhvm3YBP7JghWu3B EK7dqIcMO6SAXHoqkmSrLPm/Ef6HIVMbJxE2HH3R7ANric5EzViz0w6aLeLDp7F1mJhV X2IqKlPFUAzR3kDMf7z/6/5RNp9j26YgXp+RsDO5VcFO+qwDwvzss9XTJoM0n6KbbP7K 2VnRs656M6bYmMqDxt+Z0frzl8wq/LfFY+dxh+2p5cE4I6EnxGPoIdfwnhuQ8eH4Gp1h loPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UxZtPrFh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id g2-20020a056a0023c200b0068beee4922csi15872418pfc.23.2023.09.26.22.15.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 22:15:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UxZtPrFh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 583F68153D26; Tue, 26 Sep 2023 20:42:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229478AbjI0Dmx (ORCPT + 99 others); Tue, 26 Sep 2023 23:42:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230156AbjI0DgT (ORCPT ); Tue, 26 Sep 2023 23:36:19 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6C3A16E90; Tue, 26 Sep 2023 18:56:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695779807; x=1727315807; h=to:cc:subject:references:date:mime-version: content-transfer-encoding:from:message-id:in-reply-to; bh=B4V8UJd1VttRqhaNTVjHfz83p7oeLXpMegVFKtP+eNI=; b=UxZtPrFhuK534xBdP0e4E4LeFaPVRj7IZ8qoYMbOkc5f7KJguxJE2sCM O1kilq1J4ZIbAmyX/EPVdEDAdehmKkwWuSCJNr6g2PmSqkQjX1mUXomnZ Mva4bMlHKR171LZwDpFQymnGENaT/lcI7WK6bySsk/urxR803AeCg6XXQ hV5ZUAhk2NBxGLRkw3oe/1tn2WGIhtGrnu51l5dN7WaE/sMHivf7Q23O0 pjml3dhCCltjIv/Uac334GapizwZkQMkyCZbSmOzlw7BzS0esBiyIpDbH 2vFX6VTVLIbs0swVKuiLWQq4bEkHVWbZZ1dXPSFgCNZoSftmN0W6E+EQE w==; X-IronPort-AV: E=McAfee;i="6600,9927,10845"; a="384488449" X-IronPort-AV: E=Sophos;i="6.03,179,1694761200"; d="scan'208";a="384488449" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2023 18:56:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10845"; a="784156380" X-IronPort-AV: E=Sophos;i="6.03,179,1694761200"; d="scan'208";a="784156380" Received: from hhuan26-mobl.amr.corp.intel.com ([10.92.96.100]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 26 Sep 2023 18:56:44 -0700 Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes To: "Jarkko Sakkinen" , dave.hansen@linux.intel.com, tj@kernel.org, linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, x86@kernel.org, cgroups@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, sohil.mehta@intel.com Cc: zhiquan1.li@intel.com, kristen@linux.intel.com, seanjc@google.com, zhanb@microsoft.com, anakrish@microsoft.com, mikko.ylinen@linux.intel.com, yangjie@microsoft.com Subject: Re: [PATCH v5 01/18] cgroup/misc: Add per resource callbacks for CSS events References: <20230923030657.16148-1-haitao.huang@linux.intel.com> <20230923030657.16148-2-haitao.huang@linux.intel.com> Date: Tue, 26 Sep 2023 20:56:43 -0500 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: "Haitao Huang" Organization: Intel Message-ID: In-Reply-To: User-Agent: Opera Mail/1.0 (Win32) X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Tue, 26 Sep 2023 20:42:59 -0700 (PDT) On Tue, 26 Sep 2023 08:13:18 -0500, Jarkko Sakkinen 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 = css_misc(css); >> > >> + enum misc_res_type i; >> > >> + >> > >> + for (i = 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, >> should >> > > this not have that as an invariant? >> > > >> > > I.e. it might be better to fail unless *all* ops are non-nil (e.g. >> 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 >> 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 instance >> 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 vm_ops are assigned statically, but you still need dynamically assign 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 either way. TJ, do you have preference on this? Thanks Haitao