Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp747753lqb; Wed, 17 Apr 2024 09:32:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXgQGMLgsigrWLS3tTgfUIOo7/dGgCKrNjvYkJB+TJlbWyzBzKaeRB/pIy7YN7cO/panttJr+NndOd5rxZIkQ3Uw6C3lmCqeiA+ywTCOQ== X-Google-Smtp-Source: AGHT+IEkJAogPZbdrscDpeGxhesnYoHG0kTRezToUqt4sJiZ2+SY00D5W1BtNWKa35VVdNpr5pFi X-Received: by 2002:a17:906:c10f:b0:a52:3ca9:9bda with SMTP id do15-20020a170906c10f00b00a523ca99bdamr5860389ejc.22.1713371526126; Wed, 17 Apr 2024 09:32:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713371526; cv=pass; d=google.com; s=arc-20160816; b=YMU7CPzoF2rNz6DyKhCv7vPwMq4i0XDJQTYPRsAJr/UBaklkDNjchNQHY7yckdnOKa O3ICKXbgJZIuU/875WG1LWnuGau89oKrxX4JKltsQz/VxgcadIdm8qEPkqjHHGSRZF2v jesvaAOnd17V+PXyxEagB9XVb5cmyi39ol23KehIPtqbbaggeLrXAGmIR43tdGz4gEXp raOTzu6Nhh5ZNjaouVUecVW/cvRCoX3KiwADBdd4U9UTndbCtFaNkRcN87x1figIUZqw Hjm+qr3UaliIOmJl6XEyJrsz/0b1hXr+RnYmz9hsOeXPkb5QTqXg3+pFeLSoS4NXattl 3vCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=O4FJeYjzVSrCJLMWVOfo4rKcH+oK+crdFCS4dm+nSJw=; fh=/7AqYDe4mQKoJZ8Roi+FJPgiYc3Gyu8g/sTN1gbnCOE=; b=wSiJ4HLNdLBhhyEeKDH4mZ4rWvB6q83sVhtmKSHY0AkLrsd341WDkbxkI/DVvy2NpY AqjVUacAZ7p/01ytOiZy8h0O83F3LNSSZS73pP9fImqv7iD3mLhHJ4dZYBPr2QCC8jgm pxZTnmqxpWGfUbW9zVMP+wpK32XihR86DBx2H+sPKBTgwIZqqvQxqZnUrGz5Y1+OAPhH 9HPIUW7YOgSYve/6M7PEs3ykuRQB/Y1fsWwYWhk470098UWyF6Ly6CrUtHb9Nigcjsuu 1yejqD8lpyolp8tx/+Qvz0kYnNAsoV9pFY8bVXZC88vUM3prOy/o/KdwSHB0M34YXGWw p/gg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="bJMw/qGp"; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-148411-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148411-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z10-20020a1709063aca00b00a51dfda479asi6839619ejd.43.2024.04.17.09.32.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 09:32:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-148411-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="bJMw/qGp"; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-148411-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148411-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2D1711F22E75 for ; Wed, 17 Apr 2024 11:37:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C1D7413CF9A; Wed, 17 Apr 2024 11:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="bJMw/qGp" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 5D75813C9B2; Wed, 17 Apr 2024 11:37:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713353837; cv=none; b=eCYoKbx4/9J8JRNvL4fORMlC/kaUom7nxU7M5LQ+c/72S7qAwDbRH48jb+6Z6pwmkfiPxM8NThZ4z2mQ786KC/lDje5vAWcdbBBZx0XU+xyK2NXkzN0B5jTzshAPVOgxAsBYrqHoKirRH4L/LhMEmBDi8fA4v33ABVm6s4JjyhI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713353837; c=relaxed/simple; bh=ni1rHrQkZPj0oa4mBUOmn8s86m7db/sCZzs6v/o4CR8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XkfIxwl9+Pt1c+X27fylONGLeZU01zrNMBx6hlLi8n9gMUYyT0/zrX1cZ3v+zeDDJyWxDBbY5+wuARXgy92uwXcn3JoDrUbWKzhQOfIrIE+4PSoS++Wc9JkhMDKV9KEycfnuG9oDzM7pfUqQrDsohjLQA8lv+ZTxfW2TVkbUalU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=bJMw/qGp; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org 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=O4FJeYjzVSrCJLMWVOfo4rKcH+oK+crdFCS4dm+nSJw=; b=bJMw/qGpR0b9/jwlohMK0wYLf1 3Iwlt7Xkt9gigpNoAdTdquU7sEYatU38PE510DDkwfDrHKtGRQbpAidJD8zSXTfq4tTFDwlgDLXVh F4Y3GC71PcDSALfxgIDKtiFbh5WsoIjhmwBOl9qMNila0XmgFv+8lb9bZypVyLO8eapLGebDXE6O7 lRkgfqEQYfMeV7FRigv654M98vQQzL6C3V2ehXS4ULWzyg9sYCgt0NgCb1yQC7Pbo5Mf0gKAGJKVP 3p54qePNYQE4fziXioJM6YxOb3p9UMIqBk2fXDPPa5uS43dzqlUATOkKTBpTn5qzbw2y3pOKR0JRf 5Jpkbk5Q==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rx3b5-00000002pWR-24HE; Wed, 17 Apr 2024 11:37:03 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 2553630047C; Wed, 17 Apr 2024 13:37:03 +0200 (CEST) Date: Wed, 17 Apr 2024 13:37:03 +0200 From: Peter Zijlstra To: Elizabeth Figura Cc: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?iso-8859-1?Q?Andr=E9?= Almeida , Wolfram Sang , Arkadiusz Hiler , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Randy Dunlap , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng Subject: Re: [PATCH v4 02/27] ntsync: Introduce NTSYNC_IOC_WAIT_ALL. Message-ID: <20240417113703.GL30852@noisy.programming.kicks-ass.net> References: <20240416010837.333694-1-zfigura@codeweavers.com> <20240416010837.333694-3-zfigura@codeweavers.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240416010837.333694-3-zfigura@codeweavers.com> On Mon, Apr 15, 2024 at 08:08:12PM -0500, Elizabeth Figura wrote: > + if (atomic_read(&sem->all_hint) > 0) { > + spin_lock(&dev->wait_all_lock); > + spin_lock_nest_lock(&sem->lock, &dev->wait_all_lock); > > + prev_count = sem->u.sem.count; > + ret = post_sem_state(sem, args); > + if (!ret) { > + try_wake_all_obj(dev, sem); > + try_wake_any_sem(sem); > + } > > + spin_unlock(&sem->lock); > + spin_unlock(&dev->wait_all_lock); > + } else { > + spin_lock(&sem->lock); > + > + prev_count = sem->u.sem.count; > + ret = post_sem_state(sem, args); > + if (!ret) > + try_wake_any_sem(sem); > + > + spin_unlock(&sem->lock); > + } > > if (!ret && put_user(prev_count, user_args)) > ret = -EFAULT; vs. > + /* queue ourselves */ > + > + spin_lock(&dev->wait_all_lock); > + > + for (i = 0; i < args.count; i++) { > + struct ntsync_q_entry *entry = &q->entries[i]; > + struct ntsync_obj *obj = entry->obj; > + > + atomic_inc(&obj->all_hint); > + > + /* > + * obj->all_waiters is protected by dev->wait_all_lock rather > + * than obj->lock, so there is no need to acquire obj->lock > + * here. > + */ > + list_add_tail(&entry->node, &obj->all_waiters); > + } This looks racy, consider: atomic_read(all_hints) /* 0 */ spin_lock(wait_all_lock) atomic_inc(all_hint) /* 1 */ list_add_tail() spin_lock(sem->lock) /* try_wake_all_obj() missing */ I've not yet thought about if this is harmful or not, but if not, it definitely needs a comment. Anyway, I need a break, maybe more this evening.