From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23714372EEE for ; Thu, 25 Jun 2026 23:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782428763; cv=none; b=HcaqYGDp47cRqx5faNpKXATrKn6I9X35FcvqcWMS/p4EyeaVhpOWrw7nBy53JKo6mUGfxXrkq8cK2RJV3LV0b07nn122dzKJnMkI8l8ucjR+aLo+57+HFfYXaHUL2Gs6JPMzmu7azAR23g3fIarkelaFoekABzPH1zMG41szpJw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782428763; c=relaxed/simple; bh=StI4QgCscfo0VI+BHiz68HuvaK0xRBAwEauzRHmwn74=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=EAEE64uti+Te17018DxWHc3jNaRu1NnFa5KmnlXta405yVPFjbsoz9VdY8cwQTVc7QX2igpr4eQfZ6E0WgWNPfWc/P7JYiojFSL3y9I3aubfiUu2Lks1gZusQu1zpPB1/cnwVg4CIF69WeLdxVrfT+hOgfJmnBmdrY72oU2XvnA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=N7k3J48t; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="N7k3J48t" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A46501F000E9; Thu, 25 Jun 2026 23:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1782428761; bh=kLWP2P+hJJpU5CGAbEtTCsF6sUy45tSGbWyZKSc5EFE=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=N7k3J48tXhMLTDeKuNpG2AyC7NA4zPX9rf9WxNQJX8YXzsPzPdyc5qjA5DfgFOBM2 eafFG8A3/PmvupSrgIusnrvVTLcb38M/mAA5mvMIAJOY8XIqTr8tHIIKGhQNgchrEG sJ/mC4xz29sW5/M69tnRmLZILo4IzhCN/KY2X6FY= Date: Thu, 25 Jun 2026 16:06:01 -0700 From: Andrew Morton To: Jianlin Shi Cc: linux-kernel@vger.kernel.org, ebiederm@kernel.org, "Eric W. Biederman" , Davidlohr Bueso Subject: Re: [PATCH v2] ipc: only destroy orphaned shm segments on sysctl write Message-Id: <20260625160601.1a58f7e114be14161e710148@linux-foundation.org> In-Reply-To: References: X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 15 Jun 2026 10:27:41 +0800 Jianlin Shi wrote: > proc_ipc_dointvec_minmax_orphans() currently calls > shm_destroy_orphaned() whenever shm_rmid_forced is set, including on > sysctl reads. Reading /proc/sys/kernel/shm_rmid_forced should not take > shm_ids rwsem for write and walk all segments. > > Only run the cleanup when the sysctl is written and the forced RMID > policy is enabled. > > When shm_rmid_forced=1, monitoring tools that read > /proc/sys/kernel/shm_rmid_forced trigger the cleanup on every read. > > ... > > --- a/ipc/ipc_sysctl.c > +++ b/ipc/ipc_sysctl.c > @@ -28,7 +28,7 @@ static int proc_ipc_dointvec_minmax_orphans(const struct ctl_table *table, int w > > if (err < 0) > return err; > - if (ns->shm_rmid_forced) > + if (write && ns->shm_rmid_forced) > shm_destroy_orphaned(ns); > return err; > } Seems reasonable, I guess. Maybe. It's not backward compatible. Nothing in the shm_rmid_forced documentation (Documentation/admin-guide/sysctl/kernel.rst) indicates that a read has any such side-effect. But there's a risk that users have discovered that a read has this effect, so they're using reads because that's a lot less hassle than figuring out what value to write. Davidlohr, Eric: any thoughts on this? btw, the doc says "if you change this from 0 to 1, already created segments without users and with a dead originative process will be destroyed" but the implementation will do the destruction for any write of a non-zero value. It should read "if a non-zero value is written already created segments without users and with a dead originative process will be destroyed". Minor detail.