Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3398123rwl; Mon, 27 Mar 2023 13:29:30 -0700 (PDT) X-Google-Smtp-Source: AKy350ZQn2KYDkii5lMadDNMhKOzbk751KmoI2VdXNHylQjy4ozTgbXTFBmeV3XnmW1prkA7n+Y/ X-Received: by 2002:a17:902:c9d2:b0:1a1:a9a4:ba26 with SMTP id q18-20020a170902c9d200b001a1a9a4ba26mr10197835pld.8.1679948970506; Mon, 27 Mar 2023 13:29:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679948970; cv=none; d=google.com; s=arc-20160816; b=jeS2zsWxELQpcYurjexgWcph5+qAqhADJIHRWFeoiqLwhr+FMTtW94kbPl4eegEJz4 REdxtLZtz4v2vw0uGHMlzGFoc+2UNEXFADMSpVou8rakmpMxxCxYEQJaHrtdjLnd/Lj6 G/KkIy2fHUNh+Cr1FNcrQgixwMkT54JQFkw+Dr8kwe/v2gK2+M8S462nXvGxLIbMCgCN T6cLDNzptO9xUsfvwtPsC2PpJ9GM/D+cgwTfv4Rj6i/qd4vEDHB4y9/kjeaoneXKIRPc cJvCDkYGEuqvNCHRSNpKWZ/wEzj+1KGpC/aNQvB8SiUul+QqK/BG7DKcf0Wb+K1k/bIn UG2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OyPFo4v7z/4QuNDV6N3/A+RFNemmtx8czMnE3tFUcd8=; b=Gyz4HrEiq06uNKsv3Fi9MDoZpiqmWhYD+8LOcahmVzbbM01Ej/1YYg8OgA4QCxJin4 CVMyGieJ2TvWwAYjWJAYswcJylRP+JwnjI6/nK/3fU9kV/x/JUrdcjoI1D6TR8cZNXCX f4zMorVpgqiaAaEKT0rGMxIbhzqh2/PhKtWtICL0GdsU814Ssjll1C6It0GCH+4y/9lp 16mBreJSgUiho9QG6KhX2wbzAKp7AxU3fWTXQCamTCd+tZMjVSTBdIyJ+L52zFfCa7fu jucZFtj8JbDksjXlHVtjci/1asq2Q3R6PgASW3WgcufUUsrqjIpHXYjqFmAsIiq9Zt1u jj6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QEwqzNqs; 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 w4-20020a656944000000b00513185220f0si9926146pgq.709.2023.03.27.13.29.17; Mon, 27 Mar 2023 13:29:30 -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=QEwqzNqs; 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 S229544AbjC0UZT (ORCPT + 99 others); Mon, 27 Mar 2023 16:25:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229912AbjC0UZO (ORCPT ); Mon, 27 Mar 2023 16:25:14 -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 0BD593AA5 for ; Mon, 27 Mar 2023 13:24:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679948667; 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=OyPFo4v7z/4QuNDV6N3/A+RFNemmtx8czMnE3tFUcd8=; b=QEwqzNqsC6VevxoVx/OSO9gD3wF2487FA+EjAZzuQIsvYiooo0WMaHxE3+n62WBRNuEXwE KXA6DsIscPRP7vDUOeWE8LT5zQ7c6VYmNtqvEqB2UYGScXvnQl7l/1KI7Q2rE7NYv5ElrF blEEhOr/9ccPUInGN0WXDJo1DPaMckM= 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-626-Rithe-3aNKO8GnJWYN1xow-1; Mon, 27 Mar 2023 16:24:23 -0400 X-MC-Unique: Rithe-3aNKO8GnJWYN1xow-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4C5C6884EC0; Mon, 27 Mar 2023 20:24:23 +0000 (UTC) Received: from llong.com (unknown [10.22.17.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id D979B2027040; Mon, 27 Mar 2023 20:24:22 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 2/8] locking/rwsem: Enforce queueing when HANDOFF Date: Mon, 27 Mar 2023 16:24:07 -0400 Message-Id: <20230327202413.1955856-3-longman@redhat.com> In-Reply-To: <20230327202413.1955856-1-longman@redhat.com> References: <20230327202413.1955856-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 From: Peter Zijlstra Ensure that HANDOFF disables all spinning and stealing. Signed-off-by: Peter Zijlstra (Intel) --- kernel/locking/rwsem.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c index e589f69793df..4b9e492abd59 100644 --- a/kernel/locking/rwsem.c +++ b/kernel/locking/rwsem.c @@ -468,7 +468,12 @@ static void rwsem_mark_wake(struct rw_semaphore *sem, adjustment -= RWSEM_FLAG_HANDOFF; lockevent_inc(rwsem_rlock_handoff); } + /* + * With HANDOFF set for reader, we must + * terminate all spinning. + */ waiter->handoff_set = true; + rwsem_set_nonspinnable(sem); } atomic_long_add(-adjustment, &sem->count); @@ -755,6 +760,10 @@ rwsem_spin_on_owner(struct rw_semaphore *sem) owner = rwsem_owner_flags(sem, &flags); state = rwsem_owner_state(owner, flags); + + if (owner == current) + return OWNER_NONSPINNABLE; /* Handoff granted */ + if (state != OWNER_WRITER) return state; -- 2.31.1