Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp670669ybh; Sat, 3 Aug 2019 07:23:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzDa7OcqND3h3bJt0IWCoSQ5eF5up3TykzBIkrDejtx5q/JLJ6DoecagzIdHDd4OxyuNyqp X-Received: by 2002:a17:90a:bf92:: with SMTP id d18mr9753786pjs.128.1564842195630; Sat, 03 Aug 2019 07:23:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564842195; cv=none; d=google.com; s=arc-20160816; b=AvNR+8nTcJdnwbWxlytaFNXjD7S8S2Ouzcge5F6pRltF1JmPa3C835Wbb50TcJb7ul 0Z8MZXOKw/tGke5o8pKFeCQWSG5JgheEc+uHHMm5Gv3xkDIIcBRImOTrRw+YT/pPAxUz dwoVNcNqzUusDYDwMwcizCrVI7X//qeeXUM4kjJSk2HDnDI1QjND3zfVQCEKRFImXYKo TF+mccc7+MndICHQrkVCcgOfufKR/8duShHHYoNk7VcNQwK+Q2PHME1X9snRdZjdByi0 40pgu0k3cMHnhhC2KvN5UqGORRbe7ElfArj7y1E+vDxCpuIyczpn5v4MHkndQntrLfoG bhIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=XeZdACcLsfRamGTD+0ui/3XFAY1UUrho8HNdY4Rv0tE=; b=eiRr+0XLSKIIQvgFPT42EXpSUwlzwdJNBYwRrKmDCJEMi7z9AePPhPWJA1wOUIx/yD ngb0KEHGn+EXRzSErJ1NCsI2zzNDijQMbbUGDooV9jpj6h33Y86b+HXBC0sGO96bKGCi 7hQx2ZBNtzZQYmTiWTRWkUPidaRH5K4wVz67LXPRqbTogjgsP+uhyamYPE/Cb6P5/zqr b6aK/Hs8PfWe8aIDU4la+JiBYT8Lrhbz6pKAfsdVMugpf4uNhwXmTiXM/oP+aWEZfIU4 3a6oOCi1Ik3eVKZzw9PTYKOCFIkxfrzRZa43lRrK3n5vxTtPqV12VG3QykbvsRBmnKuR tX5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dg7QIORM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n13si39638332pff.46.2019.08.03.07.23.00; Sat, 03 Aug 2019 07:23:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dg7QIORM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728918AbfHBPKw (ORCPT + 99 others); Fri, 2 Aug 2019 11:10:52 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:40125 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726044AbfHBPKv (ORCPT ); Fri, 2 Aug 2019 11:10:51 -0400 Received: by mail-ed1-f68.google.com with SMTP id k8so72646209eds.7; Fri, 02 Aug 2019 08:10:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=XeZdACcLsfRamGTD+0ui/3XFAY1UUrho8HNdY4Rv0tE=; b=dg7QIORMgbnys+sXltzvNGkxyJMd8mOTaIgtojDmJ5RuN7VgwYYPXTSZJvCGrtQGy2 VfIlIT6ItQ/8ELE0EEepDt6yj2FY1YF2jT0k3YxF3cON6pS9kZ+DvTPb08Ti+YzKuFSM 7LnTwRp0qh7lSeh3nmRJHwtJX1EQRdz4oJhDC3iXk9hNIYnDp9iyO3tMLgy4F0Qc1Geu ntpLQ/HQnWCsk7jQnyHyUZdHZ2sSWOKY06USYW6W+lvmQ9LKRFScNWTG0Bf1m9T0YgLO UEAmf/JE01tsDoC3qGFykarEltjBY5dphLnqH2WJaxa9w+0qghAbvDMsUpNiMxOTWL6D fl7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=XeZdACcLsfRamGTD+0ui/3XFAY1UUrho8HNdY4Rv0tE=; b=cn5Fh+PxWwas/Ep5/s5nIiMXITfHXPVMvZ46FW+i8+1qohVQ+FwFfHREUM8wf1eRGg ScpIrDnId5nhUvxAqp2wEDlm6JQynvcRztoR19CP75DytnHnEojbGbFeoP+Vwe+EKls0 gmGDjZcOfC2k3NTs3kVv4s7lFX5flPvGPnTDFIA/krINh57QtQW9b8ei5qSSRws22WN0 vd4RrluuXpB/gGyHCr7Zru5W6hf4oqI17LfwMyyGm6PkeJDXUptPZPUG3WmGguJ+ioaj 5EMpnpgf6Qxev3Ag3r0s/fAUMkEAu81V1HKpDCv4x2zUirrVRJ/W8cdeDlLvpMemiK9X 5AOg== X-Gm-Message-State: APjAAAXUOVi2mioj4VWWxKQPtQ/XD2CRVPP6JutvhGBBN1yeNQmrLchs bth+Whh5KgIvO56g5VN1BHzBdHyOaaDUKbXsjhw= X-Received: by 2002:a50:b66f:: with SMTP id c44mr119857205ede.171.1564758650295; Fri, 02 Aug 2019 08:10:50 -0700 (PDT) MIME-Version: 1.0 References: <20190802083541.12602-1-hslester96@gmail.com> In-Reply-To: From: Chuhong Yuan Date: Fri, 2 Aug 2019 23:10:39 +0800 Message-ID: Subject: Re: [PATCH v2 1/2] cxgb4: sched: Use refcount_t for refcount To: Willem de Bruijn Cc: Vishal Kulkarni , "David S . Miller" , Network Development , linux-kernel Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Willem de Bruijn =E4=BA=8E2019=E5=B9=B48= =E6=9C=882=E6=97=A5=E5=91=A8=E4=BA=94 =E4=B8=8B=E5=8D=8810:53=E5=86=99=E9= =81=93=EF=BC=9A > > On Fri, Aug 2, 2019 at 10:27 AM Chuhong Yuan wrote= : > > > > Willem de Bruijn =E4=BA=8E2019=E5=B9= =B48=E6=9C=882=E6=97=A5=E5=91=A8=E4=BA=94 =E4=B8=8B=E5=8D=889:40=E5=86=99= =E9=81=93=EF=BC=9A > > > > > > On Fri, Aug 2, 2019 at 4:36 AM Chuhong Yuan wr= ote: > > > > > > > > refcount_t is better for reference counters since its > > > > implementation can prevent overflows. > > > > So convert atomic_t ref counters to refcount_t. > > > > > > > > Signed-off-by: Chuhong Yuan > > > > --- > > > > Changes in v2: > > > > - Convert refcount from 0-base to 1-base. > > > > > > This changes the initial value from 0 to 1, but does not change the > > > release condition. So this introduces an accounting bug? > > > > I have noticed this problem and have checked other files which use refc= ount_t. > > I find although the refcounts are 1-based, they still use > > refcount_dec_and_test() > > to check whether the resource should be released. > > One example is drivers/char/mspec.c. > > Therefore I think this is okay and do not change the release condition. > > Indeed it is fine to use refcount_t with a model where the initial > allocation already accounts for the first reference and thus > initializes with refcount_set(.., 1). > > But it is not correct to just change a previously zero initialization > to one. As now an extra refcount_dec will be needed to release state. > But the rest of the code has not changed, so this extra decrement will > not happen. > > For a correct conversion, see for instance commits > > commit db5bce32fbe19f0c7482fb5a40a33178bbe7b11b > net: prepare (struct ubuf_info)->refcnt conversion > > and > > commit c1d1b437816f0afa99202be3cb650c9d174667bc > net: convert (struct ubuf_info)->refcnt to refcount_t > > The second makes a search-and-replace style API change like your > patches (though also notice the additional required #include). > Thanks for your examples! I will fix the #include in those no base changed patches. > But the other patch is needed first to change both the initial > atomic_set *and* at least one atomic_inc, to maintain the same > reference count over the object's lifetime. > > That change requires understanding of the object's lifecycle, so I > suggest only making those changes when aware of that whole data path. I think I had better focus on the 1-based cases first.