Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1209933lqe; Mon, 8 Apr 2024 01:57:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV1oZHsKWa/qm24H2VRic6fJJRKTazCpHb09ffimiY6FICrHukHtnV+bKl3bCANMk3hxfsvV5mE4f/ZbbZl4AB7kqKkT6ntHRT+QZGLLA== X-Google-Smtp-Source: AGHT+IFYb+PwCkWsWecxgUWelLp8NFe0vJA+SLb0t7veeQAJyKh36vpdinDpNy1qGjcg/WIFnYHf X-Received: by 2002:a05:6358:2295:b0:17e:bbdb:acbe with SMTP id t21-20020a056358229500b0017ebbdbacbemr9630861rwb.14.1712566658278; Mon, 08 Apr 2024 01:57:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712566658; cv=pass; d=google.com; s=arc-20160816; b=WaNjlSYElko7NZaZfdKzF96Th+DC6AF99UvQmTDzp7RIa1vC4ZuAZdM7F5/Im+X0r2 b+WPyLS9iMcGHnzlAPb6bUIWCQUKZ4Mk4Mw0xDXJ0++wEXF7mVx7xwMS+whq0o1Wv7Hr otAzfuEtV4X3u1PTOh5fG6ZfAghwLPk1wVDAvXJfebzSZ3WUKpK6M3/ppidXpGc5fgUN Z2sx4ThfhxHubfglCQ3mgKtdQg8hBXTzwEd2KTSEaRCTkIL3iHZEQUAEHSV7AU0jl7GP sXMGxbbK0Yu8ZhVFgXWpWXUzbfbf7KqkwUYxcGExLT5MUgyVWDYTLM03QA7+TyVg3WIc 6xjQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=CUkPAONzwDRb/Nkur4cZQic06C81obmvAaXkWg3RRnE=; fh=NVLHYNxTFxZg90CuAUl5EFs9nACqSf1JvKaCbeMsn7U=; b=jJ+7zAwO1591un+wWD5Vq5fbwOUj37N+WCm5U97daPbKCjP0j/EiwpM0iPLdnN1hGY TJttSABgZdz/sfw5uIyiaY1YVjz1ZH+ZT4lWTuZNi2ySp645eUz62iVmYXJmTzMo+Vx5 d4Wo+G8TmGkqCZscWOF/k2p9D1sx7oBI3Kehe5lsdIIu4rY4bc6+e/V6zHN31SN+iahD YdCFImF6nFse3vwkBJtG6f8bdtp8D743qCdSmw6OD9eP2U5+M7hqeU2KTRziN7mGHTcs RWfIRhDWKcOFxX4ECrem5fOJ2JwKSeQXDNRoR5Eos8WjnXDqDgaK4DRm+wOD48G+ZmFj sPNg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=j1cr+GRr; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-135083-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135083-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id w7-20020a63d747000000b005dd565d7626si5778435pgi.900.2024.04.08.01.57.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 01:57:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135083-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=j1cr+GRr; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-135083-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135083-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id D3A90B20C39 for ; Mon, 8 Apr 2024 08:51:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4C743FBBE; Mon, 8 Apr 2024 08:51:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="j1cr+GRr" Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) (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 9BFE83C470 for ; Mon, 8 Apr 2024 08:51:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.40.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712566278; cv=none; b=BmQP9uHAY7TLOiOczd2byZ6jZM/zQriadDXutgwDsoS1M7tARZdxvxxJT4fEsF7KGPPGP2icPmD/4gy5xMddf7T92zTOLYy1weH6JhJ4xM5HLQVZQrv/1eDdfgD4qXo5hICdLRvzoOnxYbq7jXVbolXarkYs8r10MXEk2Bc1/zg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712566278; c=relaxed/simple; bh=LrHR5P/LrNI/UQPu1hlqeRHQWbUqR3Ke0r8v10Mpe2c=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r1MYDki0gP8esQdlOK2EN9NgYcFrVhHMtVBCzQBfJRV8ihUYqAPedrixqkxa1+LiUA63pzfJd+WSWyvVUMHnvpOavp1XOiNpsTVKaxq+c/9UPUqBzM/mpVB+9BIyOopyPNEzbMzNyBBwfg0Nb0uUJ3CLjHGQZT1K/S33nn119Ig= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=j1cr+GRr; arc=none smtp.client-ip=185.70.40.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1712566268; x=1712825468; bh=CUkPAONzwDRb/Nkur4cZQic06C81obmvAaXkWg3RRnE=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=j1cr+GRrMMDEkZcscWsT32bBHzNmnUv2/sPLO4VMfHQ4WnUlopjx3XddPs8HG7wJQ Kf+AcdxPcMhQTVUvM1mValC43tW63xzJrRISZ4s77mQlvR6EW2V/6+uB+rKayebDhg SCKC+p8UstTdDBVEUZ/nvdmVDNKz7D+c9WnkaL/I9gpcFCfJiMYm4gqVjH6+3SI6vM g/LwBLJz+/VXvwC9c+6Jm5MeljxZywSpgz8gbiP9X4HsFWDpZcbNUi8A/ug1nPVQ6m Amg9Q9foy4phbHdWfWV9bMYg2drenU45LTXhDaCSTHTgd3vA8FMeDP/7HG3rSSXrKX xYmHkxCcbUlQg== Date: Mon, 08 Apr 2024 08:51:04 +0000 To: Alice Ryhl From: 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 Subject: Re: [PATCH 5/9] rust: list: add List Message-ID: In-Reply-To: References: <20240402-linked-list-v1-0-b1c59ba7ae3b@google.com> <20240402-linked-list-v1-5-b1c59ba7ae3b@google.com> <3f3cf5ae-30df-4032-b752-77126035784c@proton.me> Feedback-ID: 71780778:user:proton 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=utf-8 Content-Transfer-Encoding: quoted-printable On 08.04.24 10:04, Alice Ryhl wrote: > 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`. >=20 > 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. I just was confused by the "due to the writes to `item` below". In the single element case, I also think that the INVARIANT comment of the next `unsafe` block (still visible in this mail) is a bit weird, since the element still is in the list. For a single item, removing it is setting the prev, next and first pointers to null. So I think you might be able to use this for the last bullet point: * If the list has one item, then `next =3D=3D prev =3D=3D item`, so th= ese writes have no effect, since also `(*item).prev =3D=3D prev` and `(*item).next =3D=3D next` by function requirement. For the INVARIANT comment below, I think you also need the case distinction: * If the list had more than one item, `item` is no longer in the list, so the pointers should be null. * If the list had one item, then `item` points to itself, to remove it, we set `prev` and `next` to null and later also `self.first`. What do you think? --=20 Cheers, Benno >=20 > Alice >=20 >>>>> + 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(); >>>>> + }