Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1508562pxf; Fri, 12 Mar 2021 11:09:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJwN+Dj9JfKRDEBx2rNnO1dmD2NH6ttdZJdVDhkHd/0TE65xzEYqfcxUC2n6WU0vf/2fltJE X-Received: by 2002:a05:6402:27d4:: with SMTP id c20mr16237122ede.271.1615576186600; Fri, 12 Mar 2021 11:09:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615576186; cv=none; d=google.com; s=arc-20160816; b=00P7GLZdoXH27l5C23xlApUqdENL1FZdVVjhzgmJS5WafUuYPZ+h5zQErTsEPZCVOr fxcof8E6Kx2RIXkEU+aM6jJpsCI26lWdX8qb09U96U0b0j03ptLitd/B43LyxT4pZwjA wVI26t4wUE+1Jxs874JpfY/8wbuow/5vPh6g2x9epvuBCJYcEdd1o3pHyEn/JLV68PPI 1x39GvkHTrUo0FNOCxcsJYtuUmu0cE7coM4FSQJv7qZFpqeaCKaRf9vQJHq/bLN2LpO5 w6fZN5rokH/Dtjl7nbLvOS0X1bVC9IMM75MelVRxzQ0RSRL5M+6SExfrD6dXiyZ+to4H TViA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=tJjzSwOgveQ7vdx3Cu3uc6PULmHuHzmVLjdTR0gLlhA=; b=Cft8VP7LAgPdBMXdGn6R66R06AFndwv2OAE+WVKI49NCVDL2S2cEZkt3h96pG6k7w4 d0eEUJxT132lMsl369EKnZzdJ1pP6FWW6hk1lAXCmPMGIUgy+4BGgs+85oaJM+PTXN7u V+PfPCfXcxtybne1vG3BiIQhorsjMmzpiVKF8p/ykFzrMjfzxLjwmDJu6krQtoT4JJGU kFLl34SaOx514fvVSC6+kqvUgDW0N8WorqPV6ygvEQOjNyVMW8YSBdX2Ai88oixyEFyl SZ7BNDvFhsTiGnjXMVY/Au6AQ5d1w0sV+B/vtgU58Dinkbf+lgK9LjrkoUoALdfbPxJp BA3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ntQoBbcW; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w25si5144410ejy.70.2021.03.12.11.09.24; Fri, 12 Mar 2021 11:09:46 -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=@google.com header.s=20161025 header.b=ntQoBbcW; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234164AbhCLTHh (ORCPT + 99 others); Fri, 12 Mar 2021 14:07:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234165AbhCLTHW (ORCPT ); Fri, 12 Mar 2021 14:07:22 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35DC0C061762 for ; Fri, 12 Mar 2021 11:07:22 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id f2-20020a17090a4a82b02900c67bf8dc69so11183639pjh.1 for ; Fri, 12 Mar 2021 11:07:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=tJjzSwOgveQ7vdx3Cu3uc6PULmHuHzmVLjdTR0gLlhA=; b=ntQoBbcWXqtifUBev/B0KOJ7BdEhMcK4Vt5DvxlbjWTaLmYcIzto4hVOQ019Ktjclt IzpMHUC/yiAR42nNISAaWyzIojLrbFqvLiuqfCJeg4pkWHKlQIuqvE/fB5ka2n9/pkxv YKc+kNafGRjUbzhy/8GpyCOkWZhLaF7gTkkwxvjBQ05Zb4MpXjI1NEx/9kHWr5VG/hr9 fyFTu4Dx4sGcxcI4/77RGpWwmxVRidKc9jp2iRX8mPbvdvav/UYKiLxb3Kwnjf/GxyYm jnVuPX8KHdjB2ohJT5DD6zNXt2j3Go/jUeaKAltxlVB+ClDE9O+cvF1HmjxqqD3oE3ec Q9sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=tJjzSwOgveQ7vdx3Cu3uc6PULmHuHzmVLjdTR0gLlhA=; b=HFu3ZC1jBB31EYDY6jzRUN6xu5gCpYxBG5Wyfk4wX8d9V03orxPWS2q72r4UEYp48g H6r0uhpj+DHLUQr240rHFNL9jaDeXGRKlhe6D0yD13twvnNLbW6yRzej0IvHltLJCFCO rcEd5giIVQUOq9HhHlugsPWp8fpqXv7UPhCPMeB6AKajc/JCFdUdVJw7PXKn7rsEUfMD qP6KETZtfdYrVJgYg97cKm4qWHw+aasnb/VjE053A3SbLfzyHPvdfW5VaZZv06cmzsC0 j8WXSN1DzzzJ8neBD/apu0mIRJ6jJCDMhkZJHbxQMfeof5thr5bh+f18IFczqeprPyMw bpgg== X-Gm-Message-State: AOAM530UC7V+X1jz3AYKj0WTn22Ma1XFdZg/QhJZsAnkRsyK4REi0WMD V0cmD+J4GW4Umchz+fa33ahgjg== X-Received: by 2002:a17:902:ba0a:b029:e6:5c5c:d3b8 with SMTP id j10-20020a170902ba0ab02900e65c5cd3b8mr466876pls.79.1615576041235; Fri, 12 Mar 2021 11:07:21 -0800 (PST) Received: from google.com ([2620:0:1008:10:18a1:1d64:e35b:961e]) by smtp.gmail.com with ESMTPSA id b3sm2917024pjg.41.2021.03.12.11.07.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 11:07:20 -0800 (PST) Date: Fri, 12 Mar 2021 11:07:14 -0800 From: Vipin Sharma To: Michal =?iso-8859-1?Q?Koutn=FD?= Cc: tj@kernel.org, rdunlap@infradead.org, thomas.lendacky@amd.com, brijesh.singh@amd.com, jon.grimm@amd.com, eric.vantassell@amd.com, pbonzini@redhat.com, hannes@cmpxchg.org, frankja@linux.ibm.com, borntraeger@de.ibm.com, corbet@lwn.net, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, gingell@google.com, rientjes@google.com, dionnaglaze@google.com, kvm@vger.kernel.org, x86@kernel.org, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [Patch v3 1/2] cgroup: sev: Add misc cgroup controller Message-ID: References: <20210304231946.2766648-1-vipinsh@google.com> <20210304231946.2766648-2-vipinsh@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 11, 2021 at 07:59:03PM +0100, Michal Koutn? wrote: > Given different two-fold nature (SEV caller vs misc controller) of some > remarks below, I think it makes sense to split this into two patches: > a) generic controller implementation, > b) hooking the controller into SEV ASIDs management. Sounds good. I will split it. > > + if (misc_res_capacity[type]) > > + cg->res[type].max = max; > In theory, parallel writers can clash here, so having the limit atomic > type to prevent this would resolve it. See also commit a713af394cf3 > ("cgroup: pids: use atomic64_t for pids->limit"). We should be fine without atomic64_t because we are using unsigned long and not 64 bit explicitly. This will work on both 32 and 64 bit machines. But I will add READ_ONCE and WRITE_ONCE because of potential chances of load tearing and store tearing. Do you agree? > > +static int misc_cg_capacity_show(struct seq_file *sf, void *v) > > +{ > > + int i; > > + unsigned long cap; > > + > > + for (i = 0; i < MISC_CG_RES_TYPES; i++) { > > + cap = READ_ONCE(misc_res_capacity[i]); > Why is READ_ONCE only here and not in other places that (actually) check > against the set capacity value? Also, there should be a paired > WRITE_ONCCE in misc_cg_set_capacity(). This was only here to avoid multiple reads of capacity and making sure if condition and seq_print will see the same value. Also, I was not aware of load and store tearing of properly aligned and machine word size variables. I will add READ_ONCE and WRITE_ONCE at other places. Thanks Vipin