From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27FA8C433ED for ; Wed, 14 Apr 2021 05:54:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06460608FC for ; Wed, 14 Apr 2021 05:54:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348017AbhDNFy5 (ORCPT ); Wed, 14 Apr 2021 01:54:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:58872 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233304AbhDNFyw (ORCPT ); Wed, 14 Apr 2021 01:54:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 49CED611C9 for ; Wed, 14 Apr 2021 05:54:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618379671; bh=e0GvAqItKrgC7xw+mYTZm1jWGWMl1RtZC+QudRQVvVU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=AKyiMYAOp5u74Mfl8iLk7Sxh1yYch8Aicyz+bYIOBK6sJoTIco/QV2z1X/6ORQ8RO k13lHshi4pwQIEK3wXLN66kASyFjysW5HY5pK0v0qcksfMY1EgbEgAkDtK2uijwBU3 uqLHomJ8D0hoNH0oaTyWU4NiyrcofypIE3IdiMVV+L1fAh8kNLtZpgeatZBL08UsxG x8u/OfJL3M/2EA6xntC5qiD/LPkeDXPjBryw2h8selY9QFa9MPqXpGUUe6Bjm2khZK vJBITiYaZMmWPlmUH62OTo0xpRX7sC30OeZTrkKNNi6CbJRVp5uM/o8ut0p+ILEGjL JMLwk0dKJ0V/w== Received: by mail-lj1-f180.google.com with SMTP id l22so14642205ljc.9 for ; Tue, 13 Apr 2021 22:54:31 -0700 (PDT) X-Gm-Message-State: AOAM530u5RN15j1JdVNCPgNjnaEXjkb33X+HSC9Ei5IKxatPwfxeZy0r yW91KLC4PPqi+GznVZWDLjFeeqH1/62uBAVizQ4= X-Google-Smtp-Source: ABdhPJzLhQOFkp2cNfza5RPwNjXsLt4AjtmrFdQ9MA3JHT7YIse6wTSnxKU/n/GZ0uYgcHLjxzwDlxV5nnIYOxZkYsU= X-Received: by 2002:a2e:919a:: with SMTP id f26mr22943414ljg.508.1618379669738; Tue, 13 Apr 2021 22:54:29 -0700 (PDT) MIME-Version: 1.0 References: <20210413104503.GD15806@arm.com> <73cab48b63ea4ba3b1ef532f47d146f4@AcuMS.aculab.com> In-Reply-To: <73cab48b63ea4ba3b1ef532f47d146f4@AcuMS.aculab.com> From: Guo Ren Date: Wed, 14 Apr 2021 13:54:18 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] riscv: locks: introduce ticket-based spinlock implementation To: David Laight Cc: Catalin Marinas , =?UTF-8?Q?Christoph_M=C3=BCllner?= , Peter Zijlstra , Palmer Dabbelt , Anup Patel , linux-riscv , Linux Kernel Mailing List , Guo Ren , "will.deacon@arm.com" , Arnd Bergmann Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 13, 2021 at 6:54 PM David Laight wrote: > > From: Catalin Marinas > > Sent: 13 April 2021 11:45 > ... > > This indeed needs some care. IIUC RISC-V has similar restrictions as arm > > here, no load/store instructions are allowed between LR and SC. You > > can't guarantee that the compiler won't spill some variable onto the > > stack. > > You can probably never guarantee the compiler won't spill to stack. > Especially if someone compiles with -O0. > > Which probably means that anything using LR/SC must be written in > asm and the C wrappers disabled. Agree, and cmpxchg has been widely used in Linux. I think it's the last requirement for complex atomic API, although cmpxchg has ABA problem: CPU0 CPU1 ======= ====== do { old32 = load32; *ptr32 = new32_tmp; *ptr32 = old32; load32 = cmpxchg(ptr32, old32, new32); //still success } while (load32 != old32); That means cmpxhg only cares about the result but not the middle situation. It's different from LR/SC or AMO instructions. > > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales) > -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/