From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 3925226AFC for ; Tue, 28 Jan 2025 15:22:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738077723; cv=none; b=sqH5TJBKEIfXyMlXF+iuY5TrYeWggy5OExLIaEFQtAlq8QmvecPnEgQaZR65Oo15YoXBWrM8yYyoktdqLYqT0acQAD0Mf+A2sZNXOHqDoMnXma7wtxwqP3E/AA5+SUMHPGt5B4WOIrqt8WfcwGsvexoplxaIYgUqSP8ZKcoUfyA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738077723; c=relaxed/simple; bh=Lgqbe/aIYnDPeTEcamJGDRAnLJEma7nTBkAsv5v/3Vk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Cmn8DXTEiMl+z0MZpWc/LsUx2jMuNgoB0aRLin6ItCGFW5sJ0M0ae8F9CwqUAyY8/QnBV0Ar8fWAmbliwJPX9iXuidNyppm2QbHaAN797LSChYr4VwMqpLRBPiDDeQ+pvquW3voo1PVOJXM81K7vhvitnCHK16p5sIPJZk2ghbg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=inQRmZl4; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="inQRmZl4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738077721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/uC/GOLwyPoIezQAjm4gHq0NOQKSQN8kYnbnF8LUxfg=; b=inQRmZl4CVb84TsKGLeOWrZepAZZOE8pRMb25o86YIs0XBi+bt4kyB84FFyzeK8+16LkoN ox5dhdammc9UNJzbBZ3Zace3JIQwRzBVwF+kMnU+BKaT+hqoLeQsQ6KH5fYfCKUlFZ/GtS P/Lgiju4MHhfxjLllU/LCd7tb22yMDY= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-582-xaOUflubNfeG3t9WycnyVA-1; Tue, 28 Jan 2025 10:21:56 -0500 X-MC-Unique: xaOUflubNfeG3t9WycnyVA-1 X-Mimecast-MFC-AGG-ID: xaOUflubNfeG3t9WycnyVA Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 937981800269; Tue, 28 Jan 2025 15:21:55 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.70]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 8225A18008D4; Tue, 28 Jan 2025 15:21:53 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 28 Jan 2025 16:21:29 +0100 (CET) Date: Tue, 28 Jan 2025 16:21:25 +0100 From: Oleg Nesterov To: Mateusz Guzik Cc: brauner@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] exit: call add_device_randomness() without tasklist_lock Message-ID: <20250128152125.GA24845@redhat.com> References: <20250128140701.3136924-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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250128140701.3136924-1-mjguzik@gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 On 01/28, Mateusz Guzik wrote: > > --- a/kernel/exit.c > +++ b/kernel/exit.c > @@ -141,13 +141,14 @@ static void __unhash_process(struct task_struct *p, bool group_dead) > /* > * This function expects the tasklist_lock write-locked. > */ > -static void __exit_signal(struct task_struct *tsk) > +static unsigned long long __exit_signal(struct task_struct *tsk) > { > struct signal_struct *sig = tsk->signal; > bool group_dead = thread_group_leader(tsk); > struct sighand_struct *sighand; > struct tty_struct *tty; > u64 utime, stime; > + unsigned long long randomness; > > sighand = rcu_dereference_check(tsk->sighand, > lockdep_tasklist_lock_is_held()); > @@ -174,8 +175,7 @@ static void __exit_signal(struct task_struct *tsk) > sig->curr_target = next_thread(tsk); > } > > - add_device_randomness((const void*) &tsk->se.sum_exec_runtime, > - sizeof(unsigned long long)); > + randomness = tsk->se.sum_exec_runtime; > > /* > * Accumulate here the counters for all threads as they die. We could > @@ -214,6 +214,8 @@ static void __exit_signal(struct task_struct *tsk) > flush_sigqueue(&sig->shared_pending); > tty_kref_put(tty); > } > + > + return randomness; > } > > static void delayed_put_task_struct(struct rcu_head *rhp) > @@ -242,6 +244,7 @@ void release_task(struct task_struct *p) > struct task_struct *leader; > struct pid *thread_pid; > int zap_leader; > + unsigned long long randomness; > repeat: > /* 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 */ > @@ -254,7 +257,7 @@ void release_task(struct task_struct *p) > write_lock_irq(&tasklist_lock); > ptrace_release_task(p); > thread_pid = get_pid(p->thread_pid); > - __exit_signal(p); > + randomness = __exit_signal(p); > > /* > * If we are the last non-leader member of the thread > @@ -280,6 +283,8 @@ void release_task(struct task_struct *p) > put_pid(thread_pid); > release_thread(p); > put_task_struct_rcu_user(p); > + add_device_randomness((const void*) &randomness, > + sizeof(unsigned long long)); > > p = leader; > if (unlikely(zap_leader)) Hmm, why not simply shift add_device_randomness(sum_exec_runtime) to release_release_task() ? Oleg. --- a/kernel/exit.c +++ b/kernel/exit.c @@ -174,9 +174,6 @@ static void __exit_signal(struct task_struct *tsk) sig->curr_target = next_thread(tsk); } - 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, @@ -279,6 +276,8 @@ void release_task(struct task_struct *p) proc_flush_pid(thread_pid); put_pid(thread_pid); release_thread(p); + add_device_randomness((const void*)&p->se.sum_exec_runtime, + sizeof(unsigned long long)); put_task_struct_rcu_user(p); p = leader;