Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp2716591rdb; Tue, 26 Dec 2023 02:47:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgClbsX40m3RjEJx1TfRoDwA2wJSIGpUQZJP+IjL4Y0EISw5+cUtL8IcbdGXL0JchUZA90 X-Received: by 2002:a17:903:11d0:b0:1d0:9fdb:a95b with SMTP id q16-20020a17090311d000b001d09fdba95bmr2640890plh.101.1703587644857; Tue, 26 Dec 2023 02:47:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703587644; cv=none; d=google.com; s=arc-20160816; b=v3vfCrhVo4SAp8E0hmo1gvbJM4cshuGJkKd4AtcnXzHoPvCOLP+KSzjJOx68KgMnNx F7WuhrdVv7wul9IohwOy5KwZElULwua+VM3LCSukAwzDx6jfbKYYsUdbVaPv8GRnE0MW +UBV5PLFWhS+5hC71bwV+dhwelthtqYQ2r8ktWfwbicPBIviuto00f74SIbeYcE9w/xe KWqB5W8fhdjMyvAquXZdCsRr1v2K9VSxn9WPW1KlmNLaCqK8VFRwVB4FiY4+LCUj+T1U Dw20dOsbQkqIN5pBjc4W2W90w94ml+J4xIqj38iQ0kOZ8sRDquHdcXa+SUw31151vgNR M2gw== ARC-Message-Signature: i=1; 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:references:in-reply-to:message-id :date:subject:cc:to:from; bh=N9JJtMFel+gLacN1+o5SR+kyQmb2076SLO98bB5Pbdc=; fh=GFKx5GS5Z21R0JSv0nN/feUTam2fh3EFp7QMjERW6uc=; b=Ztyt33itljqM9RdK8wyX6Kv80qJR43pfEAfqkGtcVXk3mddLwQmGYu9J7qFQX0sMsr vMiIwB2unmj5k+O8+URANkwAnOORsaZ6D1rnqtbZZOpmR2EfJLGTg3cyh5+DkXWQi1m6 ops3x8UJgk1xgsIF/A0+T+S5a/YnNdQeg1k0Hx4PHDLqSJCWiOuSd/oLeBUcxpB6Z0tt WhYQckUR6JFYNO0haKzzWU8SRjmzpRSuhsT8SP5z6TLokwepFDMz6QYYCF9SNUICd8Am mj7ubV41/ejIExpVSgirL+mhWEjNn3wFYX8cHTeSTU+E2q3+kLwXDntPk5h5iG4cbM0c KLBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-11478-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11478-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u5-20020a17090282c500b001d1db5e39b4si9166975plz.172.2023.12.26.02.47.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 02:47:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11478-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-11478-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11478-linux.lists.archive=gmail.com@vger.kernel.org" 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 897AB282F5E for ; Tue, 26 Dec 2023 10:47:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C44224E1BB; Tue, 26 Dec 2023 10:47:21 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mail115-95.sinamail.sina.com.cn (mail115-95.sinamail.sina.com.cn [218.30.115.95]) (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 1BE554E1A1 for ; Tue, 26 Dec 2023 10:47:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sina.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sina.com X-SMAIL-HELO: localhost.localdomain Received: from unknown (HELO localhost.localdomain)([116.24.9.48]) by sina.com (172.16.235.24) with ESMTP id 658AAF2600004821; Tue, 26 Dec 2023 18:47:07 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com Authentication-Results: sina.com; spf=none smtp.mailfrom=hdanton@sina.com; dkim=none header.i=none; dmarc=none action=none header.from=hdanton@sina.com X-SMAIL-MID: 93595545088862 X-SMAIL-UIID: 373CAD4AC90E4AE3A8DF32B71374E1FC-20231226-184707-1 From: Hillf Danton To: Matthew Wilcox Cc: "Eric W. Biederman" , Maria Yu , linux-kernel@vger.kernel.org Subject: Re: [PATCH] kernel: Introduce a write lock/unlock wrapper for tasklist_lock Date: Tue, 26 Dec 2023 18:46:52 +0800 Message-Id: <20231226104652.1491-1-hdanton@sina.com> In-Reply-To: <87o7eu7ybq.fsf@email.froward.int.ebiederm.org> References: <20231213101745.4526-1-quic_aiquny@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Wed, 13 Dec 2023 12:27:05 -0600 Eric W. Biederman > Matthew Wilcox writes: > > 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. lock(&lock->wait_lock) enable irq int lock(&lock->wait_lock) You are adding chance for recursive locking. > > Yes. It seems to make sense to distinguish between write_lock_irq and > write_lock_irqsave and fix this for all of write_lock_irq. > > Either that or someone can put in the work to start making the > tasklist_lock go away. > > Eric