Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2871566ybk; Tue, 12 May 2020 10:06:10 -0700 (PDT) X-Google-Smtp-Source: APiQypJPpsbhJzu3+BzSbL9k4Ur5wgqkzZFewfBBRYSkrpVtZXlninv/5+ENZd7fkoZAC+UrNS8x X-Received: by 2002:a50:e8cb:: with SMTP id l11mr19795500edn.174.1589303170282; Tue, 12 May 2020 10:06:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589303170; cv=none; d=google.com; s=arc-20160816; b=ieuXFIvUsVnEECPmawDTIPBVc4XWKV5RvBKGJwzzhhWVG5Chaq/UZ5aUofFq41Thnf F28pXI4tuEZJjlGzvxbC4F5H7YZLgMc3J/S1Csu4cyPBzi5Bc0Nkz0gxw/ivvnqwgR6u ufE9dKuP2nGZ0lFnYk7NFt2+cjUM8n4wXcC9s+WtcogGvVEMI+UNePissSGnuwq48elz yCjbMCdbMq8jWhdQwY2bbmy1AQuIBM1trlU9Gp+GrO6qU6iyQnIBn/2exDF9Ta8ktn2+ 0LK9vvUYWF5UJZZC+fw2Pufttcww/+PoTVsynujZzovcefBhN2kHvvyu9qHZtFixvqFo Zc4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=bMl/fOAUr8vHkT4D9E3wfnXPLUvU4nPgj6yvwFItw88=; b=tAYS3puF9DFl3caQFlb0emMvK93FPlKjFERejq1X2ekRQyfS9l5dXF1Hu6rz9geO6G xq4K5579v0mb+fQ7IS/QBpbpUyCwTvVpVKeWAG+dzvfnDQh3hG5h+oOv5HtuL+M4Js86 KxpcG0nT1mX5s7L7zavzRUk3lI/XBs7RBsQ++Yb0onwfe9n1gWFsC7oXVeAzVwRl7vlI yYpU9otHh8zfPCe7byk1a8BDNJ/GMGqEd/tib6atOBGm6C8E09SNQZ2WslBUfJ6TDAJx doZLlux7Li/7wO9i1NtpUpqCm1R15wiB+2iT4VuWjIp2R8XL+FoQast78YowtnYwUMZd aeVA== 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 h22si5967874ejf.95.2020.05.12.10.05.36; Tue, 12 May 2020 10:06:10 -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 S1727954AbgELRDu (ORCPT + 99 others); Tue, 12 May 2020 13:03:50 -0400 Received: from mx2.suse.de ([195.135.220.15]:48286 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726031AbgELRDt (ORCPT ); Tue, 12 May 2020 13:03:49 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B0C0BAC4D; Tue, 12 May 2020 17:03:50 +0000 (UTC) Date: Tue, 12 May 2020 09:58:24 -0700 From: Davidlohr Bueso To: Oleg Nesterov Cc: akpm@linux-foundation.org, peterz@infradead.org, paulmck@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: Re: [PATCH 1/2] kernel/sys: only rely on rcu for getpriority(2) Message-ID: <20200512165824.t6ktwllqlvkiingv@linux-p48b> References: <20200512000353.23653-1-dave@stgolabs.net> <20200512000353.23653-2-dave@stgolabs.net> <20200512150936.GA28621@redhat.com> <20200512160915.n3plwrwwrlpfqyrs@linux-p48b> <20200512164130.GC28621@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200512164130.GC28621@redhat.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 12 May 2020, Oleg Nesterov wrote: >On 05/12, Davidlohr Bueso wrote: >> >> On Tue, 12 May 2020, Oleg Nesterov wrote: >> >> >do_each_pid_task(PIDTYPE_PGID) can race with change_pid(PIDTYPE_PGID) >> >which moves the task from one hlist to another. Yes, it is safe in >> >that task_struct can't go away. But still this is not right because >> >do_each_pid_task() can scan the wrong (2nd) hlist. >> >> Hmm I didn't think about this case, I guess this is also busted in >> ioprio_get(2) then. > >agreed... > >> > >> >could you explain in details why do you think this PF_EXITING check >> >makes any sense? >> >> My logic was that if the task with the highest prio exited while we >> were iterating the list, it would not be necessarily seen with rcu >> and the syscall would return the highest prio of a task that exited; >> and checking against PF_EXITING was a way to ignore such scenarios >> as we were going to race with it anyway. > >Sorry, still can't understand. The PF_EXITING flag is not protected by >tasklist_lock or rcu_lock. Sorry for not making my idea clear, perhaps it's complete garbage. Right, but setting the flag is an indication that the tasklist_lock will be taken and removed from the list, and therefore we could optimistically avoid considering that task altogether instead of relying on the old copy of the list. It's not perfect, but it does reduce the window in which getpriority() can return a stale value(?). At least this is how I justify it. Otoh this also opens a window in where the lockless version can ignore highest prio task when the locked version would otherwise consider it. So it might not be worth it. > >OK, if nothing else. Suppose that a prgp has a single process P, this >proces has already exited but its parent didn't do wait(). > >Currently getpriority() returns task_nice(P). With the PF_EXITING check >it will return -ESRCH. Hmm? Yes, that would need fixing but you don't seem to be buying the idea in the first place. Thanks, Davidlohr