Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3393857pxb; Wed, 13 Oct 2021 05:14:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuKRyIbgmXKQ2bn/gb37gM9q7zVTCZ9WcJOfAxAWnHtAk+HNtttlH9f0JnHiFXs/Wwvmkj X-Received: by 2002:a63:dd46:: with SMTP id g6mr27681177pgj.347.1634127284041; Wed, 13 Oct 2021 05:14:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634127284; cv=none; d=google.com; s=arc-20160816; b=d+jSdByE2Mh+53HRdkFNE4IVcmrjyNQ44/aNKIRHRIPRKGUqpUmN2tCP5qyW3VaKUg 4q3bkciwsiAPSqoKtCz6kGzVwZ17j7k0RbVEtW1UhKzpP3zkdrMy3X3i5bazNK5OKnQw qZQbTlozCqx8NQMz7HehUEK5OOCIYJW539ymmxn82l+besNEQG+MkjNvomE2CKDucMbD wR54XAo+2352R+TlwMfc0NLluggWtuy2D00wFoUbgbe8UPFdFbwd1buKSVcfJok8qWuT sgvj2YDEuLbBtXI1JkrOr/OpBpiw2sO/NxGzkGetr3ibmJqaQVrnV+r6yvOURoWV7cqI 47Rw== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=ADU9RaPVzYH1k9s3qRnypUIa11/VHLNEKj6CnGlBQvg=; b=ugHmpvMMpUPF8FfAcxFK1QoumjcyVgRZZ8r1DCzkDQkr7aePMw0hNjC4AoaH+jtybu iTTgM2Jkej54EopvDoqXxRhsd3Kl9C8RJ5n0HDkQW0D4Qu6dZWfnr4IEfHXUsqVotKTc qbNbIYEuqyIDg+vENRTNZKOw2ubOulTewNBdDB9KS9mAWRYcFNUeclVGaVB0UxmwVGXu elf6nOP19RTrZKN2IBhEJTdOxzGqY5ScLlOV2pviceBu6xDd7L3WFS36IEmlsUZcfrVj TLXLQKfCeRoK+rVLZloyZY1xViyKWGaorpIOZtEg8LHjKBfAgOO/RyJGgtAZqb/6b9IP /evg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n2si7057826pjh.91.2021.10.13.05.14.27; Wed, 13 Oct 2021 05:14:44 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231208AbhJMMOp (ORCPT + 99 others); Wed, 13 Oct 2021 08:14:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:58778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229653AbhJMMOo (ORCPT ); Wed, 13 Oct 2021 08:14:44 -0400 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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