Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1190665lqe; Mon, 8 Apr 2024 01:04:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXBQuVcejcd2UzehQ6DrPRSrJUqCfm+6iD8Pas7Csv/mXJOmnWdpbtOrL7wyTQK/wYb70blhAyOY4k38szBrrYrmRgSDdakQwJFNeSKTw== X-Google-Smtp-Source: AGHT+IEhoE335A2sPmZEezf1PsbvKtzj84uhzzlpMaagDNwfkVUdjeFC2HJyuyg9/NNdHTg8CXwB X-Received: by 2002:a05:6830:6e06:b0:6ea:19a3:810f with SMTP id ec6-20020a0568306e0600b006ea19a3810fmr2104078otb.17.1712563483457; Mon, 08 Apr 2024 01:04:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712563483; cv=pass; d=google.com; s=arc-20160816; b=AjSzf38bSgAHA8mhuDgus9isZNIszDJsBaOFpYeKZDhwaFi8dUHerjO6Y009FgNLtz ikOuL+4T9RkKr/0wrBq3563etUr/kT04Qs4BbF63O09nW92eXFreyFUxR5Y44img65Uv kS4nuw7abCMLKLdVSXtromchUJQ1Wv5Ud+rtQMB6Wzeh8eChbiT5WHFqPdYZu/wTZazl L0xuufw+EEYnQSvng0zwiRue6gdBimHiHtzZd7n1dhdlok5JjrVulsPOWCiXL73w+vpg angx8Nq3SIZZXe/3dVHvxZ+uaqL8WsCtVoiPt3oele8KLgX2cesFnCGQXQIIt8gnVZek JKNw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=HHOIPSa/Ioif2qoA5aZKv29U1sNgEs2SSy9Tn1rKK+8=; fh=CI8yxH9QwiOfk/1fYePWlxk7trsJdU3Rfc5kvuEpak0=; b=TKhOIs0Z4+WHQRg+PdyUu9int8jpzwKD3OmVELLoGIIkjO5gkSVBcTwP8Kf3eHynYp zB3nBryZJmvBVoRisHWd8z7Hmi1jqCHFqBJJHJ+gn/AWZr/EblRe/MOrRSYWhQSSCfEP mWGaFH7gkiV2ksiOVZSSiFAhfkSh9hMAKvvlR7t8tasOu6poqkwztI1g64Yy7NXlMHwr 7bd4OtJnkfXyh41RAIgW/fMc5qHnin45/Gke70NgVsRoWZI6Gnlww++7PHalhhvRiQaj zs0XEo9od6OZP63RazXpC5p5FBvcpfKTqoJ44duu6QFTYk2XIAyXu/PNovJcsAh7PWBe 3kAw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SA7bhGqM; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-134989-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134989-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o24-20020a635a18000000b005dc1c316cf5si5821257pgb.357.2024.04.08.01.04.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 01:04:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134989-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SA7bhGqM; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-134989-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134989-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 65FB42828B6 for ; Mon, 8 Apr 2024 08:04:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0E5025632; Mon, 8 Apr 2024 08:04:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SA7bhGqM" Received: from mail-vk1-f179.google.com (mail-vk1-f179.google.com [209.85.221.179]) (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 8C6A429CE8 for ; Mon, 8 Apr 2024 08:04:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712563471; cv=none; b=b6bD53R/b+M8ppRjtFCheLhz4ewBQbpZ857iv+gSy02x2WKUW7GHonXxRNf+AnwFpvucABiA36foW3BAXFsx3EbGYjSjesu512KANUG/kskYwyRKKfN8Ok21GszyDyrPI67cJIQFUFhRzYgZv/EFhv88+88IWqII7qfBRwrPSKA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712563471; c=relaxed/simple; bh=M3C8rM8DeyxXdmwLP5rZUOxDVPuH43HP8/2t6W4VfWY=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=az52MHPpPpS6yLA5VQdtdHIKlK0lB43vXZxi+rQtfdkvln1N+f5wfJ9tsUgc8BY6IvS1Yo33wM7mmBXH3KkWZWmsIm2rLwVVU8UJwlxKpDZ+TSlCN5ZPhpjVhWS/kyaWypIK2JwaB9+0hgGOSJtCeP2OSvLPNNPCYipz/DOTYWQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=SA7bhGqM; arc=none smtp.client-ip=209.85.221.179 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=google.com Received: by mail-vk1-f179.google.com with SMTP id 71dfb90a1353d-4dabc6f141bso446262e0c.2 for ; Mon, 08 Apr 2024 01:04:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712563468; x=1713168268; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=HHOIPSa/Ioif2qoA5aZKv29U1sNgEs2SSy9Tn1rKK+8=; b=SA7bhGqMXzV00sWKdEgYFhkV/fJzaPdphiDTlY0oETXYHircKxk55DtDnVhtXC6AHd 8WqrmP28cALHBC7EdV0eAvnkPmk5oPK28A7l7Jjgj0omUQFk9zD1+9Gwg9zRjSFo8SBZ UYufWO8ucG5zgumqrBanzxa2tuAZLN2Es1F3vjy9bsAFvaVe99ahoojkcHOZjzdQjwa4 qLHULTzmT2fkKadIRQHhoej2h7D4KowlmOIwGOv27KllDK+4hYMz7kr9g7jaeAcmFOYz U1icnkgehd0/9etpZgR0/Pl7zwHN9WfRF3Juije2arstpK5IPr+Kp+SryDa3XCUmp6WZ x69A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712563468; x=1713168268; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HHOIPSa/Ioif2qoA5aZKv29U1sNgEs2SSy9Tn1rKK+8=; b=skrOib8+MNS7pd8gtCFmy4K51qpQnwmu4/MMGOP0v+OaUHRBkiE1bz/atvV2F8SFAz gGTBcJF9Q2UfM3X9PpjKBS0Xe2mtmQZJeq9lde5Ujo+N6sO24DyLj7RttX+J6NvyjTS8 d02LVbuNVtZnon3Zw58i9DBqIpjSoLy1i+yIKvbI+GhAQ10cz8Y5UXBkmRsUtq4qEtVZ 7KP+oOOh4UB2ksWdvXFuVDInx1zzNw3LZCPRZPez7OxkXmHOClJohYamswFaA/azRtU8 e8f7X1+DvKR6BYN/71rAhlssnGVNEADehff5yJHIo+/DySXxds0uWvTVtX4bdUWTIkhl 26PA== X-Forwarded-Encrypted: i=1; AJvYcCVGmV3av6jujInAq3iXUOtNI1OXxJgf0qSCU/BfpB1vXoFjJtmNtnntTEENq+RZKAR9rnUF7Z68ZV5VNynr5GbcT875rh7MPgnreY/r X-Gm-Message-State: AOJu0YxiI3okWeRhmtWMPNRCY+oAUD+VA/LwWGsepbLu3sUo5WbNAaqT X8wN26YGn0AughexMcQGhJ7G+9rm8XIR57/XgVSmfA5d4vMSjx0Dy5CD0BVE8VxNu9IdfVgM1ja /+GD8zxBXI5Ntc9/0Gego9HbhkDNA8HebfPc8 X-Received: by 2002:a05:6122:491:b0:4da:9d3e:a7df with SMTP id o17-20020a056122049100b004da9d3ea7dfmr4346854vkn.5.1712563468420; Mon, 08 Apr 2024 01:04:28 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240402-linked-list-v1-0-b1c59ba7ae3b@google.com> <20240402-linked-list-v1-5-b1c59ba7ae3b@google.com> <3f3cf5ae-30df-4032-b752-77126035784c@proton.me> In-Reply-To: <3f3cf5ae-30df-4032-b752-77126035784c@proton.me> From: Alice Ryhl Date: Mon, 8 Apr 2024 10:04:17 +0200 Message-ID: Subject: Re: [PATCH 5/9] rust: list: add List To: Benno Lossin Cc: Miguel Ojeda , Andrew Morton , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Marco Elver , Kees Cook , Coly Li , Paolo Abeni , Pierre Gondois , Ingo Molnar , Jakub Kicinski , Wei Yang , Matthew Wilcox , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 4, 2024 at 4:51=E2=80=AFPM Benno Lossin wrote: > > On 04.04.24 16:12, Alice Ryhl wrote: > > On Thu, Apr 4, 2024 at 4:03=E2=80=AFPM Benno Lossin wrote: > >> On 02.04.24 14:17, Alice Ryhl wrote: > >>> + // never null for items in a list. > >>> + // > >>> + // INVARIANT: There are three cases: > >>> + // * If the list has at least three items, then after remov= ing the item, `prev` and `next` > >>> + // will be next to each other. > >>> + // * If the list has two items, then the remaining item wil= l point at itself. > >>> + // * If the list has one item, then `next =3D=3D prev =3D= =3D item`, so these writes have no effect > >>> + // due to the writes to `item` below. > >> > >> I think the writes do not have an effect. (no need to reference the > >> writes to `item` below) > > > > ? > > The first write is > > (*next).prev =3D prev; > > Using the fact that `next =3D=3D prev =3D=3D item` we have > > (*item).prev =3D prev; > > But that is already true, since the function requirement is that > `(*item).prev =3D=3D prev`. So the write has no effect. > The same should hold for `(*prev).next =3D next`. Oh, you are arguing that we aren't changing the value? I hadn't actually realized that this was the case. But the reason that they end up with the correct values according to the invariants is the writes below that set them to null - not the fact that we don't change them here. After all, setting them to a non-null value is wrong according to the invariants. Alice > >>> + unsafe { > >>> + (*next).prev =3D prev; > >>> + (*prev).next =3D next; > >>> + } > >>> + // SAFETY: We have exclusive access to items in the list. > >>> + // INVARIANT: The item is no longer in a list, so the pointe= rs should be null. > >>> + unsafe { > >>> + (*item).prev =3D ptr::null_mut(); > >>> + (*item).next =3D ptr::null_mut(); > >>> + }