From patchwork Sat Nov 4 09:16:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "wuqiang.matt" X-Patchwork-Id: 161555 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1546541vqu; Sat, 4 Nov 2023 02:17:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHOilGsbreOuwhSpNyJWAr70J2j86nCJBAJ87ojDhc6NB4QVyJxOVFxq/HJu7E/ja/HgaK8 X-Received: by 2002:a0d:ebcf:0:b0:5a8:78b0:a9fd with SMTP id u198-20020a0debcf000000b005a878b0a9fdmr5736590ywe.29.1699089445216; Sat, 04 Nov 2023 02:17:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699089445; cv=none; d=google.com; s=arc-20160816; b=nbOI4FzlrGkM7jeR3tgDiu18kaPNxlMCnpSVU+z/aZU2N6UEryjY/AtrPQ7ba1iRQZ akjrkGvxzqM1UO2r2ikS327XtvfCiyRbotR+DJQ+1fF3smPHiS/QDloLC6aUXbxjb8BI zB9EAfUVVhpoaEogpJaMaIvl1V/+JnNQyhSYnzVuWqg+98Lo8yY0N4KzkTmJ4z1gDsCB J4+RXrkNm8SnXSOaCltLBVyPedk64zKorrsLk0oMZMz0fyiDjDMc3eAg+J7Rx2aS97tr iM8GF68VFCuMzMAGfVV92F4vhv5r8QkIMwR4/SHAEvCIUpK7zFICiq7oqqlI5C8AxjyP umuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TZsOGiaArG1gPfWJWYyqQWKmeMDqaJOsSKH43M0pjNo=; fh=5cdAk/4eKFcH/8WtTZO0ubPFYqkVoBxeWOjASEhKlHQ=; b=PBWunIOlcFLd/x52GC/dEswpiKKmMezOPs5/Qi2Kv68fwVZmjgvOl9KO6ZaMvzq52S bvpJSteN1K3ztfoSS56H6Jh0UL+FFGrfYL+uprJwBjxWOctO2upf6EP2RWlF8mQVGgcB t4RzbSVSpom3BEaR2er94z/nA6hW5YfXNu1V6T9hGhwwKwQzpr5mdZdcl7q4CD9eug+g ZBzXYenaSBvIkEO0FmnUladvOioeKQ/myMFYB9Kez28FsSakL1HYnxkdI6UkT8SgVhNN RjzuISa3igdpPCsYzXTY4BEntlg49sosGKf3XcHOkJprp90aK8ZauZ7c6Ev35/+bx724 shcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b="Q/U+dBHC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id l6-20020a656806000000b005bd03d2fda6si3105061pgt.350.2023.11.04.02.17.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 02:17:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b="Q/U+dBHC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id F28D880EA94D; Sat, 4 Nov 2023 02:17:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231734AbjKDJRF (ORCPT + 35 others); Sat, 4 Nov 2023 05:17:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231580AbjKDJQ7 (ORCPT ); Sat, 4 Nov 2023 05:16:59 -0400 Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91A2FD49 for ; Sat, 4 Nov 2023 02:16:35 -0700 (PDT) Received: by mail-qk1-x72a.google.com with SMTP id af79cd13be357-7781bc3783fso186448385a.1 for ; Sat, 04 Nov 2023 02:16:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1699089394; x=1699694194; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TZsOGiaArG1gPfWJWYyqQWKmeMDqaJOsSKH43M0pjNo=; b=Q/U+dBHCPN+0cYxnzGDmOICtLzHegbWb2rExRSc9m0SSrRRG/7baJ4tiI/SuE1VeqH qa04UYbzXRvAmHv4GrOQeX3yscLfaLpWQ2YJE1PGNR1RhnTWdLz2K5FtdR6LygDxgSKa OCO/cQoCIsErOX7ebeTijU44VG1x7Xm8FEgn4okcW0i1cy/TJNSFy+k4mIcprYXnUg8E DVIgD2k46XlA4PGlthjXDyoL0LcjTC0J0I5BEkmgDVLFUP0Whel+xniIuj6s7kLFQiPu 634TCks3uHSlEuW9w10j0rQ0kAkET7ZG3SO+JMLnafVcaH8zIzbmxo3KhPE3x/eGpOVS wwfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699089394; x=1699694194; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TZsOGiaArG1gPfWJWYyqQWKmeMDqaJOsSKH43M0pjNo=; b=J9xOeLs/o/eq+YrdLZc/cgGzK18a2vL296XoJ+pUo04uymFb4PY3jr9fqS9BToF/sX zcapgu3PA1IkFsL1XvfC9gIbxUU9N/UPfpJGQ7tsgB7+dJODcnbCj9KQrm3MnernhEKk WoaFToea2R8QeZW4At2It+19KyRPda57shbcXWEI1Dje3wU59UKsiScdb+6YVc7UB7wB Z2Cacv99wOgcGNzGEs2GjjdVvw5kBflxRvEwA2nuPUPGHddQ2gX4LM0jnXMuHOfuZ5nJ 5Po/U/hfmrnrqItI/aUIlPP7wrt2aD+usfGb1I1RDRGubhBygYDP5oBCkdSsqd/8Q9us H0Dw== X-Gm-Message-State: AOJu0YzT9Ub1LfNz5tJWYtU23HW7BKwqRzuaSH02uQRhUsWxNQk8l0pl t/O7NA5mcHJtArFaUC7WsW505Q== X-Received: by 2002:a05:620a:2588:b0:777:2767:6465 with SMTP id x8-20020a05620a258800b0077727676465mr27504451qko.40.1699089394700; Sat, 04 Nov 2023 02:16:34 -0700 (PDT) Received: from devz1.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id d4-20020a170903230400b001cc54202429sm2585127plh.288.2023.11.04.02.16.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 02:16:34 -0700 (PDT) From: "wuqiang.matt" To: vgupta@kernel.org, bcain@quicinc.com, jonas@southpole.se, stefan.kristiansson@saunalahti.fi, shorne@gmail.com, geert@linux-m68k.org, andi.shyti@linux.intel.com, mingo@kernel.org, palmer@rivosinc.com, andrzej.hajda@intel.com, arnd@arndb.de, peterz@infradead.orgm, mhiramat@kernel.org Cc: linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-openrisc@vger.kernel.org, linux-trace-kernel@vger.kernel.org, mattwu@163.com, linux@roeck-us.ne, "wuqiang.matt" Subject: [PATCH v2 1/4] locking/atomic: arc: data size checking in arch_cmpxchg Date: Sat, 4 Nov 2023 17:16:12 +0800 Message-Id: <20231104091615.4884-2-wuqiang.matt@bytedance.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231104091615.4884-1-wuqiang.matt@bytedance.com> References: <20231104091615.4884-1-wuqiang.matt@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sat, 04 Nov 2023 02:17:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781624414071314360 X-GMAIL-MSGID: 1781624414071314360 Macro __cmpxchg() renamed to __cmpxchg_32() to emphasize it's explicit support of 32bit data size, BUILD_BUG_ON() added to avoid any possible misuses with unsupported data types. In case CONFIG_ARC_HAS_LLSC is undefined, arch_cmpxchg() uses spinlock to accomplish SMP-safety, so the BUILD_BUG_ON checking is uncecessary. Signed-off-by: wuqiang.matt Reviewed-by: Masami Hiramatsu (Google) --- arch/arc/include/asm/cmpxchg.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/arc/include/asm/cmpxchg.h b/arch/arc/include/asm/cmpxchg.h index e138fde067de..bf46514f6f12 100644 --- a/arch/arc/include/asm/cmpxchg.h +++ b/arch/arc/include/asm/cmpxchg.h @@ -18,14 +18,16 @@ * if (*ptr == @old) * *ptr = @new */ -#define __cmpxchg(ptr, old, new) \ +#define __cmpxchg_32(ptr, old, new) \ ({ \ __typeof__(*(ptr)) _prev; \ \ + BUILD_BUG_ON(sizeof(*(ptr)) != 4); \ + \ __asm__ __volatile__( \ - "1: llock %0, [%1] \n" \ + "1: llock %0, [%1] \n" \ " brne %0, %2, 2f \n" \ - " scond %3, [%1] \n" \ + " scond %3, [%1] \n" \ " bnz 1b \n" \ "2: \n" \ : "=&r"(_prev) /* Early clobber prevent reg reuse */ \ @@ -47,7 +49,7 @@ \ switch(sizeof((_p_))) { \ case 4: \ - _prev_ = __cmpxchg(_p_, _o_, _n_); \ + _prev_ = __cmpxchg_32(_p_, _o_, _n_); \ break; \ default: \ BUILD_BUG(); \ @@ -65,8 +67,6 @@ __typeof__(*(ptr)) _prev_; \ unsigned long __flags; \ \ - BUILD_BUG_ON(sizeof(_p_) != 4); \ - \ /* \ * spin lock/unlock provide the needed smp_mb() before/after \ */ \