Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2282495ybk; Mon, 11 May 2020 17:11:54 -0700 (PDT) X-Google-Smtp-Source: APiQypL0/C+VawVyYOeBt2yd93fpzD7Rub+vZltvvK2WwCvw724uiV0Jy8UnpaBfVGQFfqR8VmsL X-Received: by 2002:aa7:de11:: with SMTP id h17mr7577605edv.268.1589242313991; Mon, 11 May 2020 17:11:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589242313; cv=none; d=google.com; s=arc-20160816; b=lZuopZWsMXmyh1GKbUzj+JjQcRvrMxVLULGY7I9oWcRMf8YbF6hRrlm/bbJng+fJwp 7kvBC6FgUC8r6D4eu7QTZ10yq527elULzucrfIgKAGAMs1B3+Hhgxh6VWUrifSRrv485 bTu7upxb7libuBx2IO4acZQUCgXW63WcqAEJ/aw5GCPd2Xt/rHKk0xtXlo6XF7Z/qvLH ZDzTjYPBhWqMGa9UW2ojwNjFHujRxlNg0J5v0kqGftbunVIfypRRcpiTnuqDRGobqqul q855zszYlgd6X9kbZszAmvwSU/ucAxsCAqJ2Khc5A1CMhYjUrI57fi4ZeJa9y4DplZzV pWkA== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=6ZTyQ8XDKXi5cttLPO4Z5WEpujYLcp973KdN3hiRpmQ=; b=AntbC7xBNIZ8JuV7CIRMg9tifFnzG0SrBU2V7OxbQqloVnTl7/oo0xk8fzBmW2KVKi psZu+j60qmVhlAcqgjY9T2AnbRnB379cN3NOBk2zwX5KpnSgiOVtT9muHXRDGbuS/P+w 3iS5tvtRu7c6lE7bJuVXy/jD6ZYnbE9xg3/bvE+S7JtM3C75kZ7MVJXsOxaDPi14xzED 5xB42jkBSfhZmyD7mzFBy0C+7Hp73LQ5Medgk8QXhocK6BZpXSyisbvhrfSZ8T4GyoHM QLvp0Te3rZCOaMqsW1uFlJ9LF0hsg+kOjNtTkpgbyik/2HAPv9FFLj6BAaomh6QS6HIQ zXJQ== 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 22si7039025ejw.409.2020.05.11.17.11.31; Mon, 11 May 2020 17:11:53 -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 S1728303AbgELAJ1 (ORCPT + 99 others); Mon, 11 May 2020 20:09:27 -0400 Received: from mx2.suse.de ([195.135.220.15]:34718 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725836AbgELAJ0 (ORCPT ); Mon, 11 May 2020 20:09:26 -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 4FB97AE9A; Tue, 12 May 2020 00:09:27 +0000 (UTC) From: Davidlohr Bueso To: akpm@linux-foundation.org Cc: peterz@infradead.org, oleg@redhat.com, paulmck@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, dave@stgolabs.net, Davidlohr Bueso Subject: [PATCH 2/2] kernel/sys: do not grab tasklist_lock for sys_setpriority(PRIO_PROCESS) Date: Mon, 11 May 2020 17:03:53 -0700 Message-Id: <20200512000353.23653-3-dave@stgolabs.net> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200512000353.23653-1-dave@stgolabs.net> References: <20200512000353.23653-1-dave@stgolabs.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This option does not iterate the tasklist and we already have an rcu aware stable pointer. Also, the nice value is not serialized by this lock. Reduce the scope of this lock to just PRIO_PGRP and PRIO_USER - which need to to set the priorities atomically to the list of tasks, at least vs fork(). Signed-off-by: Davidlohr Bueso --- kernel/sys.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kernel/sys.c b/kernel/sys.c index 0b72184f5e3e..f9f87775d6d2 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -214,16 +214,19 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval) niceval = MAX_NICE; rcu_read_lock(); - read_lock(&tasklist_lock); - switch (which) { - case PRIO_PROCESS: + + if (which == PRIO_PROCESS) { if (who) p = find_task_by_vpid(who); else p = current; if (p) error = set_one_prio(p, niceval, error); - break; + goto out_rcu; + } + + read_lock(&tasklist_lock); + switch (which) { case PRIO_PGRP: if (who) pgrp = find_vpid(who); @@ -253,6 +256,7 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval) } out_unlock: read_unlock(&tasklist_lock); +out_rcu: rcu_read_unlock(); out: return error; -- 2.26.1