From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (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 671A13ACA5A for ; Tue, 20 Jan 2026 07:56:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768895764; cv=none; b=fOOG33xxQNnWvkM2fLv1lg7SL/oRbI9GbHJFnzeZboeGBjnn9G8oEq+ParpcIH7ZbyHIFrzx/q729h9H9L0veOFhyP6AQnNUmURX5W0X6xW7NpVkDcQ8OJNNqdnnLF3Z92Y3qXNNN2TCcXrzQPp8Zye9B2+RMNg8cOtCOiyBUWQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768895764; c=relaxed/simple; bh=Z1ON5Z0cSM7bM+AviLwpLgIcyBgMR16fKcb6Hq54fjE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rNWkQmTp5x+NXCBubwV49L1HyVKrx4RSVilryhoBlhTBhmhVmejjbhab29SNTvxneB4Jr5xLmW5+jmOTmjZZn5eHsa62opb17/TwXyUWBVAYwMBEOLS2TOYiToBWE93FYW5UgfMZ4nshSvHk1+DJfUJqZebIo+8PK3sL3I4Xq3A= 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=Q8bZIPoD; arc=none smtp.client-ip=209.85.221.73 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="Q8bZIPoD" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-430ffc4dc83so4568630f8f.3 for ; Mon, 19 Jan 2026 23:56:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768895760; x=1769500560; 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=aCnJ8y0UYrlkUlqd4IHCJ2AeMARemKBN0GlGR7eCJus=; b=Q8bZIPoD/eJUVL1Vge/90aosdkyJVfGVzxyGmGRMTcLDioR9/Tq2pIo/J4HoFiS3TC 3n+i86cfrxEHK2n0SDsQBC4Y90qgHe7nmGwhg+i1xDnG/nwrcGO4RNQn4SHReH3o8QTp wunuUQCD+s+KCNE33GWp1e7hksuVAG8Eayd67gKv8wegkFMHJiAL2YmuWBPChouSyxeU GbFLq5RAkRUtLRQPQxN/oiLWXveEsq8b/F7lSvum9xRhCXk/vlTRIA1l7pdDsuM/rxif SPqNtzwNcJ9F2dxzNdiZ5f+B4bXcHHbM2hMaQvh5gM/PJp/eidMJmuK3C6vyqxVLdwN4 RQZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768895760; x=1769500560; 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=aCnJ8y0UYrlkUlqd4IHCJ2AeMARemKBN0GlGR7eCJus=; b=GiSVj9UaXLUbwzciI+kdP0F4COgbWGM3kPQeh6iMYhD7hvO2KLVu2LFgafgeDyCpxB 6QGKNJcXfIiG5CMWzo+XAz1GHXBvmyHwW7hnDNIvlOkbrazDOO6yhgtvmpSc2IyCBYMe Hxy8LKcK3qX9YYljif3gqA4mYgYeanTnl1h5pNAgiSotErQnvaugXZgrCPrSlvrmCQXE ox1imu0t8W5Tf4+ne2GEf4lkMi7P+pr6Iitq7IKJu18l//f2UK0iVOKmM5uy/z6AERN/ ZgURNmitV+btt92CmQwwkOu4AA9Lyq6BEeSf7zVdOATrakJdSn8E8Rshl4Q6XnmPwz5m clDg== X-Forwarded-Encrypted: i=1; AJvYcCVBxW1otzCwKMXUHKpp00Rl1GUzUSFVsPydwnPQdWXU3FS+2rMsxCGqDHUsuPsdsVihHpStHeWQfmfNMLM=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0/E38jIS1IEqRNC13C90ws9O89BAec+35S5JMeJLm+2lhKiwO qvtDpSDxX4LIa0dsHFJzDan4o72JnyllpDft4vzz9P803ziYmjs53jTo6tdprdWewkF/AEt55rN Ej+BhY+qGFwcb/buk3g== X-Received: from wrnv6.prod.google.com ([2002:adf:ebc6:0:b0:42f:b693:9d6]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:5889:0:b0:430:ff81:2961 with SMTP id ffacd0b85a97d-4356a082ebfmr18818918f8f.51.1768895759472; Mon, 19 Jan 2026 23:55:59 -0800 (PST) Date: Tue, 20 Jan 2026 07:55:58 +0000 In-Reply-To: <20260119133101.23708-1-jason.kei.hall@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260118142623.1188141-1-jason.kei.hall@gmail.com> <20260119133101.23708-1-jason.kei.hall@gmail.com> Message-ID: Subject: Re: [PATCH v3] rust_binder: refactor context management to use KVVec From: Alice Ryhl To: Jason Hall Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , "Arve =?utf-8?B?SGrDuG5uZXbDpWc=?=" , Todd Kjos , Carlos Llamas Content-Type: text/plain; charset="utf-8" On Mon, Jan 19, 2026 at 06:31:01AM -0700, Jason Hall wrote: > Replace the linked list management in context.rs with KVVec. > This simplifies the ownership model by using standard > Arc-based tracking and moves away from manual unsafe list removals. > > The refactor improves memory safety by leveraging Rust's contiguous > collection types while maintaining proper error propagation for > allocation failures during process registration. > > Suggested-by: Alice Ryhl > Link: https://github.com/rust-for-linux/linux/issues/1215 > Signed-off-by: Jason Hall Thanks! Please send the next version as a separate thread rather than a reply. > pub(crate) fn deregister(&self) { > - // SAFETY: We never add the context to any other linked list than this one, so it is either > - // in this list, or not in any list. > - unsafe { CONTEXTS.lock().list.remove(self) }; > + // Safe removal using retain > + CONTEXTS.lock().contexts.retain(|c| { > + let p1 = Arc::as_ptr(c); > + let p2 = self as *const Context; > + p1 != p2 > + }); Please use Arc::ptr_eq here too. > - pub(crate) fn deregister_process(self: &Arc, proc: &Process) { > + pub(crate) fn deregister_process(self: &Arc, proc: &Arc) { > if !Arc::ptr_eq(self, &proc.ctx) { > pr_err!("Context::deregister_process called on the wrong context."); > return; > } > - // SAFETY: We just checked that this is the right list. > - unsafe { self.manager.lock().all_procs.remove(proc) }; > + let mut manager = self.manager.lock(); > + manager.all_procs.retain(|p| !Arc::ptr_eq(p, proc)); > + let len = manager.all_procs.len(); > + let cap = manager.all_procs.capacity(); > + if len < cap / 2 && cap > 128 { > + let _ = manager.all_procs.reserve(0, GFP_KERNEL); Calling reserve(0) has no effect. It will not shrink the vector. Perhaps we should add a method to `Vec` for moving elements from one vector to another? Alice