Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp153436lqs; Thu, 13 Jun 2024 06:42:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV6fbUs1dVDoiZT4Zb0hDV8LEmW3Kaf0aoWkbG7Yldoh0vrcEYi2UTvj1D98tC4qO4uATvVIeW+FVG6IKQms6A5KrI/+oSGyN61DlXs7w== X-Google-Smtp-Source: AGHT+IGM0ehBmjX7uHJhW4NowS/X2MmUJ1pm9NVfTB67+QVufvLiHZcis4fIK83bCCNqzCdSmMlG X-Received: by 2002:a17:906:1cc6:b0:a6f:301f:a944 with SMTP id a640c23a62f3a-a6f47d52421mr277964166b.23.1718286151391; Thu, 13 Jun 2024 06:42:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718286151; cv=pass; d=google.com; s=arc-20160816; b=xmLE8w8RwOxt37KHPEKs8vmjkEWoPmQgPe/iOGXkbtU3kgeBL0Ex5r1eDygX7T0GkT o8BiPOFZreGQBDUBzOWdGl2VSgh8UflbJm5dRUJylVGzozCaezSnN9mGu1XYie2uWRsJ Zg0U7n0YWIdP4WwxF5ph1haW8V9eHcRwokzg8JQ4iyW/w2CqisAP+lzWQyZxa/wh9wgc m9GpqaUk3k05ETiyjnXvbWANPevC6cnD7k3iJFAQ7mFEn6jX7hiGodBNyoVdG3OfwhRg gXDN8ip9GXeeap+r2UXWlM5RcrQW2bAua9qHtMljcDT1PBE2DNq10HCCjHVqD1K2Oqry Rp+A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=Bh3yFA46dPP9BP4RFwHcMW7E8X0pV417kdUP+kIvhw4=; fh=ADTEf4TupCb33ST+cZ3rPazdVB3RVNVumhgNConOxwQ=; b=iuE/y+FrchTZIlzPTcCofclD+arzCt5ERn0bpUIXGpOMQPoVGfDEfqD1kWzQMeYH4/ nH+MS3RLuOyWcV/CaOW8uGJVChwU/IIOFNp4E6eczzvj/nKns8zpb+TiWTGi8NRXQLlT pNTdOzZxV0HRd00UmrzXIT9dsuo32mXWM4hbsuriXdNyd69BFt03qoLL7HIytMIO5gix 9vpMdrez7HsJyU2oaclwWjCdIa9rXGHmd0Kf+tyTRAitr8iQon0jKUAVAUo92vRMMc8B qZZd9VGn6rAlVJJXvSn8v/krZ8BQFht+Qo+8ZMmFV74J/SKyyLIorNclTioNJJXz/yLJ yXCw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=nwk3vody; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-213349-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213349-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56d21b28si76066866b.111.2024.06.13.06.42.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 06:42:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213349-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=nwk3vody; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-213349-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213349-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.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 am.mirrors.kernel.org (Postfix) with ESMTPS id DE5A41F235FE for ; Thu, 13 Jun 2024 13:42:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 845261448E9; Thu, 13 Jun 2024 13:42:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="nwk3vody" Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 8352A144D36; Thu, 13 Jun 2024 13:42:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718286137; cv=none; b=P7DU1vObWSTBuxWX0CI/Hwzf7MDDCZl0E0zY9PvNV7mWLDM2v8s9PrZ/jummO4OKT4def1dF/I/9GUpFVkaBL50KExMDNr24GIJ+RsgZ1MbfZnur964OXCcPgrRZHdQB+n8x+OcLBr3SFc8x5C0B8QgxF2Jcu111BTR4VisUiyQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718286137; c=relaxed/simple; bh=gEBQjHna2XbzIzD705NXiOjgONId5w03PKl+TxkD1yE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=PbXz4nVB2Cf/osaZ173qjWATdDrygcjKaNVeM1ygUS6TEG1Vbb90yR2s9ho3FcDb+OBO5CjBuiTqjOOfs3gfirSb+81ZYQZTdzqCr5PSOObdsDTd54CJqc7ePWrSaAA6DfGfpgPxKQFfxlBbY+xu5bkigMmalnw44F8SBHj5aLg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=nwk3vody; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45DDKYdr011166; Thu, 13 Jun 2024 13:42:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s=pp1; bh=B h3yFA46dPP9BP4RFwHcMW7E8X0pV417kdUP+kIvhw4=; b=nwk3vodyUucAMrLTx 7XAVhau3ZuTPC5JX/Hza/L9n7LJdAq3wmTPM+Ly8kB3Eq/aHWhbjnvVkEaKYZB9i IR1E69N4uG7yYjBiUgOwlS6oExV6lVDVlFlGZqufpuWGqolUtWFMoe8JhYwupQce DEDztcOey/E4f8tOSUxrI6Ow/VWX4vgU8BmxdFk0DCQ+szftCz2M+ZpZcZBECQx3 MqT4FIGxNtSqUzpPN3csCrpy8F2dkFFl44oZyEvGOusQrF+mKvj3SpyayiVsIqUY ofMD6We5foSbZXK+kG9zXcJQdC70E45ELfKbaknOWt+oA1cVEEZnb6M/uiJXyb0a 1+dWw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yqq4u1p32-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jun 2024 13:42:02 +0000 (GMT) Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 45DDf9Pa011175; Thu, 13 Jun 2024 13:42:01 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yqq4u1p2y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jun 2024 13:42:01 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 45DD24WS027246; Thu, 13 Jun 2024 13:42:01 GMT Received: from smtprelay05.wdc07v.mail.ibm.com ([172.16.1.72]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3yn21183u2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jun 2024 13:42:01 +0000 Received: from smtpav06.wdc07v.mail.ibm.com (smtpav06.wdc07v.mail.ibm.com [10.39.53.233]) by smtprelay05.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 45DDfwi123528170 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Jun 2024 13:42:00 GMT Received: from smtpav06.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A88E25803F; Thu, 13 Jun 2024 13:41:58 +0000 (GMT) Received: from smtpav06.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A573A5804E; Thu, 13 Jun 2024 13:41:54 +0000 (GMT) Received: from [9.109.198.180] (unknown [9.109.198.180]) by smtpav06.wdc07v.mail.ibm.com (Postfix) with ESMTP; Thu, 13 Jun 2024 13:41:54 +0000 (GMT) Message-ID: Date: Thu, 13 Jun 2024 19:11:52 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] list: introduce a new cutting helper To: Keith Busch Cc: Keith Busch , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, hch@lst.de, sagi@grimberg.me, paulmck@kernel.org, davidgow@google.com, akpm@linux-foundation.org, venkat88@linux.vnet.ibm.com References: <20240612155135.3060667-1-kbusch@meta.com> Content-Language: en-US From: Nilay Shroff In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: yOj-B8kJC8OQ0h8P5quDiiU1kMCIz3af X-Proofpoint-ORIG-GUID: iQODFnnSfOi94haZX-PGOdDd8fq0PmCa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-13_05,2024-06-13_02,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 suspectscore=0 clxscore=1015 impostorscore=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2406130098 On 6/13/24 18:26, Keith Busch wrote: > On Thu, Jun 13, 2024 at 10:26:11AM +0530, Nilay Shroff wrote: >> On 6/12/24 21:21, Keith Busch wrote: >>> +static inline void list_cut(struct list_head *list, >>> + struct list_head *head, struct list_head *entry) >>> +{ >>> + list->next = entry; >>> + list->prev = head->prev; >>> + head->prev = entry->prev; >>> + entry->prev->next = head; >>> + entry->prev = list; >>> + list->prev->next = list; >>> +} >> I am wondering whether we really need the _rcu version of list_cut here? >> I think that @head could point to an _rcu protected list and that's true >> for this patch. So there might be concurrent readers accessing @head using >> _rcu list-traversal primitives, such as list_for_each_entry_rcu(). >> >> An _rcu version of list_cut(): >> >> static inline void list_cut_rcu(struct list_head *list, >> struct list_head *head, struct list_head *entry) >> { >> list->next = entry; >> list->prev = head->prev; >> head->prev = entry->prev; >> rcu_assign_pointer(list_next_rcu(entry->prev), head); >> entry->prev = list; >> list->prev->next = list; >> } > > I was initially thinking similiar, but this is really just doing a > "list_del", and the rcu version calls the same generic __list_del() > helper. To make this more clear, we could change > > head->prev = entry->prev; > entry->prev->next = head; > > To just this: > > __list_del(entry->prev, head); > > And that also gets the "WRITE_ONCE" usage right. Yeah this sounds reasonable. > > But that's not the problem for the rcu case. It's the last line that's > the problem: > > list->prev->next = list; > > We can't change forward pointers for any element being detached from > @head because a reader iterating the list may see that new pointer value > and end up in the wrong list, breaking iteration. A synchronize rcu > needs to happen before forward pointers can be mucked with, so it still > needs to be done in two steps. Oh bother... Agree and probably we may break it down using this API: static inline void list_cut_rcu(struct list_head *list, struct list_head *head, struct list_head *entry, void (*sync)(void)) { list->next = entry; list->prev = head->prev; __list_del(entry->prev, head); sync(); entry->prev = list; list->prev->next = list; } Thanks, --Nilay