From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 928BBC433FE for ; Wed, 13 Oct 2021 12:12:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 008FF60E53 for ; Wed, 13 Oct 2021 12:12:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 008FF60E53 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ubuntu.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 7CCCF6B006C; Wed, 13 Oct 2021 08:12:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 77CE36B0071; Wed, 13 Oct 2021 08:12:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69276900002; Wed, 13 Oct 2021 08:12:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0145.hostedemail.com [216.40.44.145]) by kanga.kvack.org (Postfix) with ESMTP id 5C10F6B006C for ; Wed, 13 Oct 2021 08:12:43 -0400 (EDT) Received: from smtpin33.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 1F6218249980 for ; Wed, 13 Oct 2021 12:12:43 +0000 (UTC) X-FDA: 78691302606.33.E35B354 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf09.hostedemail.com (Postfix) with ESMTP id 94C863000106 for ; Wed, 13 Oct 2021 12:12:42 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 482A060ED4; Wed, 13 Oct 2021 12:12:39 +0000 (UTC) Date: Wed, 13 Oct 2021 14:12:36 +0200 From: Christian Brauner To: David Hildenbrand Cc: Christian Brauner , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Vlastimil Babka , Suren Baghdasaryan , Matthew Bobrowski , Alexander Duyck , Jan Kara , Minchan Kim Subject: Re: [PATCH v2 2/2] mm: use pidfd_get_task() Message-ID: <20211013121236.rydqx27bgzh67y4h@wittgenstein> References: <20211011133245.1703103-1-brauner@kernel.org> <20211011133245.1703103-3-brauner@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 94C863000106 X-Stat-Signature: pnu438uidjn8a915rupdrtgewh7wtrj4 Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf09.hostedemail.com: domain of "SRS0=XpQJ=PB=ubuntu.com=christian.brauner@kernel.org" designates 198.145.29.99 as permitted sender) smtp.mailfrom="SRS0=XpQJ=PB=ubuntu.com=christian.brauner@kernel.org" X-HE-Tag: 1634127162-213597 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Oct 12, 2021 at 04:13:31PM +0200, David Hildenbrand wrote: > On 11.10.21 15:32, Christian Brauner wrote: > > From: Christian Brauner > > > > Instead of duplicating the same code in two places use the newly added > > pidfd_get_task() helper. This fixes an (unimportant for now) bug where > > PIDTYPE_PID is used whereas PIDTYPE_TGID should have been used. > > What would have been the effect of the BUG? Is it worth Fixes: or better Right now, there's no issue. I hope my "unimportant for now" gets that across. Retrieving it via PIDTYPE_PID or PIDTYPE_TGID doesn't matter right now because at pidfd creation time we ensure that: - the pid used with pidfd_open() - the task created via clone{3}()'s CLONE_PIDFD are used as PIDTYPE_TGID, i.e. the struct pid the pidfd references is used as PIDTYPE_TGID, i.e. is a thread-group leader. The concern is for the future were we may want to enable pidfds to refer to individual threads. Once that happens the passed in pidfd to e.g. process_mrelease() or process_madvise() can refer to a struct pid that is only used as PIDTYPE_PID and not as PIDTYPE_TGID, i.e. it might be a pidfd refering to a non-threadgroup leader. Once that happens we want to make sure that all users of pidfds are ok working with non-threadgroup leaders. If we have on central helper that becomes a relatively simple exercise in grepping and we're sure that all current callers use PIDTYPE_TGID as they're using the helper. If we let places use PIDTYPE_PID or PIDTYPE_TGID interchangeably this becomes a more arduous task. So in a sense it's a bug-in-the-making. It's arguably fixes the addition of process_mrelease() since I mentioned this pretty early on and requested the addition of a helper as part of the patchset. I think it just got lost in the reviews though. > even separating out the fix? > > > > > Link: https://lore.kernel.org/r/20211004125050.1153693-3-christian.brauner@ubuntu.com > > Cc: Vlastimil Babka > > Cc: Suren Baghdasaryan > > Cc: Matthew Bobrowski > > Cc: Alexander Duyck > > Cc: David Hildenbrand > > Cc: Jan Kara > > Cc: Minchan Kim > > Reviewed-by: Matthew Bobrowski > > Signed-off-by: Christian Brauner > > --- > > /* v2 */ > > unchanged > > Acked-by: David Hildenbrand Thanks! Christian