Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4159428pxf; Tue, 30 Mar 2021 00:13:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwf3+UDdYUKU3I4koHL3e/9693tlHAcsdkI7n/rcaUdg8AjUdpBzMMpUo3LzpBve1Uuv2ut X-Received: by 2002:aa7:cc03:: with SMTP id q3mr32833087edt.366.1617088438250; Tue, 30 Mar 2021 00:13:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617088438; cv=none; d=google.com; s=arc-20160816; b=QrKYo13cxdEX/Qu274LccnPLLLwVEAk2LeQI8o30EqrqG1L3dXfmLJLm8XBWiLDWts KB20pVCj8+6UoHZw0S6/UkqxJt1SupO2n1E+XE5hJSK9B5YE9ag9V0nu0ZZ00gqmORHi uTfycKAicwC+wk+DI5qRSc2amtzcyGkEGzkq+Qxy2IAUsVWf0vWICEl2o83K3O5AuDLb mMJwk21TOfMRSbri+lZJvnT5na9mBeC7rmoCAVvd//Eldi70oa+32w/B7k+0oYG90VdV NU3PTSYGqki9Q+YTwL+dPRZWbYjv/spQJzuXLU6+4hHt4tJnq1SiWV6oT5YqigObOSAA nJBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=235OiivCpOcXoAw2ZC5cgWDu4GvM8rAbXdUmKAZPPqw=; b=cLau0JMzrkoOQYOh+zb2q/CcaEtiRzPB6iPmg4lYlc4Sk1VXH5Z+ppad6L73CDyvUO O7kvAcf8YPCzjpX/AH0+YIXXJS9s/pMKEMon8+TAwlgTJE6DWFaLvY9ydwHvkqTstWK5 O0NsAiupM2XqzGq7NU2p8rESGW9X7hdQCUqV14ovBk4y86/kHSIYx9fl3f+PKngBPAM+ Teyan7Kp2UtUipT8UqnYegFhtPlLPTkBtI8UtvUaTyfuL7wDczAAb0p1RtpttOWknR5N pnQwM41I+ZtLd/wm8SumJAAH+uNa7RcHAO/jTC4LLPCawNg9g7AaDoP1pBebmcayEbSe DR+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jw5si14712792ejc.103.2021.03.30.00.13.35; Tue, 30 Mar 2021 00:13:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231192AbhC3HM2 (ORCPT + 99 others); Tue, 30 Mar 2021 03:12:28 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:36421 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231124AbhC3HMI (ORCPT ); Tue, 30 Mar 2021 03:12:08 -0400 Received: from mail-ot1-f52.google.com ([209.85.210.52]) by mrelayeu.kundenserver.de (mreue108 [213.165.67.113]) with ESMTPSA (Nemesis) id 1N2m3G-1ld3Gc1HJM-0138q1; Tue, 30 Mar 2021 09:12:06 +0200 Received: by mail-ot1-f52.google.com with SMTP id t23-20020a0568301e37b02901b65ab30024so14724361otr.4; Tue, 30 Mar 2021 00:12:05 -0700 (PDT) X-Gm-Message-State: AOAM5312LOB1OQ+LBYTu/wZBy3A6sVxvfZeTukLGeMj1HbbkPnhNY4Ql x5FkXvVSQHkQlRU8MrwBcbzAzxmnXIn1J3BMayM= X-Received: by 2002:a05:6830:148c:: with SMTP id s12mr26882538otq.251.1617088324803; Tue, 30 Mar 2021 00:12:04 -0700 (PDT) MIME-Version: 1.0 References: <1616868399-82848-1-git-send-email-guoren@kernel.org> <1616868399-82848-4-git-send-email-guoren@kernel.org> In-Reply-To: From: Arnd Bergmann Date: Tue, 30 Mar 2021 09:11:50 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 3/4] locking/qspinlock: Add ARCH_USE_QUEUED_SPINLOCKS_XCHG32 To: Guo Ren Cc: Peter Zijlstra , linux-riscv , Linux Kernel Mailing List , linux-csky@vger.kernel.org, linux-arch , Guo Ren , Will Deacon , Ingo Molnar , Waiman Long , Anup Patel , Sebastian Andrzej Siewior Content-Type: text/plain; charset="UTF-8" X-Provags-ID: V03:K1:dAc5/IYR3tPhlPw55hBn68XavOmrbOPoV9eDq5ASekeKo4KXdBt zG1nND9akWPe1zCpdB3g2XyNcD4NsEvHJIMPgk/mRumNTnCkQt1RQoMiYkNknXjTHkEOtSN IAKcvC5wsIideRGGjimmJ/lfGh9/wuWpx/XXQQJd62TauGO20yCg+FqVkcAj/VAYGrJg4My KAEK8nC3sztcuJUbOpvTw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:2Ml0stvVTjU=:kt/2nob/5Op9UcVdXbiJ1B +CiIPVdQxeKZ9NN7g3MGau8DSrXSHN8K433EbhL0VRMFnPHHso0rmdopG2y6MzhgcGKzU6IKO AwInUVew1aIPfFigXoBbj0Hc2ckCA5VSs+WWzA7U7WMx9lE4DwzzpQJr8WRGhlmV54volstgG /d3jb2nLe4HS+yOPTLS9dxyM0s3BEQIV8kHdcQpiFGQ0ltoggLeTVspxm9ZksMEuFJp7RPN9A vmUldroy1LIE5rU6ppUKTI4U4BAlqeSxrQSFyGPFujb1PAlhUYvH6ycqMKgYr28ZS3uynl5mU xCuRIFl1pQTDamqXonXegn6O15R9wrgp7xzJR7Wv3hEUp++JuoHrrPG7ysvglxbb6+0zTyVg9 dV5cTXI0iTfu+9W92s7ywrJLA3QXx38j3hkx58m10gY5KSY6Mit1DXkGM+jo9PZafxUCfVIAh KTPmigP+pbqNE8A4mX4i5q3Zf3uVZQFU3EA2njg63ToU029Ghwr7pDYBQH+gpvPKz0iaHZGsK V2cSLoK6g9vzoS7ZCHc8o1p+rTqfo59K2JztfZ6iHFlHsELaWp5JDNToR+Lp/9s9IvM/LOIjk zXkONm/ElG2sb+t6SVf+uyLG+1nUyvY+8X Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 30, 2021 at 4:26 AM Guo Ren wrote: > On Mon, Mar 29, 2021 at 9:56 PM Arnd Bergmann wrote: > > On Mon, Mar 29, 2021 at 2:52 PM Guo Ren wrote: > > > On Mon, Mar 29, 2021 at 7:31 PM Peter Zijlstra wrote: > > > > > > > > What's the architectural guarantee on LL/SC progress for RISC-V ? > > > > "When LR/SC is used for memory locations marked RsrvNonEventual, > > software should provide alternative fall-back mechanisms used when > > lack of progress is detected." > > > > My reading of this is that if the example you tried stalls, then either > > the PMA is not RsrvEventual, and it is wrong to rely on ll/sc on this, > > or that the PMA is marked RsrvEventual but the implementation is > > buggy. > > Yes, PMA just defines physical memory region attributes, But in our > processor, when MMU is enabled (satp's value register > 2) in s-mode, > it will look at our custom PTE's attributes BIT(63) ref [1]: > > PTE format: > | 63 | 62 | 61 | 60 | 59 | 58-8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 > SO C B SH SE RSW D A G U X W R V > ^ ^ ^ ^ ^ > BIT(63): SO - Strong Order > BIT(62): C - Cacheable > BIT(61): B - Bufferable > BIT(60): SH - Shareable > BIT(59): SE - Security > > So the memory also could be RsrvNone/RsrvEventual. I was not talking about RsrvNone, which would clearly mean that you cannot use lr/sc at all (trap would trap, right?), but "RsrvNonEventual", which would explain the behavior you described in an earlier reply: | u32 a = 0x55aa66bb; | u16 *ptr = &a; | | CPU0 CPU1 | ========= ========= | xchg16(ptr, new) while(1) | WRITE_ONCE(*(ptr + 1), x); | | When we use lr.w/sc.w implement xchg16, it'll cause CPU0 deadlock. As I understand, this example must not cause a deadlock on a compliant hardware implementation when the underlying memory has RsrvEventual behavior, but could deadlock in case of RsrvNonEventual > [1] https://github.com/c-sky/csky-linux/commit/e837aad23148542771794d8a2fcc52afd0fcbf88 > > > > > It also seems that the current "amoswap" based implementation > > would be reliable independent of RsrvEventual/RsrvNonEventual. > > Yes, the hardware implementation of AMO could be different from LR/SC. > AMO could use ACE snoop holding to lock the bus in hw coherency > design, but LR/SC uses an exclusive monitor without locking the bus. > > RISC-V hasn't CAS instructions, and it uses LR/SC for cmpxchg. I don't > think LR/SC would be slower than CAS, and CAS is just good for code > size. What I meant here is that the current spinlock uses a simple amoswap, which presumably does not suffer from the lack of forward process you described. Arnd