Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2445944pxp; Mon, 21 Mar 2022 20:43:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzF4obkY9yACo+MQM/cg871+bsJKIYY6gjbTdT0AsfuVnnceKX8x3Y7NrJVAuGDZkCyLIEG X-Received: by 2002:aa7:92cf:0:b0:4fa:3b47:7408 with SMTP id k15-20020aa792cf000000b004fa3b477408mr25744058pfa.72.1647920635342; Mon, 21 Mar 2022 20:43:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647920635; cv=none; d=google.com; s=arc-20160816; b=IjqQdSpRQcaJByXvhuVASkktnwSprKfp9IUVBRE+pFKCdClbBJN7cS1zYQs53bKFaE vGhNbsLItazRXuKiG3zloIxn3tFjuditUUy2aBcivruoGz5j9ZC1ayJCeYC+C6fD8qdB p1VW+6kciB4ZauhZmXXURO8E/k/TKnQUoKOXW7VCDoaJdj50kqsIBgGTBXAoRz8kcWjc 15sMgmMvbg8MDFaj81VbUqq+ot4ZFK1iLgvc2d5DdfS1F3Vmk72PtZshlWx70qzlC+4l FnSLv8SsdRJHd1kwfb9d66pubVLv2mxKM1ok+OiQXtX/xLwgV4GXEdkALkCF7pCUal9v xHKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Hh+l+cDJOH+rmHGFl5Z8Zd7K4dLUYHJocdz9v2HO6zA=; b=H/j0FjUlKIXxY2Z5FstuSqFQ4Iqe13JWCqBcsW9XQWP7U0ZPAygkJCAwto0nZkJjMc G1Q87Vku8Ej0Z09zKNuv0v5zGDwCr6c8XtZEqOuVo8xX+3Yyt2nilYYipYvrI7aXwjME iTWTEZkf1C6XKRoXwawH9ApoovCYy1qH4+b4dyllSEmtgPUtafJ5GfXvFH2LFyhaSDBF eIYKmy+sz5oiK7hUmgpNP2wtxdNv8PF9lPLlpjBvu3c+C4DnGcP07sFytAkXipRC6MZ+ N5F4TLWcSoYl+3lt4eiaK+Z+CPPW02E7iE1Y4kEuUCwujNsxiAGHHisQ7aYBeyZU084j Ei5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DjtmHKsk; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 7-20020a170902e9c700b00153b2d16635si12368837plk.573.2022.03.21.20.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 20:43:55 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DjtmHKsk; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 99EFF52B21; Mon, 21 Mar 2022 20:10:54 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235945AbiCVDMM (ORCPT + 99 others); Mon, 21 Mar 2022 23:12:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235946AbiCVDMK (ORCPT ); Mon, 21 Mar 2022 23:12:10 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 136DD50468; Mon, 21 Mar 2022 20:10:42 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id x2so823678plm.7; Mon, 21 Mar 2022 20:10:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Hh+l+cDJOH+rmHGFl5Z8Zd7K4dLUYHJocdz9v2HO6zA=; b=DjtmHKskX4TxeKbVb7A93JrGp2xt18gLwaV/CfU6iNuYFEdrAE1RP9ngjSmWlQq13X yHAxabQDUqqWL45RtLOICtJf40+Gw0+ps6Y9Uq1uM+L7l1QUKvFRirvhaJOrT/kAg/9X wNvXOLCWc4HE2YMGhHYgJ8xDGCbuo1qWdoXBThR4yz4nKi3EbI10zq7VCWwUZP44Znq5 Ht1vQtGaa9S25e03tNwBJ5eR8sbMM2GdHdFFgFD8RHjkpInfUCZ1l+WWPm7viu8CUe5C aGh+Dea1u2wzHcWT4ZdW1u6zquKoTRTy4hix8MEkUKRaOqMESjh5vkUuC7SFEKzSVR4X hysA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Hh+l+cDJOH+rmHGFl5Z8Zd7K4dLUYHJocdz9v2HO6zA=; b=Ujlgh+Rw0I3ZL0C3wVGLgMZHloQdC45HFa4ldy3B+iOFX/M++3PCIl/R+60yOTR1cf 1C6TkxwxzjnUc7p8u5IsaWGmgkovx2bLHPaGrVk9eN2sfM0+KaTMI+wV+BHDMoekiiJJ c7SMqK7ucza4qdJj/FRc68HkAXM3LY1MZKehMX8Tc/V0fb2/AE5WxFNUSGZ9CY6FS6yr noYQ7mhlYWvfL+RrNVzQrcD7eu0aPrXa6f/zmw8DQ5eyh2L2BnfprqZhtPii6lNuTPl+ 2aUFwPyAm+YasZaFwImekzz215UYfFP+y8xWnQbkQVOGMht8JXtJzkiyPDYYmmSt9hG6 ToBg== X-Gm-Message-State: AOAM532vn41Mku17htVz+hwX+tO/j8eNxPaLP/RV+fkP8MOyzECkDtFG jf4fYmR46zrax8OJ3HvoawY= X-Received: by 2002:a17:902:e9d3:b0:154:6dd6:2521 with SMTP id 19-20020a170902e9d300b001546dd62521mr5289232plk.59.1647918641193; Mon, 21 Mar 2022 20:10:41 -0700 (PDT) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id s141-20020a632c93000000b0038134d09219sm16260355pgs.55.2022.03.21.20.10.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 20:10:37 -0700 (PDT) Date: Tue, 22 Mar 2022 12:10:36 +0900 From: Stafford Horne To: guoren@kernel.org Cc: palmer@dabbelt.com, arnd@arndb.de, boqun.feng@gmail.com, longman@redhat.com, peterz@infradead.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org, openrisc@lists.librecores.org, Palmer Dabbelt , linux-riscv@lists.infradead.org Subject: Re: [OpenRISC] [PATCH V2 1/5] asm-generic: ticket-lock: New generic ticket-based spinlock Message-ID: References: <20220319035457.2214979-1-guoren@kernel.org> <20220319035457.2214979-2-guoren@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220319035457.2214979-2-guoren@kernel.org> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Hello, There is a problem with this patch on Big Endian machines, see below. On Sat, Mar 19, 2022 at 11:54:53AM +0800, guoren@kernel.org wrote: > From: Peter Zijlstra > > This is a simple, fair spinlock. Specifically it doesn't have all the > subtle memory model dependencies that qspinlock has, which makes it more > suitable for simple systems as it is more likely to be correct. > > [Palmer: commit text] > Signed-off-by: Palmer Dabbelt > > -- > > I have specifically not included Peter's SOB on this, as he sent his > original patch > > without one. > --- > include/asm-generic/spinlock.h | 11 +++- > include/asm-generic/spinlock_types.h | 15 +++++ > include/asm-generic/ticket-lock-types.h | 11 ++++ > include/asm-generic/ticket-lock.h | 86 +++++++++++++++++++++++++ > 4 files changed, 120 insertions(+), 3 deletions(-) > create mode 100644 include/asm-generic/spinlock_types.h > create mode 100644 include/asm-generic/ticket-lock-types.h > create mode 100644 include/asm-generic/ticket-lock.h > > diff --git a/include/asm-generic/ticket-lock.h b/include/asm-generic/ticket-lock.h > new file mode 100644 > index 000000000000..59373de3e32a > --- /dev/null > +++ b/include/asm-generic/ticket-lock.h ... > +static __always_inline void ticket_unlock(arch_spinlock_t *lock) > +{ > + u16 *ptr = (u16 *)lock + __is_defined(__BIG_ENDIAN); As mentioned, this patch series breaks SMP on OpenRISC. I traced it to this line. The above `__is_defined(__BIG_ENDIAN)` does not return 1 as expected even on BIG_ENDIAN machines. This works: diff --git a/include/asm-generic/ticket-lock.h b/include/asm-generic/ticket-lock.h index 59373de3e32a..52b5dc9ffdba 100644 --- a/include/asm-generic/ticket-lock.h +++ b/include/asm-generic/ticket-lock.h @@ -26,6 +26,7 @@ #define __ASM_GENERIC_TICKET_LOCK_H #include +#include #include static __always_inline void ticket_lock(arch_spinlock_t *lock) @@ -51,7 +52,7 @@ static __always_inline bool ticket_trylock(arch_spinlock_t *lock) static __always_inline void ticket_unlock(arch_spinlock_t *lock) { - u16 *ptr = (u16 *)lock + __is_defined(__BIG_ENDIAN); + u16 *ptr = (u16 *)lock + IS_ENABLED(CONFIG_CPU_BIG_ENDIAN); u32 val = atomic_read(lock); smp_store_release(ptr, (u16)val + 1); > + u32 val = atomic_read(lock); > + > + smp_store_release(ptr, (u16)val + 1); > +} > +