From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) (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 1D1051CEAC2 for ; Tue, 10 Feb 2026 08:47:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770713277; cv=none; b=RTLOLL32bPOApkaaonKKZc00QbJJ7cQDIck3VDZgbBJ/jsNa/SNS0e9ICo9BDGX1x9dyUZ8RF5Du22KDsc3tD0hhgualLsU8DXsmbCLfOy8DUSdxgl7M9orQDQvLpFh6jGC5EodWvOVYL46IosllYUsj5S771fPhWGHtQ8z+ymk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770713277; c=relaxed/simple; bh=3lnGLctRTV1ZhP7gsANbRBWYr/uaOemWulTLa6OebJo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fU6z8vbcl450kQCtpBcOOsGjk2m01YCZRN2j6Mofr6/FHAWVqOc3rY6I0y8rPxSqCOKnXFi+GI1eMsS2ecEQzNYsJ+QkA0fbQpREmB4G4oERxYOQ/oAxJlknWsrfamk6O7i7EH/ZODVjafbvoKrA4Cfx0uKYyC+gbY0ONM05unQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=EvaFxUND; arc=none smtp.client-ip=209.85.218.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EvaFxUND" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-b8718916c9aso60087166b.0 for ; Tue, 10 Feb 2026 00:47:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770713273; x=1771318073; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ULYjWWC903FxjlaA/DfXcj/bqj7W1j7W1eSCTHW/xkw=; b=EvaFxUND285Y3oVyxjVN89cDVVKtUUnTes1vgOJYBW2C3AcXNDFEt8ikXkvM2jEKwP opUNVt7T4n+fgUjZ49Q8Twi7E+KB17Aqk+nlfQgA5QnBh1tVHt6/LBejIO28MqpUjHBY z3xp2w1lZk1GoXC8WJiGtg4mMA3LKo8aWbPocEQItu0kO+0z2i43lZyAKVk4+ZepRDNz GJDU8bnAwcl7Zec7S1XU0cKi7lBii9eiZ5oVlZDLAF8OnCDCprro26A1AAx6ja9775+/ PalV8lZHRvPQdvmrnTEmIcIbqqrJswKzwvLmFg+LM8ISsbHvkx8Rhj2yin6DfvTkRWej cOyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770713273; x=1771318073; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ULYjWWC903FxjlaA/DfXcj/bqj7W1j7W1eSCTHW/xkw=; b=p7ERsMv8Vh9B0ZvUwf0IGRXgyN9+opkR8DxXlY3Ypr7ULQjogopr3dqe88TaxfDHpt NIVjIblhgayfJZKxrc6xNHUB84uAxBH170YCxxp1K2PTfrYp/eo2rWdOhiaPvfHItvez CzNTepioXDSEhj7NNGOy9Bf3wG5asO+GOLR22BcLNwfmC9nqi0uc9feOMsK7L9IppyMS PSt5TRB0Q/y7visl/9nGdbyogod6mosJD28jK6sTFFkEb4jB2UcJLIgtB+BVogSAVq/z Ag+suw6S0wC92SS+Pq8rB7ZbswxkLEZ8sr2ewNiDm+iR5JuIfP+F6jezU5q7WCp1SXU0 sA8g== X-Forwarded-Encrypted: i=1; AJvYcCUXGCEl5uzFtribaX1JJ3NSstvmyNrEUArZGZzo4ymEf5KtSosJp7peD/aI2M0MsdFp6YbqiJqXij8EF6U=@vger.kernel.org X-Gm-Message-State: AOJu0YxC6BeFXRPne6NPa86rOBTbb/bny1jLXvbg4Tic+Qn1rvIECXh2 NG06B3RTnRppdDgTlXL8iQXtNjIjOCRAolY6Y2zf4c/c8sRKyVab70hXM8uxY3Tx5tMhSuCYVjW U6yp7C860Lio6vU/Tdw== X-Received: from ejdai24.prod.google.com ([2002:a17:907:e158:b0:b8e:b3d3:3838]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:3d16:b0:b88:510a:59b3 with SMTP id a640c23a62f3a-b8edf40a6a6mr848568966b.48.1770713273356; Tue, 10 Feb 2026 00:47:53 -0800 (PST) Date: Tue, 10 Feb 2026 08:47:52 +0000 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260205-binder-tristate-v1-0-dfc947c35d35@google.com> <20260205-binder-tristate-v1-1-dfc947c35d35@google.com> <9d0d6edd-eab4-4f31-9691-78ed48e7ad5b@lucifer.local> <9a037fdf-1a98-437f-8b80-7fdc53d5b0fa@lucifer.local> Message-ID: Subject: Re: [PATCH 1/5] export file_close_fd and task_work_add From: Alice Ryhl To: Lorenzo Stoakes Cc: Greg Kroah-Hartman , Carlos Llamas , Alexander Viro , Christian Brauner , Jan Kara , Paul Moore , James Morris , "Serge E. Hallyn" , Andrew Morton , Dave Chinner , Qi Zheng , Roman Gushchin , Muchun Song , David Hildenbrand , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Miguel Ojeda , Boqun Feng , Gary Guo , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , kernel-team@android.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-mm@kvack.org, rust-for-linux@vger.kernel.org Content-Type: text/plain; charset="utf-8" On Mon, Feb 09, 2026 at 03:21:58PM +0000, Lorenzo Stoakes wrote: > On Thu, Feb 05, 2026 at 01:45:40PM +0000, Alice Ryhl wrote: > > +/** > > + * close_fd_safe - close the given fd > > + * @fd: file descriptor to close > > + * @flags: gfp flags for allocation of task work > > + * > > + * This closes an fd. Unlike close_fd(), this may be used even if the fd is > > + * currently held with fdget(). > > + * > > + * Returns: 0 or an error code > > + */ > > +int close_fd_safe(unsigned int fd, gfp_t flags) > > +{ > > + struct close_fd_safe_task_work *twcb; > > + > > + twcb = kzalloc(sizeof(*twcb), flags); > > + if (!twcb) > > + return -ENOMEM; > > + init_task_work(&twcb->twork, close_fd_safe_callback); > > + twcb->file = file_close_fd(fd); > > + if (!twcb->file) { > > + kfree(twcb); > > + return -EBADF; > > + } > > + > > + get_file(twcb->file); > > + filp_close(twcb->file, current->files); > > + task_work_add(current, &twcb->twork, TWA_RESUME); > > + return 0; > > +} > > Would need an EXPORT_SYMBOL_FOR_MODULES(...) here right? Ah yeah, for Binder to become a module it would need to be exported. (Though maybe it's worth moving this logic even if Binder is not made into a module?) > > diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h > > index c45306a9f007..1c99a56c0cdf 100644 > > --- a/include/linux/fdtable.h > > +++ b/include/linux/fdtable.h > > @@ -111,6 +111,7 @@ int iterate_fd(struct files_struct *, unsigned, > > const void *); > > > > extern int close_fd(unsigned int fd); > > +extern int close_fd_safe(unsigned int fd, gfp_t flags); > > One nit, generally well in mm anyway we avoid the 'extern' and remove them as we > go. Not sure about vfs actually though? Right. Not sure about this. > > extern struct file *file_close_fd(unsigned int fd); > > > > extern struct kmem_cache *files_cachep; > > I mean this is essentially taking what's in binder and making it a general > thing, so needs Christian's input on whether this is sensible I think :) Yeah. Alice