Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2542060rwb; Thu, 29 Sep 2022 11:32:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4GtMgkVWAUWvfoB1yLM4d5ItCpefmc/OP53SFQhkdto5LIGvC8tJ9P4S/eIzFZPxLvDfjd X-Received: by 2002:a17:907:7210:b0:783:37b0:b5ca with SMTP id dr16-20020a170907721000b0078337b0b5camr3609018ejc.689.1664476348307; Thu, 29 Sep 2022 11:32:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664476348; cv=none; d=google.com; s=arc-20160816; b=c1CwzICmCyd2Oj0kxAVqvXIolJ/g4KKBQ5fRn8T4eR433clpuNiuQxafz+ouuHdkAz gMK61FIJtfx2NABpkVGWmyNw+q22gUQYe739Ae5/YEYT6gcoeoSomD/pwx8eYbgESsK7 u3FwsyrhK+px99T5YGaN1cOad2QyZ9RfnvOIG7wszchWDym650AKTXHonnn3schNYBJn cTkeKr2E8p8hrsJ15F9Zg6df6EbE/709nbYOboMZzARTcLJAEMHa+4HXNVuycUWIIIX0 wf06METKpIx334FJuvl/aDfIMkgHcQk1y/z5qXaMZ/SjTA8okvAp/G6Ndf1E48ep86oO vcAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=YRzdq8mq9arpjI/e/1rqcxjVTskm5LfNGtLLpdc1IU0=; b=bwhOfbVoVtM1xDtVAp0J7oHwVYjLpM82+1MdQ2DUc1ddN0P3PvMB/6mTxjPwQihyLO QLk0UVcgZyPHsZYm3aFV2E6NF+Ck//+9F7dv0KmJ/K/FNtSHtQ+una/BuLJCuaSwoEQW ATwsAjrwF/qrPL/KdDBMxTLJWyn/b2dFOE/4zIvZpgmgopXh97KOKG+9jYnEVn6AO5rk GnYeUhFLuyDRKhEEkJw6RPGZI4yFLeovERjSqVn6O2+ScEkRRh/AoYeOJedwhd/I+4dJ GqsCi49hRcZv+NmeU9up0Lu2ZpRKoz4K1ToNsuFG/XSCsT9z8/aaB/BA6qtBYwmi8tRH QuHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f51KM3qK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ht16-20020a170907609000b00783c42d2da2si10152587ejc.415.2022.09.29.11.32.02; Thu, 29 Sep 2022 11:32:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f51KM3qK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235229AbiI2SHI (ORCPT + 99 others); Thu, 29 Sep 2022 14:07:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229519AbiI2SHH (ORCPT ); Thu, 29 Sep 2022 14:07:07 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83ADC1B95E9 for ; Thu, 29 Sep 2022 11:07:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664474825; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YRzdq8mq9arpjI/e/1rqcxjVTskm5LfNGtLLpdc1IU0=; b=f51KM3qKEi53q72iduCQLTMNYtcrDMCmq4MjYGDW4V6GE40rFzlX/zjsddFsq7GuwFkWEc jZ6bd6G3ssryWo9N3QOMY95mcV4+aI4CEBBolwG2Gz8zGhd8clbsvnO0mE1w/f219FAArV yCvFxLgPduFsQTuAb2OVckbrskRBk+8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-564-PJ7P_HZ5OEeGIqvd5K4rqw-1; Thu, 29 Sep 2022 14:07:00 -0400 X-MC-Unique: PJ7P_HZ5OEeGIqvd5K4rqw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6E2B2833948; Thu, 29 Sep 2022 18:07:00 +0000 (UTC) Received: from [10.22.8.248] (unknown [10.22.8.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFBBB42238; Thu, 29 Sep 2022 18:06:59 +0000 (UTC) Message-ID: <6530f135-e8ac-bb6c-4715-1ea8f76cf4c4@redhat.com> Date: Thu, 29 Sep 2022 14:06:59 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH] locking/rwsem: Prevent non-first waiter from spinning in down_write() slowpath Content-Language: en-US To: Mukesh Ojha Cc: linux-kernel@vger.kernel.org, john.p.donnelly@oracle.com, Hillf Danton , Peter Zijlstra , Will Deacon , Boqun Feng , Ingo Molnar References: <20220929180413.107374-1-longman@redhat.com> From: Waiman Long In-Reply-To: <20220929180413.107374-1-longman@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE 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 On 9/29/22 14:04, Waiman Long wrote: > A non-first waiter can potentially spin in the for loop of > rwsem_down_write_slowpath() without sleeping but fail to acquire the > lock even if the rwsem is free if the following sequence happens: > > Non-first waiter First waiter Lock holder > ---------------- ------------ ----------- > Acquire wait_lock > rwsem_try_write_lock(): > Set handoff bit if RT or > wait too long > Set waiter->handoff_set > Release wait_lock > Acquire wait_lock > Inherit waiter->handoff_set > Release wait_lock > Clear owner > Release lock > if (waiter.handoff_set) { > rwsem_spin_on_owner((); > if (OWNER_NULL) > goto trylock_again; > } > trylock_again: > Acquire wait_lock > rwsem_try_write_lock(): > if (first->handoff_set && (waiter != first)) > return false; > Release wait_lock > > It is especially problematic if the non-first waiter is an RT task and > it is running on the same CPU as the first waiter as this can lead to > live lock. > > Fixes: d257cc8cb8d5 ("locking/rwsem: Make handoff bit handling more consistent") > Signed-off-by: Waiman Long > --- > kernel/locking/rwsem.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) Mukesh, can you test if this patch can fix the RT task lockup problem? Thanks, Longman