From nobody Mon Dec 15 21:42:40 2025 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C2FE212D86 for ; Wed, 5 Feb 2025 20:09:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738786183; cv=none; b=jSDp6UTwAXlp82cPlFKd0gN8R5WdSJLpIHzYEkgJwA5Y6wr78/abpynyXEvjwkNSy+jg73UwW3Bdt5DYBLkiTv/vPlEccu8jY2ktBaDa7EJufBmgFl5OM69Bag3sR9FMjVBzgsRKKeD5qj0fQMZADaqzwpKFW/oOGFfL8Ffm8yU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738786183; c=relaxed/simple; bh=u+0IP/WM+c1HWcevhyhBDP6G4TM3xWdnu+4FbhJH/Kg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JRUQWXKCDdkoCLeH9L5M2rNOxhAhkxH0fmt2JAUMR8k8F9UY8XQECD+X+Aq5e4ccYHgc8hAnQwXZAHqFyTy416/5dMNi0qjb+44cmVACiSuT65podPwv0ZTLfpgwiodKddKdHI2FF3NcNG1sjMOAEQDYgF4U38J5kujzwo57ajU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Tow0J9ZD; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Tow0J9ZD" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-ab76aa0e6fcso27369866b.3 for ; Wed, 05 Feb 2025 12:09:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738786180; x=1739390980; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DaN+NvEOsPAuKb5beMVe5hx8j0KcYxaWgEBiI4mkpQY=; b=Tow0J9ZDHqLIsNIl2eMlxPYlkS73IttDp351moUsL9aIVCCx/PoUvnzw5mtHhPD1SB m+A/wRLRk3F1Ai5+4VWM6FEQ0abSrvgalFnSlcbTgqkkNVzvl1AZXbDovYLgozd0+DkI 8GE2RIMUhaFz5/Ij0Agon4w8KfrPvoYvuGgHISIYqk7a4upIh4qn3df3Cej0rHXRwOf5 fPvo4ch0yiXiyNfFYp9iJgTs7+dEZ0PBLWBeAlZDWX63sCJL1kOfxpG6DQerNZJfVA3Y 8dlQvij1atz26eCEuu0kwZA6nq7bS/MFYYq7KU4hZUus43M82y0mkcxSjHpT91Gick6r Lbig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738786180; x=1739390980; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DaN+NvEOsPAuKb5beMVe5hx8j0KcYxaWgEBiI4mkpQY=; b=h7nL7p43wAwfdakKV8TX+V/FdSxEjhl/iSaH70238qVnUFWaatEMyNZtZxv7Chsx0N Idm5KQcupq8PwUSoLbcRCd+rQ2EJrp1JKwjGvi8ZgtJwjUzBcRBjJ2BvUXhhOeDrXADV xHeJ7uRQBJ56T6sqxBUIzMzcRlmd0FYa3vyDKp1Jl4kx1/CY1YVrPGJh87tHJLG+TVJ5 2dsdmcglT5bTpIwTMgdVFpLufFyHWF+0i7ZwJ8ZLGa7B57Cb7SOoA2fFHjSdVzMDqGZ3 bj+IqKJGWbjW2qayiOiIiILm5lbjev131csctLsXGo5jgac2Kqkgwl8MHSeCugeMrPLI 49Rw== X-Forwarded-Encrypted: i=1; AJvYcCVfIia+yp1sIaqcD45wpQ+vqu9usdSEjHsnhDYI1OmJchAA3ozjDFSxvTmxdcEkGE0hngYco7GVXAYHH6M=@vger.kernel.org X-Gm-Message-State: AOJu0YyYipAJZTsQW7x5TyJozSmBl9hShNMdsdrYwgeoAs4XiwSEB9Sy +6Fg9XSg57brEyHSludj/U8/84P+f5gMhUnIS6OwPilaloeLDPvA X-Gm-Gg: ASbGncstkEk3x+r/EAL9Th9hqlkRjhQHefXhJgNlbspliobPk1GrWeWXW1tjBcjUddm n8HNE/asaMJH11EbpbY+jhWcv5uPpomyV1Xw91k/A7wUVTNg9UOdngPB4N0ndR/dUZJaxzV6JrY cjk7xH88NQRbfx3L7iaYiXZBms1HMD/z362/L3E2GlcvsYbKTrc9WMGweQdtA11qdAngOqf0KZk a/tiCuR/u6bG0bkI+GJP2/b78o7Snj0LEKPeqTPuNDNT2IJS3vlrb4hvrqjvhl536P06WGHpvDb 1sxMDclQWk2wkPoFRYrZhzFQaMectfc= X-Google-Smtp-Source: AGHT+IGToc/kGWkzde6y1XJ2Iuyq2BTibRMDiLOdIZo2G0z5rfjdXFqozq1t+u7xhnldZvZXHFGMDw== X-Received: by 2002:a05:6402:401c:b0:5db:e91a:6baf with SMTP id 4fb4d7f45d1cf-5dcdb712a06mr11388909a12.14.1738786179154; Wed, 05 Feb 2025 12:09:39 -0800 (PST) Received: from f.. (cst-prg-95-94.cust.vodafone.cz. [46.135.95.94]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab703fbcc0csm932221866b.53.2025.02.05.12.09.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 12:09:38 -0800 (PST) From: Mateusz Guzik To: ebiederm@xmission.com, oleg@redhat.com Cc: brauner@kernel.org, akpm@linux-foundation.org, Liam.Howlett@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mateusz Guzik Subject: [PATCH v5 1/5] exit: perform add_device_randomness() without tasklist_lock Date: Wed, 5 Feb 2025 21:09:25 +0100 Message-ID: <20250205200929.406568-2-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250205200929.406568-1-mjguzik@gmail.com> References: <20250205200929.406568-1-mjguzik@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Parallel calls to add_device_randomness() contend on their own. The clone side aleady runs outside of tasklist_lock, which in turn means any caller on the exit side extends the tasklist_lock hold time while contending on the random-private lock. Reviewed-by: Oleg Nesterov Signed-off-by: Mateusz Guzik --- kernel/exit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index 3485e5fc499e..c79b41509cd3 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -174,9 +174,6 @@ static void __exit_signal(struct task_struct *tsk) sig->curr_target =3D next_thread(tsk); } =20 - add_device_randomness((const void*) &tsk->se.sum_exec_runtime, - sizeof(unsigned long long)); - /* * Accumulate here the counters for all threads as they die. We could * skip the group leader because it is the last user of signal_struct, @@ -278,6 +275,9 @@ void release_task(struct task_struct *p) write_unlock_irq(&tasklist_lock); proc_flush_pid(thread_pid); put_pid(thread_pid); + add_device_randomness(&p->se.sum_exec_runtime, + sizeof(p->se.sum_exec_runtime)); + free_pids(post.pids); release_thread(p); put_task_struct_rcu_user(p); =20 --=20 2.43.0 From nobody Mon Dec 15 21:42:40 2025 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC93020F068 for ; Wed, 5 Feb 2025 20:09:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738786184; cv=none; b=rraBch0QhHHWq69WX8NWjQciL9AAwLNNTEZA+4J8kl1sZ70hV1pHqZGd4815HdrdlG8dNERiRADQgHkvWFqqanShNeSr/5XjQFiQ4DKcPwI1i21Gr0hhBAaBhIvoHJqWEcZmnF/5CRSRaiQumZ1aL6rTrD4fm4dMuZD5s+EG1Mo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738786184; c=relaxed/simple; bh=p9IfmBkML/+h4zidU1zNnqGBFIPCMEc1S9CanTk6ZQQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SICuMzvq5afzuMT9oHIn4DXNLCs1/SYL6epXhywtc4tca9qkc/F2uGVsAuS2Ao0l9DxH53wSSlSBX7NAiyVW9B+WbZ28crbRrHVQqeJQ+jIO82EziJk+nQjFRDCAwCJkRkoyLHdxE9xO1WptMNG83McEsIyn2ZX+UYwSwaiBWog= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jgzr48WF; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jgzr48WF" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-ab2c9b8aecaso40084666b.0 for ; Wed, 05 Feb 2025 12:09:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738786181; x=1739390981; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/diWf3Ne11QncyO86if84fhx289XRB6QA3E34QVttl8=; b=jgzr48WFy1Ig5uI40OCDmoBHvCELXRQF55dt018aCCMEco7cq6MDrIlRMgLVpzwmFX 0zeToafHll2GIgleE9RGVmu4gzLOoSWipe639GyfYFcgkltOAuYOcQ/HbdvI8VvTbVdn 2SJXxTWHjFQpZePSVaZ9TsnUDKzBZJty/YsISGZR5FcXB4sQw9DjB/h/WHCoEvGME4IY 10g7n8+D/LQYzivQ/eobk8MFcSnqXvIB5hVFBJnWbpMlLHGgtwiu2eSj4mVAPA0tooui JSYz5b27gblYrw07jUvmE9ME+FhlBpPcJGgFICCdYtytLHBxDAqMalFM3vYZlPxurLfj UUyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738786181; x=1739390981; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/diWf3Ne11QncyO86if84fhx289XRB6QA3E34QVttl8=; b=o8EW/4PL6xVmxuCckLWM3qPnVrc4hvyvd+4ZXobHJ8gGf3qmGHS1Wlqoiz1CT5d/No udlOJxmfq2NOkraitVfPKleq9aR03x4kxIRu4CQs79LyvBO/NhBY2yrckAygGLaisqav LRbFgLQD0RkMb4k2KPtBZvXrr97KVbmj0VLYpvwWKtuerXycAg8wO9dscG8R7wrCjxef VmtdsjAVLnsxN/ZzW199XRs9ocP8MSRfuEylkK/2xqGezx31iks9hQri1Dv4U4+CDW7d PTv2agmVk8NYps+xrMkeD8iXVPV/JZA/H9WgVXD8s3FCU6DUUE5CWItt26eYvFYuFTT+ 5Eeg== X-Forwarded-Encrypted: i=1; AJvYcCUUxnZsemiQYs4LULZb30itzb394GNBmBfOOg0wmbfDZs+tFTfHOlhG/ViNH5gQS66cNuY9wTMnVtJo0R0=@vger.kernel.org X-Gm-Message-State: AOJu0YxgO6FhakwQkBSoBo6/UBKU8i4wog556bnZ4xY7QQo7avTaGQM8 Gbqn03GnNkzK4pVHbrNkvqtbvQ1Gut3z2UZthxlO2LtrS/S+1VCD X-Gm-Gg: ASbGncv6AzGe9J+n5uWP8jjX4l69NUz2dV3RItFIUZsyMHA5AsNtP1IT4IxjSnY/iCC McxjTM0FR3vpBRW2xccoBEwosj23g8GVrgbsyM4yQLR42Oaxy6l7G5ul1lJdTJtD1BuFJKcnooS 2QD7LQlUOCEnjc/FclZFhuv6YNz80t05nJFYypd3ivr4ZQkltt1fvE1Hx0XHoz9qJBoA/Y+g9VO xvTWVvt7mc0vyM9wTlPv79uwsicRiY4/4eXUy/Fn4+ySWH1EAwECTXMJbkxb3xqLYT3YICn4xYN ZdLhmJPA/1PzHg7sKtRMqfk7t1BydgM= X-Google-Smtp-Source: AGHT+IHhm2J6TejI3Q6Hmp1UNNqGIH6Qdf4lJY6zmYuaoxwWi9cVhTvNKwZHZvNjq8bgfHO1UeNWVQ== X-Received: by 2002:a17:907:8692:b0:ab6:d547:da9b with SMTP id a640c23a62f3a-ab75e23c77amr411221966b.23.1738786180759; Wed, 05 Feb 2025 12:09:40 -0800 (PST) Received: from f.. (cst-prg-95-94.cust.vodafone.cz. [46.135.95.94]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab703fbcc0csm932221866b.53.2025.02.05.12.09.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 12:09:39 -0800 (PST) From: Mateusz Guzik To: ebiederm@xmission.com, oleg@redhat.com Cc: brauner@kernel.org, akpm@linux-foundation.org, Liam.Howlett@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mateusz Guzik Subject: [PATCH v5 2/5] exit: hoist get_pid() in release_task() outside of tasklist_lock Date: Wed, 5 Feb 2025 21:09:26 +0100 Message-ID: <20250205200929.406568-3-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250205200929.406568-1-mjguzik@gmail.com> References: <20250205200929.406568-1-mjguzik@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" reduces hold time as get_pid() contains an atomic Reviewed-by: Oleg Nesterov Signed-off-by: Mateusz Guzik --- kernel/exit.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/exit.c b/kernel/exit.c index c79b41509cd3..b5c0cbc6bdfb 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -248,9 +248,10 @@ void release_task(struct task_struct *p) =20 cgroup_release(p); =20 + thread_pid =3D get_pid(p->thread_pid); + write_lock_irq(&tasklist_lock); ptrace_release_task(p); - thread_pid =3D get_pid(p->thread_pid); __exit_signal(p); =20 /* --=20 2.43.0 From nobody Mon Dec 15 21:42:40 2025 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0529B214221 for ; Wed, 5 Feb 2025 20:09:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738786186; cv=none; b=cvUH/EctwALW8nYvbUu5hkwC0sU8ebJFKP+LRiXbN8Ye7yEjmNmHCnBxlrFqFkAqD+82VjEpIO+8vDnOxPn2M8Q/SsRTGqG9pp/JV3/KcHHnS7pkdcuQnaH8GxiVopmdPI0NDFqORCis23nT96yOmG97CS5dltUayfAcTD9VRY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738786186; c=relaxed/simple; bh=8ylPtGjmg8BqUJh8ssxlycLuhNCMbKhKYTzosnppwMg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t1RKtytilsK4Cpm2gKDeMMcFDI4mqL7afQh3SBFh5rYv1ur5EOpQZYJAFQEGF3L4eCxKvwS5GSGtRA+86aEXsyDcfSCOloXAGtnJjP4VW/Z6BEGT3Z7G29cViyk3eZZ1BvgKV5hsXAeRwY8hhOR7XfeCFEK7+JVBIEHxQa9QQAk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Kia9j16z; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Kia9j16z" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-aab925654d9so37885766b.2 for ; Wed, 05 Feb 2025 12:09:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738786182; x=1739390982; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pj3pWrosGkUlfXcIPyDNQK+jIHHC44medwj1pRwHHC4=; b=Kia9j16z+dKBciWAtq/A2Mwefy8++jcKaPAvNB5PdDgTJb/Zw8eHCy6ubuwOR1Dj/i iOh0fgnaEHM7cZZTi2QuWoEhvT2CH7eRnQs3e6ZzHdjlxsertH204VRio5uy4g0lGeN7 E8N31D+fGLUTyxbTe0nGM8cB/lre/2KQrYrLvqqJpWrKUovcoGts2bXt+ZQI5ABwtiC8 35+h3cBHEzsPNPhSpW9y9EGPAgtEzbIZ17XH/AVv3JiccGe69o9K64AgnHCoinhP/oLH z3qjZQHkuDHMLjYtzWOyuWh5+3ucN/k70ikbbivtuCboHgyLJyXEDq02y+VJVVmUBLZX dDlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738786182; x=1739390982; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pj3pWrosGkUlfXcIPyDNQK+jIHHC44medwj1pRwHHC4=; b=R+fj5SFywcMrwNQhU6wnrgAOoa2j9MAYi0s6cXtHY9HMKON0jyhOK2TarOIHmTmGps Ibq0LcK0GsGVzDEEBbuGXrFQP/B1aLd7CocpbfKZbZK6psFU/wyaoAMmfLFlrfNDMoq5 ZHf+vEbY5BoYzo3NQJY22Xr4McXCy71xyTd511KK5QVcAEOmuxT1inxKCnWztXt2fxu1 fqfvBcjG2qKAWC0lyU+gQ4qAckDYYDtYlGrvc2LpnG3wewazrq0tczbhZOncOF8YAm6t xvGVtLqwapko4+H+QORApu8I8i252YrThNh5Hu51TDW29fjg4jkJULumPm0B25ay0QE5 ZBaA== X-Forwarded-Encrypted: i=1; AJvYcCVIDIapKC79FX0LALmOCGar1ZE2NsN2pbJlpDlekwXbTDEGSWIQzlmJHEjX+a3H508G3Q90CQl+lOqtyyI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6W794oqHAfYSA4mHvlOyC7FG9SIF2G3bWlXHZd2eHKMSSNK+Q ZVKj2xemj/kUswCNzTO7YWAwPh1KVukKSGpC3d1ed48y9BiQLmSz X-Gm-Gg: ASbGncvlomJm5R4Ax2/xY4HXCLGFJhmc2pGaNW6hjozCVJHEXp5V0hR2XYPPvnyzTGr jThowTMA8dOII/WCGt4KvUZGsOgegOAMlxV70cE8JDkWUyEboF3jWmgy5qUHR5xhv9pygNm/lsB Z2JtQCo2/CLONcxMrPET8FBPv796ae3goYZARBhbm49ijniwwMZAQjYRi0zG5E+WeSsB8KURIPE l4yu1kCBZFriRlAhwEmXxhsB5OOJSu+N9jtfAO0+kFPpl6w1a6IuNmFDWWBHk4cbuO/uKg/jlDU u+rISRl7KyvLs6C2l/cMScParoI/k0U= X-Google-Smtp-Source: AGHT+IFgTBn5lP4dqU0ydTXpkrpjieHD7lv/hSESjvAyOOi9Zo+cwux8FPWnWR43OTCyLUkzOvro/Q== X-Received: by 2002:a17:906:6a04:b0:ab2:b936:f110 with SMTP id a640c23a62f3a-ab75e241f9cmr455031666b.20.1738786182011; Wed, 05 Feb 2025 12:09:42 -0800 (PST) Received: from f.. (cst-prg-95-94.cust.vodafone.cz. [46.135.95.94]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab703fbcc0csm932221866b.53.2025.02.05.12.09.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 12:09:41 -0800 (PST) From: Mateusz Guzik To: ebiederm@xmission.com, oleg@redhat.com Cc: brauner@kernel.org, akpm@linux-foundation.org, Liam.Howlett@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mateusz Guzik Subject: [PATCH v5 3/5] pid: sprinkle tasklist_lock asserts Date: Wed, 5 Feb 2025 21:09:27 +0100 Message-ID: <20250205200929.406568-4-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250205200929.406568-1-mjguzik@gmail.com> References: <20250205200929.406568-1-mjguzik@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Reviewed-by: Oleg Nesterov Signed-off-by: Mateusz Guzik --- kernel/pid.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/kernel/pid.c b/kernel/pid.c index 924084713be8..2ae872f689a7 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -339,17 +339,23 @@ static struct pid **task_pid_ptr(struct task_struct *= task, enum pid_type type) */ void attach_pid(struct task_struct *task, enum pid_type type) { - struct pid *pid =3D *task_pid_ptr(task, type); + struct pid *pid; + + lockdep_assert_held_write(&tasklist_lock); + + pid =3D *task_pid_ptr(task, type); hlist_add_head_rcu(&task->pid_links[type], &pid->tasks[type]); } =20 static void __change_pid(struct task_struct *task, enum pid_type type, struct pid *new) { - struct pid **pid_ptr =3D task_pid_ptr(task, type); - struct pid *pid; + struct pid **pid_ptr, *pid; int tmp; =20 + lockdep_assert_held_write(&tasklist_lock); + + pid_ptr =3D task_pid_ptr(task, type); pid =3D *pid_ptr; =20 hlist_del_rcu(&task->pid_links[type]); @@ -386,6 +392,8 @@ void exchange_tids(struct task_struct *left, struct tas= k_struct *right) struct hlist_head *head1 =3D &pid1->tasks[PIDTYPE_PID]; struct hlist_head *head2 =3D &pid2->tasks[PIDTYPE_PID]; =20 + lockdep_assert_held_write(&tasklist_lock); + /* Swap the single entry tid lists */ hlists_swap_heads_rcu(head1, head2); =20 @@ -403,6 +411,7 @@ void transfer_pid(struct task_struct *old, struct task_= struct *new, enum pid_type type) { WARN_ON_ONCE(type =3D=3D PIDTYPE_PID); + lockdep_assert_held_write(&tasklist_lock); hlist_replace_rcu(&old->pid_links[type], &new->pid_links[type]); } =20 --=20 2.43.0 From nobody Mon Dec 15 21:42:40 2025 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECADA214803 for ; Wed, 5 Feb 2025 20:09:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738786189; cv=none; b=ZOZdl2dIPCWk4/PBLN+iIa5nJH0TddxF35HKLDkq8ltc5xAgC6NLKKnNuNjGatD8C1S9eswX9zV6sFJi6hSQPmn9fLnVJC+3qUY2H6j3kwnuvi1APhiA8wo6NRsuHRURit4SefMq2y5jxoUBBGPR57hgz/wyoU3i3EMuWuUnG3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738786189; c=relaxed/simple; bh=W3Pd3CkKGyvgAPPYybzEKfQFA7hQ9I4yfPvIKYI3E9k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oA3vh7jFYakucQOiKSLfqyGqbh/jTuE61vpj+7KCOyAHB5VZQKlSHxowRMbW+ZeOojdD/daFmfyLlttQNqPYPsMwrPpnq7UgkqsDk2GDvkpuQ1eY4JbU+CXL2vECEbDXUq5rB0oNfbGvlPR692OoSSmAYoIoGCVZu3iFogxEdn4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SSWoQtbn; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SSWoQtbn" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-aafc9d75f8bso40603366b.2 for ; Wed, 05 Feb 2025 12:09:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738786185; x=1739390985; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UXXHLc4u2eFHoy15ceLKQBCXMdX6jJSCsW2EOllr/as=; b=SSWoQtbnoCWwOQkzjCqed4sGZSf6Qgw66uDRQOATdT0aD3kscR6pSL1Afkj/6rRcuT sdgH1EB3ZFF2d+vzq2+RpmlSzHZ3wU8qsl4ygBGP161c6Fko7++9anHQ7fPqEdfI/QYe qWeplKb3o2xFchF4rJj7T2oVmY2r/I//7BsSszjLrM++IHyH9fW+zt2Bu4hbblJ7Kmj/ rAeOk574IijadYC0MAiuqtLV9zYYpFzXLmfrhDvbY1ocU3EMs4YjrvchDLikk1EqPo4o n5VRweWzIQrDnU5W4h3/dULwFApBZptbh+0X0MPqexSd01EyvvoRwJ/QYfJgqMJEpQW7 YKjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738786185; x=1739390985; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UXXHLc4u2eFHoy15ceLKQBCXMdX6jJSCsW2EOllr/as=; b=M/wfiyRlfBD9E36OSBQG8ZPwNEExso1KQrb7z0Ijh3nHA/sUh2KRYfUq/1ZIjMA2Uy qBRLcXV7y+sybId0Asybv62bGw0W58Qj3UkmgKiSSuPWRVCpjM2yl/UejAOMvZuGYVGK JxBoX0+NLv3jndsuJUZkCVBXn2EF8mtYmky0KyQvg0sdADv0GYiE/OUBDN4FsUOPUJsI PlXbTjr7Es9N3bAP/p4q65yXKIGcFxN6H0vfm27f3DaWnAzMB2KJ8+CRbB6Lku7yp8nD IT7emNqUAuyaQ7jCbZ+SJPZndRKNBa7PTlz4q7vb040pMe6Gv9EKYOyr9CtKFatv/QnJ i60g== X-Forwarded-Encrypted: i=1; AJvYcCXldyaGzk1+WPzgchNHRWBeGGTSJAj0gDUIWWJp+9SiUZu91dudhtNFvKcAIKBYvYSc+l39WMHwLKdwsQk=@vger.kernel.org X-Gm-Message-State: AOJu0Yz+r3/k5RzWEQXem9vHACkL7w3qLsCYUOle3C93yTxaa8z8KxvB 70+Ysxo+8V0zEw2FOfpricfPX5XpsZELD9d01J4z08Mxwv2iu290 X-Gm-Gg: ASbGncsMVL1KPmQO6Z8lWejnRSSG08otP2JbgTnHUArtEA1BbGHiXRA+EntnXsjZwVd XXHE4aF3kCJSJht/DkGXmjAsCAnmmR6uDO3YtCZJMxhi9n8zwf8edlcHp+e1GkkX/bHeXOwcArr EQawdUylERM0pcpzFji/PUfgEs+rJ9tyiOna5oyc3aVpdiRbBX3vzQr+l7SvWLEdtpojapdDfEI LRNPzCpDgX/CRW2taZd1fE4ZYV8plIaiixMKD2S8HIcpQzeNj9H6K1zQ0HvlHixYh4KeiOHZcbm KCAutjVQfrqSo/n0FKJuFcxup3cPpyQ= X-Google-Smtp-Source: AGHT+IFDmULsBHl9yMwJRJbGHgVNOKJAub6H9YT0BDzPSTc7XIU9hNIyfZX4Cm4lZOh8Lcspw1U0/w== X-Received: by 2002:a17:907:96a2:b0:aa6:9198:75a6 with SMTP id a640c23a62f3a-ab75e23ea38mr444140866b.21.1738786185031; Wed, 05 Feb 2025 12:09:45 -0800 (PST) Received: from f.. (cst-prg-95-94.cust.vodafone.cz. [46.135.95.94]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab703fbcc0csm932221866b.53.2025.02.05.12.09.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 12:09:44 -0800 (PST) From: Mateusz Guzik To: ebiederm@xmission.com, oleg@redhat.com Cc: brauner@kernel.org, akpm@linux-foundation.org, Liam.Howlett@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mateusz Guzik Subject: [PATCH v5 4/5] pid: perform free_pid() calls outside of tasklist_lock Date: Wed, 5 Feb 2025 21:09:28 +0100 Message-ID: <20250205200929.406568-5-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250205200929.406568-1-mjguzik@gmail.com> References: <20250205200929.406568-1-mjguzik@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As the clone side already executes pid allocation with only pidmap_lock held, issuing free_pid() while still holding tasklist_lock exacerbates total hold time of the latter. The pid array is smuggled through newly added release_task_post struct so that any extra things want to get moved out have means to do it. Reviewed-by: Oleg Nesterov Signed-off-by: Mateusz Guzik --- include/linux/pid.h | 7 ++++--- kernel/exit.c | 27 +++++++++++++++++++-------- kernel/pid.c | 44 ++++++++++++++++++++++---------------------- kernel/sys.c | 14 +++++++++----- 4 files changed, 54 insertions(+), 38 deletions(-) diff --git a/include/linux/pid.h b/include/linux/pid.h index 98837a1ff0f3..311ecebd7d56 100644 --- a/include/linux/pid.h +++ b/include/linux/pid.h @@ -101,9 +101,9 @@ extern struct pid *get_task_pid(struct task_struct *tas= k, enum pid_type type); * these helpers must be called with the tasklist_lock write-held. */ extern void attach_pid(struct task_struct *task, enum pid_type); -extern void detach_pid(struct task_struct *task, enum pid_type); -extern void change_pid(struct task_struct *task, enum pid_type, - struct pid *pid); +void detach_pid(struct pid **pids, struct task_struct *task, enum pid_type= ); +void change_pid(struct pid **pids, struct task_struct *task, enum pid_type, + struct pid *pid); extern void exchange_tids(struct task_struct *task, struct task_struct *ol= d); extern void transfer_pid(struct task_struct *old, struct task_struct *new, enum pid_type); @@ -129,6 +129,7 @@ extern struct pid *find_ge_pid(int nr, struct pid_names= pace *); extern struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, size_t set_tid_size); extern void free_pid(struct pid *pid); +void free_pids(struct pid **pids); extern void disable_pid_allocation(struct pid_namespace *ns); =20 /* diff --git a/kernel/exit.c b/kernel/exit.c index b5c0cbc6bdfb..0d6df671c8a8 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -122,14 +122,22 @@ static __init int kernel_exit_sysfs_init(void) late_initcall(kernel_exit_sysfs_init); #endif =20 -static void __unhash_process(struct task_struct *p, bool group_dead) +/* + * For things release_task() would like to do *after* tasklist_lock is rel= eased. + */ +struct release_task_post { + struct pid *pids[PIDTYPE_MAX]; +}; + +static void __unhash_process(struct release_task_post *post, struct task_s= truct *p, + bool group_dead) { nr_threads--; - detach_pid(p, PIDTYPE_PID); + detach_pid(post->pids, p, PIDTYPE_PID); if (group_dead) { - detach_pid(p, PIDTYPE_TGID); - detach_pid(p, PIDTYPE_PGID); - detach_pid(p, PIDTYPE_SID); + detach_pid(post->pids, p, PIDTYPE_TGID); + detach_pid(post->pids, p, PIDTYPE_PGID); + detach_pid(post->pids, p, PIDTYPE_SID); =20 list_del_rcu(&p->tasks); list_del_init(&p->sibling); @@ -141,7 +149,7 @@ static void __unhash_process(struct task_struct *p, boo= l group_dead) /* * This function expects the tasklist_lock write-locked. */ -static void __exit_signal(struct task_struct *tsk) +static void __exit_signal(struct release_task_post *post, struct task_stru= ct *tsk) { struct signal_struct *sig =3D tsk->signal; bool group_dead =3D thread_group_leader(tsk); @@ -194,7 +202,7 @@ static void __exit_signal(struct task_struct *tsk) task_io_accounting_add(&sig->ioac, &tsk->ioac); sig->sum_sched_runtime +=3D tsk->se.sum_exec_runtime; sig->nr_threads--; - __unhash_process(tsk, group_dead); + __unhash_process(post, tsk, group_dead); write_sequnlock(&sig->stats_lock); =20 /* @@ -236,10 +244,13 @@ void __weak release_thread(struct task_struct *dead_t= ask) =20 void release_task(struct task_struct *p) { + struct release_task_post post; struct task_struct *leader; struct pid *thread_pid; int zap_leader; repeat: + memset(&post, 0, sizeof(post)); + /* don't need to get the RCU readlock here - the process is dead and * can't be modifying its own credentials. But shut RCU-lockdep up */ rcu_read_lock(); @@ -252,7 +263,7 @@ void release_task(struct task_struct *p) =20 write_lock_irq(&tasklist_lock); ptrace_release_task(p); - __exit_signal(p); + __exit_signal(&post, p); =20 /* * If we are the last non-leader member of the thread diff --git a/kernel/pid.c b/kernel/pid.c index 2ae872f689a7..73625f28c166 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -88,20 +88,6 @@ struct pid_namespace init_pid_ns =3D { }; EXPORT_SYMBOL_GPL(init_pid_ns); =20 -/* - * Note: disable interrupts while the pidmap_lock is held as an - * interrupt might come in and do read_lock(&tasklist_lock). - * - * If we don't disable interrupts there is a nasty deadlock between - * detach_pid()->free_pid() and another cpu that does - * spin_lock(&pidmap_lock) followed by an interrupt routine that does - * read_lock(&tasklist_lock); - * - * After we clean up the tasklist_lock and know there are no - * irq handlers that take it we can leave the interrupts enabled. - * For now it is easier to be safe than to prove it can't happen. - */ - static __cacheline_aligned_in_smp DEFINE_SPINLOCK(pidmap_lock); seqcount_spinlock_t pidmap_lock_seq =3D SEQCNT_SPINLOCK_ZERO(pidmap_lock_s= eq, &pidmap_lock); =20 @@ -128,10 +114,11 @@ static void delayed_put_pid(struct rcu_head *rhp) =20 void free_pid(struct pid *pid) { - /* We can be called with write_lock_irq(&tasklist_lock) held */ int i; unsigned long flags; =20 + lockdep_assert_not_held(&tasklist_lock); + spin_lock_irqsave(&pidmap_lock, flags); for (i =3D 0; i <=3D pid->level; i++) { struct upid *upid =3D pid->numbers + i; @@ -160,6 +147,18 @@ void free_pid(struct pid *pid) call_rcu(&pid->rcu, delayed_put_pid); } =20 +void free_pids(struct pid **pids) +{ + int tmp; + + /* + * This can batch pidmap_lock. + */ + for (tmp =3D PIDTYPE_MAX; --tmp >=3D 0; ) + if (pids[tmp]) + free_pid(pids[tmp]); +} + struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, size_t set_tid_size) { @@ -347,8 +346,8 @@ void attach_pid(struct task_struct *task, enum pid_type= type) hlist_add_head_rcu(&task->pid_links[type], &pid->tasks[type]); } =20 -static void __change_pid(struct task_struct *task, enum pid_type type, - struct pid *new) +static void __change_pid(struct pid **pids, struct task_struct *task, + enum pid_type type, struct pid *new) { struct pid **pid_ptr, *pid; int tmp; @@ -370,18 +369,19 @@ static void __change_pid(struct task_struct *task, en= um pid_type type, if (pid_has_task(pid, tmp)) return; =20 - free_pid(pid); + WARN_ON(pids[type]); + pids[type] =3D pid; } =20 -void detach_pid(struct task_struct *task, enum pid_type type) +void detach_pid(struct pid **pids, struct task_struct *task, enum pid_type= type) { - __change_pid(task, type, NULL); + __change_pid(pids, task, type, NULL); } =20 -void change_pid(struct task_struct *task, enum pid_type type, +void change_pid(struct pid **pids, struct task_struct *task, enum pid_type= type, struct pid *pid) { - __change_pid(task, type, pid); + __change_pid(pids, task, type, pid); attach_pid(task, type); } =20 diff --git a/kernel/sys.c b/kernel/sys.c index cb366ff8703a..4efca8a97d62 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -1085,6 +1085,7 @@ SYSCALL_DEFINE2(setpgid, pid_t, pid, pid_t, pgid) { struct task_struct *p; struct task_struct *group_leader =3D current->group_leader; + struct pid *pids[PIDTYPE_MAX] =3D { 0 }; struct pid *pgrp; int err; =20 @@ -1142,13 +1143,14 @@ SYSCALL_DEFINE2(setpgid, pid_t, pid, pid_t, pgid) goto out; =20 if (task_pgrp(p) !=3D pgrp) - change_pid(p, PIDTYPE_PGID, pgrp); + change_pid(pids, p, PIDTYPE_PGID, pgrp); =20 err =3D 0; out: /* All paths lead to here, thus we are safe. -DaveM */ write_unlock_irq(&tasklist_lock); rcu_read_unlock(); + free_pids(pids); return err; } =20 @@ -1222,21 +1224,22 @@ SYSCALL_DEFINE1(getsid, pid_t, pid) return retval; } =20 -static void set_special_pids(struct pid *pid) +static void set_special_pids(struct pid **pids, struct pid *pid) { struct task_struct *curr =3D current->group_leader; =20 if (task_session(curr) !=3D pid) - change_pid(curr, PIDTYPE_SID, pid); + change_pid(pids, curr, PIDTYPE_SID, pid); =20 if (task_pgrp(curr) !=3D pid) - change_pid(curr, PIDTYPE_PGID, pid); + change_pid(pids, curr, PIDTYPE_PGID, pid); } =20 int ksys_setsid(void) { struct task_struct *group_leader =3D current->group_leader; struct pid *sid =3D task_pid(group_leader); + struct pid *pids[PIDTYPE_MAX] =3D { 0 }; pid_t session =3D pid_vnr(sid); int err =3D -EPERM; =20 @@ -1252,13 +1255,14 @@ int ksys_setsid(void) goto out; =20 group_leader->signal->leader =3D 1; - set_special_pids(sid); + set_special_pids(pids, sid); =20 proc_clear_tty(group_leader); =20 err =3D session; out: write_unlock_irq(&tasklist_lock); + free_pids(pids); if (err > 0) { proc_sid_connector(group_leader); sched_autogroup_create_attach(group_leader); --=20 2.43.0 From nobody Mon Dec 15 21:42:40 2025 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE059214A94 for ; Wed, 5 Feb 2025 20:09:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738786191; cv=none; b=Wem2NGPGWOUycQfQFO7zrCRDUXWXnnFJQxsG5z3pt7amsDhksct48svX0CuN+a3hhbphFmSdzXv/9ea1kv2qapuAcrDmSMe+prvuDWsTJN3i0cN18DszWHZsYjRJZdiaUOvI/FoRjTDdPAGBTUA4eMBDN7Rss2LmbAEegV8XUNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738786191; c=relaxed/simple; bh=GJ2y/FCanDqhcGlPwrjJkUUipKVr30iT6x4rWzEDa78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gks8G2DU1jD6fstkgCKgdgFoeZwwp+QeEsaftxQlmDlxrA9vWjMeBq1kohu0H6CAbi4B993Z3GTdT5nuCHOMnh0j7LUzkI1U3NvfgJlr1IAk2S4OdcMOLE1z0wzi5WHnpIA+qdt82sjZEvSLPPir4vPEU0YDR8XZD16bdannYGs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=R29pBxQ3; arc=none smtp.client-ip=209.85.208.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R29pBxQ3" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5dce3adbc31so315007a12.2 for ; Wed, 05 Feb 2025 12:09:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738786188; x=1739390988; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6DMFX6YMCCpHUnKPYix3pzepx5ItpSalkZSrvWGNgEw=; b=R29pBxQ3EMJhM/0gqbRvkfwuaMbBSlzNHDcuLWwrkIEURxY5E13tg19t5S+bV8EPDW QkyNusZx1r+Z0omdMNVOw0t2CGljIdn0JZn4pOvrtqPRwh1y1YiiOfJidY3Jgku/7ScI QNxPJA/SwZA5SzsJRy29xrQcAPYdmFLJrcPy6f0pj+nb/Egce9P+fgkKCCGNUYDzsIfc 1IxYAtjxMfX+eLNVHMlKrf2PkUoZsGXFAWZ9bu3oExu9WU+7LABvW1ucYbrSCHQiuIak 3qsKt6pBCwqUJ8srU8WmeVGMaby9zP9zVJx+VfP3/Wu2DWwcuH+MKQXxgsJAase3+JKB PW5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738786188; x=1739390988; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6DMFX6YMCCpHUnKPYix3pzepx5ItpSalkZSrvWGNgEw=; b=JihgXqBwe8jWb7xTSOnX0EdopE7pe/xQzKbZcXHEXafU6Rgh9gOXr3KCcIjIQylVNe QhWybJF0JMoHQReBnjuWMmBayLsWkD0zE0GpgB3hvkGOvuuZSIS9vvAaxIz3f2pMJZpn UAsm7Z4zou047BDj7RLnZg1d9O14mMPaQxPIiNNHGcFFA+kVWLlkcU8dlo2BZmpTTCnh ik3xbTg7Q+QD+KvKBSRdRw9lu4VoO7q8UiSq78AuDTD2KB1FXMRoryJ7IVIu5cAg7dIh ba5k0nglE1gpRTIHRZSK5+Wx5Ic5xlv5StMoZWbtnCr1yYR1abPDrL0o6UbufX6duduj WiJA== X-Forwarded-Encrypted: i=1; AJvYcCUmWbnR5c+al5S32Br1NCKN7GjlJliQrXvY53c/ADh9fPkd0tg4KPYGcMaF9zL4RALbKhISB4zlar1laRA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3GdYo3meQRKthUOgQtyFDqSVgxBL+4TbCwAc6np2RPRD0G5h6 phT51y4wV7BJw83FJxwJ6Ahjk/1vohsBXVFp6RMbmW7pbZzDsOzm X-Gm-Gg: ASbGncvWyX6nhQYxaYBi/l7YflLDHS14a4ICIVuSlXixz0Tbl9Y7IkMfJGrjdEQpuy+ uBHw8zY90kOU0f6EwZJ9VbzYDcUpn4fxJQ+wSPGxaE1kVITCTUu/ZuokvfC4aG4i7tkvPQGwMGQ yWOjxri51i2nlxjFcThkYV+i+W0/vZj1+4T/Xi05ahXLq+LXQbDisS/elAzUkDDItE17+biPhnG Ftu/iuxJ4X03IiN6NxKjKjbALISoiBEUzREwho+efHndruy8r7QlYWzb0KzmiWXgjomlV2Suq82 s3to4m707pCccp/eZHRH/sRS1WFCOhY= X-Google-Smtp-Source: AGHT+IHHavuHMxmpQwSvBcREM9wxFJNCAg1KvI/6JkedpqD328qTUBETfMZe6QbsgoB5QiI7qJgVCw== X-Received: by 2002:a05:6402:3603:b0:5dc:5a51:cbfa with SMTP id 4fb4d7f45d1cf-5dcdb6f9f5fmr12270745a12.6.1738786188060; Wed, 05 Feb 2025 12:09:48 -0800 (PST) Received: from f.. (cst-prg-95-94.cust.vodafone.cz. [46.135.95.94]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab703fbcc0csm932221866b.53.2025.02.05.12.09.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 12:09:47 -0800 (PST) From: Mateusz Guzik To: ebiederm@xmission.com, oleg@redhat.com Cc: brauner@kernel.org, akpm@linux-foundation.org, Liam.Howlett@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mateusz Guzik Subject: [PATCH v5 5/5] pid: drop irq disablement around pidmap_lock Date: Wed, 5 Feb 2025 21:09:29 +0100 Message-ID: <20250205200929.406568-6-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250205200929.406568-1-mjguzik@gmail.com> References: <20250205200929.406568-1-mjguzik@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It no longer serves any purpose now that the tasklist_lock -> pidmap_lock ordering got eliminated. Reviewed-by: Oleg Nesterov Signed-off-by: Mateusz Guzik --- kernel/pid.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/kernel/pid.c b/kernel/pid.c index 73625f28c166..900193de4232 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -115,11 +115,10 @@ static void delayed_put_pid(struct rcu_head *rhp) void free_pid(struct pid *pid) { int i; - unsigned long flags; =20 lockdep_assert_not_held(&tasklist_lock); =20 - spin_lock_irqsave(&pidmap_lock, flags); + spin_lock(&pidmap_lock); for (i =3D 0; i <=3D pid->level; i++) { struct upid *upid =3D pid->numbers + i; struct pid_namespace *ns =3D upid->ns; @@ -142,7 +141,7 @@ void free_pid(struct pid *pid) idr_remove(&ns->idr, upid->nr); } pidfs_remove_pid(pid); - spin_unlock_irqrestore(&pidmap_lock, flags); + spin_unlock(&pidmap_lock); =20 call_rcu(&pid->rcu, delayed_put_pid); } @@ -210,7 +209,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *= set_tid, } =20 idr_preload(GFP_KERNEL); - spin_lock_irq(&pidmap_lock); + spin_lock(&pidmap_lock); =20 if (tid) { nr =3D idr_alloc(&tmp->idr, NULL, tid, @@ -237,7 +236,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *= set_tid, nr =3D idr_alloc_cyclic(&tmp->idr, NULL, pid_min, pid_max, GFP_ATOMIC); } - spin_unlock_irq(&pidmap_lock); + spin_unlock(&pidmap_lock); idr_preload_end(); =20 if (nr < 0) { @@ -271,7 +270,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *= set_tid, =20 upid =3D pid->numbers + ns->level; idr_preload(GFP_KERNEL); - spin_lock_irq(&pidmap_lock); + spin_lock(&pidmap_lock); if (!(ns->pid_allocated & PIDNS_ADDING)) goto out_unlock; pidfs_add_pid(pid); @@ -280,18 +279,18 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t= *set_tid, idr_replace(&upid->ns->idr, pid, upid->nr); upid->ns->pid_allocated++; } - spin_unlock_irq(&pidmap_lock); + spin_unlock(&pidmap_lock); idr_preload_end(); =20 return pid; =20 out_unlock: - spin_unlock_irq(&pidmap_lock); + spin_unlock(&pidmap_lock); idr_preload_end(); put_pid_ns(ns); =20 out_free: - spin_lock_irq(&pidmap_lock); + spin_lock(&pidmap_lock); while (++i <=3D ns->level) { upid =3D pid->numbers + i; idr_remove(&upid->ns->idr, upid->nr); @@ -301,7 +300,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *= set_tid, if (ns->pid_allocated =3D=3D PIDNS_ADDING) idr_set_cursor(&ns->idr, 0); =20 - spin_unlock_irq(&pidmap_lock); + spin_unlock(&pidmap_lock); =20 kmem_cache_free(ns->pid_cachep, pid); return ERR_PTR(retval); @@ -309,9 +308,9 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *= set_tid, =20 void disable_pid_allocation(struct pid_namespace *ns) { - spin_lock_irq(&pidmap_lock); + spin_lock(&pidmap_lock); ns->pid_allocated &=3D ~PIDNS_ADDING; - spin_unlock_irq(&pidmap_lock); + spin_unlock(&pidmap_lock); } =20 struct pid *find_pid_ns(int nr, struct pid_namespace *ns) --=20 2.43.0