Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4121732pxf; Mon, 29 Mar 2021 22:55:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEmyBqZ5LEKq+iduxsfv3G1DqxJg3wU2modUyPmNxxbOFr/dyInS7WwSGWrJ+BV2W1U8R+ X-Received: by 2002:a17:906:3e89:: with SMTP id a9mr30607854ejj.405.1617083717077; Mon, 29 Mar 2021 22:55:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617083717; cv=none; d=google.com; s=arc-20160816; b=zzJSYqC1Ag4RxcJQtyHIPAaGYSkxjx2CriyBDivGS6qp82rE3cGDhPgYVjKTpv5nD6 GwWI60Hoq2xK4HoWHRKyIdoGrqKiWmFCgLqAthHNSXbO0I9ejHviCNU/DmlPge+IJG43 HC8zRGdacVD42OkDbXenwLrWQJYpJjE2lyUx/rq7hbDoKxKgWq5bYHDiVTh9/znqB7/8 iVpy0cGDHOpQjtj/l4UGPS84ar0AAcMCCWBJlT/Or6K4vbEXi7tQ01eJXN03+W7aLbmY W57LhsCVOfVjaXJHiMT79oXtKyebrp70ZLinqo8Pw+x6IpAznGvSYg4E958gMPT8KkjI vTyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=q6lEE2mLxUSxwFUa7GfL5LXw+GX8ZqMED2HXvAcd790=; b=tha3RSAB9tk3W4TuPmJtQMS+peeajCZR1rGKsbDJjWVZ18sue5H4y208MXg+7llGGH QrF42hxNe1Quxqb72UkFv8dywYC9K6nOgIa7Rc1IiBoUX/4GT1b926KHPO7n1yTlig0N 20Kw34E60C0J23uyzqKoHH5LDaAyjKGL6LnmsIbZs2e+GgnJgWTfSjYcINp9X+Wjh0Il rbkmD+HbicdKbLa2vXef6buGRKaaOAnaK6afgzOBdPHmlEzAQ718AtQ2Ay9am3wGq16k A+DgH6QQQQHK4aOxigq5AlgMQWkdYuhMNryptfQV1cPt4rzdf+kVArYKdhWRRdeNZkQg KU+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b="QWDQj/k/"; 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 s28si14929181ejm.721.2021.03.29.22.54.53; Mon, 29 Mar 2021 22:55:17 -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; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b="QWDQj/k/"; 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 S231145AbhC3Fvb (ORCPT + 99 others); Tue, 30 Mar 2021 01:51:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231154AbhC3FvZ (ORCPT ); Tue, 30 Mar 2021 01:51:25 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05FC6C061762 for ; Mon, 29 Mar 2021 22:51:25 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id u10so18549852lju.7 for ; Mon, 29 Mar 2021 22:51:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=q6lEE2mLxUSxwFUa7GfL5LXw+GX8ZqMED2HXvAcd790=; b=QWDQj/k//08OQqkLgKt3T0BFbwXuqS+LZt6L6iSTc0BsCjEFYh0/VLD9npTeuxxWsQ 97fkc+OgI/HFewPYFVTQjqec9xguXnT4goiwh7cv91Uvzs+fQgLuBy3pfDnHx537JOv+ pBulm1ChNlHQ6wlKqEXZndfqsxQ94GixOKN5sePQBcRIfXZ7lDgwolWcdjeDr2xUtHXI 2a1bUSdW6O31D8XCrS66t7QBaOjTf/YCYiaVLIf2VPF3dI0v34NGPxnf1K6KB45Ftkgr GyBjG9C9MLS1CBL0YWsXov3mtTF1kpCQcG7HMQAUjcL6Wcvqv0it5T+c6D2/A565YeEK Rsxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=q6lEE2mLxUSxwFUa7GfL5LXw+GX8ZqMED2HXvAcd790=; b=E6qfNoG2BQmy/68O+cZdReUV1NQo3VhkzBBCTbaOfuOCmu/jKCqau//8mr3uDNI08W qG0gmYjW2Ngh0cp96F4snU0j3geuroG+MOzQPvFS6i0IsfAwgkthgV/C/5EWjc569T8o UPtQtxSqn8f8AlfIYvrmIRVAutFtbMkkdD45ydFIz6FQ2CEFq1siXb6OR1hI6bY7mJdd qm2Kscg0XTcq8v4xVc+iuIpfNkm/7Z+0OUtomUuDUUNhixxbY264aQJmoHoZFRHWBkcS IqFYrQQJ2b2/WfRAHeT+fbKoYeckmPLIxtI63/uGaJDDYs6D5YgGCEbNGc3sg8CfaEix OGyg== X-Gm-Message-State: AOAM531AfuBeBKTEfdl/aElNIm94NWp2C1ar1NzvRxbzlhyldfDCgiiQ lBH/V4MQvqgEzhsM7f/L+8liotTc/hW9mGpaTrM/ww== X-Received: by 2002:a2e:8114:: with SMTP id d20mr20111828ljg.83.1617083483493; Mon, 29 Mar 2021 22:51:23 -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: Anup Patel Date: Tue, 30 Mar 2021 11:21:12 +0530 Message-ID: Subject: Re: [PATCH v4 3/4] locking/qspinlock: Add ARCH_USE_QUEUED_SPINLOCKS_XCHG32 To: Guo Ren Cc: Arnd Bergmann , Peter Zijlstra , linux-riscv , Linux Kernel Mailing List , linux-csky@vger.kernel.org, linux-arch , Guo Ren , Will Deacon , Ingo Molnar , Waiman Long , Sebastian Andrzej Siewior Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 30, 2021 at 7:56 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: > > > > > > > > On Mon, Mar 29, 2021 at 01:16:53PM +0200, Peter Zijlstra wrote: > > > > > Anyway, an additional 'funny' is that I suspect you cannot prove = fwd > > > > > progress of the entire primitive with any of this on. But who car= es > > > > > about details anyway.. :/ > > > > > > > > What's the architectural guarantee on LL/SC progress for RISC-V ? > > > > > > funct5 | aq | rl | rs2 | rs1 | funct3 | rd | opcode > > > 5 1 1 5 5 3 5 7 > > > LR.W/D ordering 0 addr width dest AMO > > > SC.W/D ordering src addr width dest AMO > > > > > > LR.W loads a word from the address in rs1, places the sign-extended > > > value in rd, and registers a reservation set=E2=80=94a set of bytes t= hat > > > subsumes the bytes in the addressed word. SC.W conditionally writes a > > > word in rs2 to the address in rs1: the SC.W succeeds only if the > > > reservation is still valid and the reservation set contains the bytes > > > being written. If the SC.W succeeds, the instruction writes the word > > > in rs2 to memory, and it writes zero to rd. If the SC.W fails, the > > > instruction does not write to memory, and it writes a nonzero value t= o > > > rd. Regardless of success or failure, executing an SC.W instruction > > > *invalidates any reservation held by this hart*. > > > > > > More details, ref: > > > https://github.com/riscv/riscv-isa-manual > > > > I think section "3.5.3.2 Reservability PMA" [1] would be a more relevan= t > > link, as this defines memory areas that either do or do not have > > forward progress guarantees, including this part: > > > > "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. > > [1] https://github.com/c-sky/csky-linux/commit/e837aad23148542771794d8a2f= cc52afd0fcbf88 Is this about your C-sky architecture or your RISC-V implementation. If these PTE bits are in your RISC-V implementation then clearly your RISC-V implementation is not compliant with the RISC-V privilege spec because these bits are not defined in RISC-V privilege spec. Regards, Anup > > > > > 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. > > > arm64 is already in the situation of having to choose between > > two cmpxchg() implementation at runtime to allow falling back to > > a slower but more general version, but it's best to avoid that if you > > can. > Current RISC-V needn't multiple versions to select, and all AMO & > LR/SC has been defined in the spec. > > 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. > > > > > Arnd > > > > [1] http://www.five-embeddev.com/riscv-isa-manual/latest/machine.html#a= tomicity-pmas > > -- > Best Regards > Guo Ren > > ML: https://lore.kernel.org/linux-csky/