Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 046DF17CA for ; Wed, 25 Oct 2023 01:51:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="iQJyN1Uo" Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0197010CE for ; Tue, 24 Oct 2023 18:51:17 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6b5e6301a19so4906342b3a.0 for ; Tue, 24 Oct 2023 18:51:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1698198676; x=1698803476; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=KOKKG0CgjGN6zyzGsDHHzCAGDWujCIMfweGLdxpJv/0=; b=iQJyN1UoOT4ABPNokFjPmwoM+bJs2gDt005JqVgBz7DP2bl+5GEeJiGqX3OLna0bvt mLf8+NjJ5DlTEu1wy34Cjp2Q2boneElnnHUd91CWk9/dwKo1ZCzu7m0xAR5vn46rUaO8 qSXSBZcGhBcw/wv+HcOunaXsM5wBnW9eEYAmCorS1Z6WGbRENM9SRYpIgXUyL8jd/PY+ xNlTaIO+yhKkqHa7XOzF9pYPpVxZv9wVbRah8MUSxxMmFsxhckrIYXd0DsbR31K1ZhRU 58XrvfXqk44iQ6/WkPszR6tErEg8NvF3ODY6nvsZBClxYxhDMdvjU6vmwWkDMqAeJM57 hFbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698198676; x=1698803476; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KOKKG0CgjGN6zyzGsDHHzCAGDWujCIMfweGLdxpJv/0=; b=MX4jglYy5EzvLcd/P8lL1yRdZxB3JEMOg0Heh3BrGJ+e99CNiiuLvoI1kFzn17grx0 eM6mpaTxRkqA6I0f3yCubZLG0ByB1pLIWssXxEmc7YvcOC/OcnMnnVKt30CG+ffuFv7V ycvUNdOOUuvTtk/wDaYRC/mQLVwmP1HX2RS7X6KXxqyKbxoS8mn2pbqIMgCSLwWGpWvZ qoScAxFY9Xqe3WXpWJkk0SMcsjUG2vmZb/pBuhddtyGsPu/0ANq3kFoo80L0QazHare/ vQC1bmvfa0mm8GC52uTm9W6Dcvbewybux7K5fNk1rUu2wOofb+C/3y6/afslkGFoqUT5 59pg== X-Gm-Message-State: AOJu0YwM3XgZLfU669TCQ86E7UFbHatiGnnhtbLyELsR/XBcZIpyJtSo RzxN5stHOLczGWJ/90A+NI/9PcSKj+1XMMeb2MQ= X-Google-Smtp-Source: AGHT+IG7gggf3CdB7cn4+Kno5v6ImLdC4JHYDmnIzMEbnywNYNLqmtpUHLKjRHRNCAIri01OycpZyg== X-Received: by 2002:a05:6a00:178e:b0:690:3793:17e5 with SMTP id s14-20020a056a00178e00b00690379317e5mr17276979pfg.4.1698198676463; Tue, 24 Oct 2023 18:51:16 -0700 (PDT) Received: from [192.168.6.6] ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id p15-20020aa7860f000000b00690cd981652sm8256267pfn.61.2023.10.24.18.51.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Oct 2023 18:51:16 -0700 (PDT) Message-ID: Date: Wed, 25 Oct 2023 09:51:09 +0800 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH] locking/atomic: sh: Use generic_cmpxchg_local for arch_cmpxchg_local() Content-Language: en-US To: "Masami Hiramatsu (Google)" , Mark Rutland Cc: Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Peter Zijlstra , linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org References: <169815917362.8695.13904684741526725648.stgit@devnote2> <20231025084255.bc70b9d0e5af9f6f3d2d4735@kernel.org> From: "wuqiang.matt" In-Reply-To: <20231025084255.bc70b9d0e5af9f6f3d2d4735@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2023/10/25 07:42, Masami Hiramatsu (Google) wrote: > On Tue, 24 Oct 2023 16:08:12 +0100 > Mark Rutland wrote: > >> On Tue, Oct 24, 2023 at 11:52:54PM +0900, Masami Hiramatsu (Google) wrote: >>> From: Masami Hiramatsu (Google) >>> >>> Use generic_cmpxchg_local() for arch_cmpxchg_local() implementation >>> in SH architecture because it does not implement arch_cmpxchg_local(). >> >> I do not think this is correct. >> >> The implementation in is UP-only (and it only >> disables interrupts), whereas arch/sh can be built SMP. We should probably add >> some guards into for that as we have in >> . > > Isn't cmpxchg_local for the data which only needs to ensure to do cmpxchg > on local CPU? asm-generic/cmpxchg.h is only for UP, will throw an error for SMP building: #ifdef CONFIG_SMP #error "Cannot use generic cmpxchg on SMP" #endif SH arch seems it does have SMP systems. The arch/sh/include/asm/cmpxchg.h has the following codes: #if defined(CONFIG_GUSA_RB) #include #elif defined(CONFIG_CPU_SH4A) #include #elif defined(CONFIG_CPU_J2) && defined(CONFIG_SMP) #include #else #include #endif > So I think it doesn't care about the other CPUs (IOW, it should not touched by > other CPUs), so it only considers UP case. E.g. on x86, arch_cmpxchg_local() is > defined as raw "cmpxchg" without lock prefix. > > #define __cmpxchg_local(ptr, old, new, size) \ > __raw_cmpxchg((ptr), (old), (new), (size), "") > > > Thank you, > > >> >> I think the right thing to do here is to define arch_cmpxchg_local() in terms >> of arch_cmpxchg(), i.e. at the bottom of arch/sh's add: >> >> #define arch_cmpxchg_local arch_cmpxchg I agree too. Might not be performance optimized but guarantees correctness. >> Mark. >> >>> >>> Reported-by: kernel test robot >>> Closes: https://lore.kernel.org/oe-kbuild-all/202310241310.Ir5uukOG-lkp@intel.com/ >>> Signed-off-by: Masami Hiramatsu (Google) >>> --- >>> arch/sh/include/asm/cmpxchg.h | 2 ++ >>> 1 file changed, 2 insertions(+) >>> >>> diff --git a/arch/sh/include/asm/cmpxchg.h b/arch/sh/include/asm/cmpxchg.h >>> index 288f6f38d98f..e920e61fb817 100644 >>> --- a/arch/sh/include/asm/cmpxchg.h >>> +++ b/arch/sh/include/asm/cmpxchg.h >>> @@ -71,4 +71,6 @@ static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old, >>> (unsigned long)_n_, sizeof(*(ptr))); \ >>> }) >>> >>> +#include >>> + >>> #endif /* __ASM_SH_CMPXCHG_H */ >>> > >