Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5429131rdb; Wed, 13 Dec 2023 08:22:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IEDCt6NGxaC+3BMZNurQcfCX2atNqumDLqHkxNJ+AYKaom30Ui/jEC7B+CiT1DT0NbvC5vs X-Received: by 2002:a05:6a20:938b:b0:18f:97c:8237 with SMTP id x11-20020a056a20938b00b0018f097c8237mr4730181pzh.65.1702484569648; Wed, 13 Dec 2023 08:22:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702484569; cv=none; d=google.com; s=arc-20160816; b=wFdiLGbUe/+JYkeDNtbpcsfS3L4OJrpxyK5uixnmYz6fLlFiOOyiwVhMOaZmAjX86/ 2slhKLHutP1A6cSQbxfyXn9nGzjtc4JlkFXJsmvFpWGUS9mLoaJzYR0IwoAoX1Kh4FSP B98TmCyZ52cuJLx0rvih28Y44/nEbxcJ3l0NEwFW1NReWLsHTsZ0Sk9Zyay5sHIfBjuG 4B1/9kcBg8ydY8gXtcbkkS+kDVRuXJVDsLBPzX2h3lrhlN5T6cngXjcXYoE/40w/emi6 jnCJ44k+lH3adM9ORl3+IdAy2y+fgOd4iJgx5oJnIk1cyjkkB1iMl2UyC7vrGvASo7Xt p5CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=zh20bVNgEauOmKOMVTT+oQhslL42e63cd3mafc5QuMg=; fh=CFVeJKHuqm8+kBmSY/L49yU5gZaXuX1oroC/dEtKLC4=; b=KUn6M6sMQCePKkYGly8X53MAx9TnLmxdk/dlYe+97tCM4En3OKrm7eWmaULEOjNHBZ OfmEn45jRi1BzukeymZV/3yHGcLrNPaZBA+Vuuy/u0SEqT/bWiAh3DImHbh97+4KxkzU 182jUo8ZQCpaNzWCnzjiWYfJTolgRdxf3h0QKbkAX4AQCp3kt6klyTgMq7S0PHlse4HQ Xkyhbgj3jHtnEl7P5XjPeHIojxQb6vPOym/t3ISpNRN+nI7Dz2P19UxfuYruC8F3C4SG IuQIeQxW6nc0omGaBMxoCItk+Ceu/u4C9+FQZegSMMJ5PUgaraPF877CLDZvfoywJzym +ccQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=PD81Z9+H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id p38-20020a634f66000000b005c663b4fcc5si5462555pgl.458.2023.12.13.08.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 08:22:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=PD81Z9+H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 20F47803098C; Wed, 13 Dec 2023 08:22:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233328AbjLMQWj (ORCPT + 99 others); Wed, 13 Dec 2023 11:22:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233087AbjLMQWh (ORCPT ); Wed, 13 Dec 2023 11:22:37 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD99083; Wed, 13 Dec 2023 08:22:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=zh20bVNgEauOmKOMVTT+oQhslL42e63cd3mafc5QuMg=; b=PD81Z9+Hz5q5itQ3DmYt+lymtK rbAWH1HZLxLHUKVZEBh1CUDT1Gcq2raouKY3J6f0oeH7MF1Qf8jNPcX/QD3F1eFfA9LYtxKJd5XWM NYaKwqm3OkJb3wbVkc1KlSShBk3kmXX51ppvBALlC/6FF9RmPt7z14e8kNIq+p9OjLeoJ8incaTEl KOTQkgC3JC43xmofru4rI8AJ9KtlWAwIWUWqXJukMc/XBEEbnP2/cKKLw2+8MxRihfAv2AEGd9O8h qbjPKxgqUiDMxuGernieuindthAfSXsJbsHcHuxrI0NOKrda94Ap5leFuQ+F1PdOn+bvhlsLYOakq VQ/4sHXg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1rDRzx-002B4P-Kt; Wed, 13 Dec 2023 16:22:13 +0000 Date: Wed, 13 Dec 2023 16:22:13 +0000 From: Matthew Wilcox To: Maria Yu Cc: ebiederm@xmission.com, kernel@quicinc.com, quic_pkondeti@quicinc.com, keescook@chromium.or, viro@zeniv.linux.org.uk, brauner@kernel.org, oleg@redhat.com, dhowells@redhat.com, jarkko@kernel.org, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: Re: [PATCH] kernel: Introduce a write lock/unlock wrapper for tasklist_lock Message-ID: References: <20231213101745.4526-1-quic_aiquny@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231213101745.4526-1-quic_aiquny@quicinc.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 13 Dec 2023 08:22:48 -0800 (PST) On Wed, Dec 13, 2023 at 06:17:45PM +0800, Maria Yu wrote: > +static inline void write_lock_tasklist_lock(void) > +{ > + while (1) { > + local_irq_disable(); > + if (write_trylock(&tasklist_lock)) > + break; > + local_irq_enable(); > + cpu_relax(); This is a bad implementation though. You don't set the _QW_WAITING flag so readers don't know that there's a pending writer. Also, I've seen cpu_relax() pessimise CPU behaviour; putting it into a low-power mode that takes a while to wake up from. I think the right way to fix this is to pass a boolean flag to queued_write_lock_slowpath() to let it know whether it can re-enable interrupts while checking whether _QW_WAITING is set.