Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp394503rdb; Thu, 22 Feb 2024 07:06:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXBWxqfpkAiLJ8c09eaXbCBNS353TxEPUCe/vmwLxLdI9BCd20E1+y8LBNU69TFRlFGHxgytXrihTWVCkmrPQgfiO/ayghw5XKYmHIxQg== X-Google-Smtp-Source: AGHT+IGZ6EMiqi9tiE68OPje2gSV4Dfv89QRC1PJ/a9qYE+tgJY9wfi0Pry4k3hlhEvmMZ3YZO0J X-Received: by 2002:a92:d7c8:0:b0:365:27ec:e94a with SMTP id g8-20020a92d7c8000000b0036527ece94amr13430306ilq.16.1708614405663; Thu, 22 Feb 2024 07:06:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708614405; cv=pass; d=google.com; s=arc-20160816; b=ST/+cG6Bm4Gwi5vCpI59kBn5suwsOYCvQ9v+gzgN016FJP8+f1W6LaqREh0yhst95z Y4HM9Z8bzalziXPP2Ikv3P248cYcbU+rqsI4SeLuLKZ3zK06diXlJ8GfzXB8CeL6Uqav ZDP9GnTnVQTPCG7OciXrBiG3DwtZ1MOG3ey5C78iCYbf8T4bUzP0zrIOxbCWerRnqbJo SeYw5yI122TfPqjkbdzCwjgeWTODVoSksU+oisz4JEXYWodhbJJvYVRryqOunyVt+g/H w7j+7iHK//qoTt9QOaWtK6A3IvoFr7t3sVy7bmjQBJp6FCyc+33Ow2WwMHsTlyrkgYJf EwWA== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=FbM+mRMvNwlvXjAUfTOnQe38QADdr2GSal9VUe0AgiQ=; fh=c25v70+ehGE+SiLl84UT2m6flxwHxsFK+3J6BVG3azM=; b=XxeU/a9ZIRS/sd2OG7JKwJ78CUUQAXN84YSl1gbT1AK9gi/0r/9DxLcen5jQR1sKNe cbCbJ5JaRbZRq5561PWpxJREYodojQnoaZg8BIFVETHCJ77RbhRgcPTSSKy+bSALC2J1 aftw6borYPcKn89xDUlohPhRpPjIjc0Z5BHAm7p+IsuuwONYVsO5vuYbf52wD6gELYcF IXCecf6s6mA6agmYWjNYNHJ0UHhkzHfG6u8wBPM7k2oY79gft/KGI9x81Pl20XbIfMGG 80HfutMU3zi7/7SXkalNDybPma9lKVkpUagM7C7Bciajm3dg4cxsYJYH7idQHcprFZoo bT8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HI7DptFb; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-76745-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76745-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id e1-20020a656881000000b005dc81a16015si10023564pgt.118.2024.02.22.07.06.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 07:06:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76745-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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HI7DptFb; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-76745-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76745-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 04CF42855C5 for ; Thu, 22 Feb 2024 15:06:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0049414E2DC; Thu, 22 Feb 2024 15:06:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HI7DptFb" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 ABC4B14AD11 for ; Thu, 22 Feb 2024 15:06:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708614364; cv=none; b=LV2VKvmMXmWGffj4KcPO4hiaZAjCm9bsFBm3czk19hu2UZFmnw0JHXvkxQXeYfBa9N8Ra9wlmnLqNnbNS3jx4CfF+nmwsCHw60z6VBmCECPq7e/JkdqZqtSVYLM0eI1JkimKyrZezbaDfsNCs8qDWa0NyDUZS9qyRvgeSPa5LPE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708614364; c=relaxed/simple; bh=jmNJZxpioD2ev6CzuLGJoXoioGPNxz85LSb8buJEQ6o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MUhpMv4YzdUugyVTBBiqYcC5B+AGpPFSvixG1bb683Ij3YkBla+88hSUggAfS0LYSMSEmk0Kro9exaDN171VwhTs42P4HX3n3PU0hw8rH1bgxK/omjb/jmhKgDgmN4AzujVWtOmkM2GP0wyt6Q+SzVRPUtlapYGUzP760DqBbWY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HI7DptFb; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708614360; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FbM+mRMvNwlvXjAUfTOnQe38QADdr2GSal9VUe0AgiQ=; b=HI7DptFb+ethCiHlrmhJksYHq/H9qn/NttII1VOipXpW1FppMVFX9Zr4z3s/NFfFtnNE1J LxIn/v3XNzz+zvO6/5EbyHEnqMLalMmgIOhydCu0P/V0K/gq9LfiKiyEdgilZ1YQLFCQ5C GOz8AGDoVtZOtJHncv5EB8Y/LacY06I= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-488-Em10oE56NmmLMvffq-YPhw-1; Thu, 22 Feb 2024 10:05:58 -0500 X-MC-Unique: Em10oE56NmmLMvffq-YPhw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2C1D785A58A; Thu, 22 Feb 2024 15:05:57 +0000 (UTC) Received: from llong.com (unknown [10.22.33.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87B5B112131D; Thu, 22 Feb 2024 15:05:56 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , Andrew Morton Cc: linux-kernel@vger.kernel.org, George Stark , Waiman Long Subject: [PATCH v2 3/4] locking/rwsem: Clarify that RWSEM_READER_OWNED is just a hint Date: Thu, 22 Feb 2024 10:05:39 -0500 Message-Id: <20240222150540.79981-4-longman@redhat.com> In-Reply-To: <20240222150540.79981-1-longman@redhat.com> References: <20240222150540.79981-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 Clarify in the comments that the RWSEM_READER_OWNED bit in the owner field is just a hint, not an authoritative state of the rwsem. Signed-off-by: Waiman Long Reviewed-by: Boqun Feng --- kernel/locking/rwsem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c index 2340b6d90ec6..c6d17aee4209 100644 --- a/kernel/locking/rwsem.c +++ b/kernel/locking/rwsem.c @@ -35,7 +35,7 @@ /* * The least significant 2 bits of the owner value has the following * meanings when set. - * - Bit 0: RWSEM_READER_OWNED - The rwsem is owned by readers + * - Bit 0: RWSEM_READER_OWNED - rwsem may be owned by readers (just a hint) * - Bit 1: RWSEM_NONSPINNABLE - Cannot spin on a reader-owned lock * * When the rwsem is reader-owned and a spinning writer has timed out, @@ -1002,8 +1002,8 @@ rwsem_down_read_slowpath(struct rw_semaphore *sem, long count, unsigned int stat /* * To prevent a constant stream of readers from starving a sleeping - * waiter, don't attempt optimistic lock stealing if the lock is - * currently owned by readers. + * writer, don't attempt optimistic lock stealing if the lock is + * very likely owned by readers. */ if ((atomic_long_read(&sem->owner) & RWSEM_READER_OWNED) && (rcnt > 1) && !(count & RWSEM_WRITER_LOCKED)) -- 2.39.3