Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3490041pxb; Wed, 14 Apr 2021 06:44:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwog9sFH0liAmOKPlG6fMl4JnSowh2U+YXUs+AcJkOIILEU+sgal/s2qlw6BFSHZI78bV7 X-Received: by 2002:a50:fc94:: with SMTP id f20mr41209278edq.77.1618407884182; Wed, 14 Apr 2021 06:44:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618407884; cv=none; d=google.com; s=arc-20160816; b=M4wE6GU1rX5uUduajjjlJUiLxz7hocuHsBF7kcvU0JW2vGlCULFH9sq96pQFNE3O4x gYtVszg7BpOP1UT6H+Ms4WdbBap//8LGL0Gw+U9C3ocorKzmjcKa/aPMG3GIuTadVm6/ 0EU2AVXivdV1v9UAsOHyWwAfRh4PmoOf/r9HZOx1XTV7iUfaYKtxlwrgwAO8+iRfyZnV 4tfvGvq0CU4R6M5LDKW8eGjJsJRrlnjLirHudTKxaBIjewm4dEjamcIS3DiP/FYFOlQq jll1Xz4AvZsqm9nuuhcTI8WK8/fBLG1LvUAdyqmHh2X+WlJ1feoO46nTPr98yY+qlceM 1t6A== 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:dkim-signature; bh=suKFVplHEDGdd0IZVMlkQSClqz6TcOtdB/x48D6wuMA=; b=W9BLOtFfToVz9/yycZA5bP/H7PvdqckBU8x/lPcMVQCB45KGiJHKJLvOAB9ZISM64z j0cV8J2L+xtOgFoHhvHAxeVNASnkvQ6F79VmXEAN6/leb3yaihm/pYnUkHllxeYGblKB LkCZdOsHXmbAOeJz2uP/Wrslp/c8P4OPmjjrIUCa9hPjrUGKEemrU4GNQhmvKsnlP3qr 4fsWVbwHq5daDsGX7Y6ZvsmDdw94amFgPtNiiluOP2LlVBafgcH9ZH6aCfYpxaFm4GYM QOJWJNqf3w/QuZOwsmHWmcABhVfRZv14pai6WeZOwSaqBJkKiQJrLEDWQ1ODSZIuYjiz AAww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AKyiMYAO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v19si13381173edc.70.2021.04.14.06.44.19; Wed, 14 Apr 2021 06:44:44 -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=@kernel.org header.s=k20201202 header.b=AKyiMYAO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233324AbhDNFyy (ORCPT + 99 others); Wed, 14 Apr 2021 01:54:54 -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-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/