From patchwork Mon Sep 30 23:08:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167809 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CD71F912 for ; Mon, 30 Sep 2019 23:10:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A1AC62081B for ; Mon, 30 Sep 2019 23:10:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="P1V+7VW3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732114AbfI3XIS (ORCPT ); Mon, 30 Sep 2019 19:08:18 -0400 Received: from mail-eopbgr710105.outbound.protection.outlook.com ([40.107.71.105]:33459 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732018AbfI3XIS (ORCPT ); Mon, 30 Sep 2019 19:08:18 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cl+Fd7JwP3EPA3BYzGPPubbIffr28ZHNVPXKgXy+hQnsqjGgvKRoXc+2gupOlhDNCkuwWLlAZqS02wS/q+0uN9yuB63i5S8OFtz5livjNz/dUEvzrrYlFpt62zYHRPQ9hJWNfXjcPYnAjBN2fjmKA4eQ3JxOx4SqexLYUmaPLm7U1bV9RK6L6kX5/8XTmEJB/gM/T0/bp7lsVEpiB1uX1g4PulHARpXXY9DtuBCYLk3tcueaiJsGHNXdrxwXB6/a/gkqoe18Ga0TjIH+amLBgNBmXTHm95BVxlDRqrBIF3KeNytnEaeXTkaA6kPxC83a6dXQD59O3ryrfIgtPD2xTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IllcbHu49UnIzLg2B1vxZlSaLf4pVPVKbtzaaUYQwSg=; b=X8DGjc27eSe5jw3PfkiW0MR40mwpoFn/Z9W4cEbFSR2HHTHDeu5wiCnShJ3fReHQAX/08y8iGvqD3vvc2BmIIXYE+BCSL2rlNZR5XBjtY8fLCGroGM6P4QvtHZE5ZK/ScA1dk3cECscikuv+prL66CFrtpgmbSGh5Uym42lL7UHue2jd/74B8PWRaFK+YXh3thFxU5OM9rMWWd5JPE+JewAL0xxt/GwzIoZ+23ThP+pudjb8KWOxiHnF3EVg1G7vZRrwtWug8CU4E5HlTa1Qa/xP8z5cVM4AXA/aKaAtY7eCpDZ6IaWRUWe46NEqH5ni0x23L8BIwdl9UXlTk4jycA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IllcbHu49UnIzLg2B1vxZlSaLf4pVPVKbtzaaUYQwSg=; b=P1V+7VW3cariwhBs9S90N+uTqIEoXfblO1DhUPcAH0HyqM8a1dW+8V/YyXy0jB7uuBVmXOJAQ1Pci4XwG6gAzb3h06++SWtDXjYqIgKyi/KcKi0Eny6vrqk/77RfIfr56KaGPCFgMXkCgvrDk2ys4uh1VaPvR/yt1n5hmHnwQ7Q= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1709.namprd22.prod.outlook.com (10.164.206.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.20; Mon, 30 Sep 2019 23:08:15 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:15 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 01/37] MIPS: Unify sc beqz definition Thread-Topic: [PATCH 01/37] MIPS: Unify sc beqz definition Thread-Index: AQHVd+Pwc/PZwTOkWk+5nsJHrv9cbQ== Date: Mon, 30 Sep 2019 23:08:15 +0000 Message-ID: <20190930230806.2940505-2-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0e672a2c-5249-42c0-2cfe-08d745fb12b8 x-ms-traffictypediagnostic: MWHPR2201MB1709: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4502; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(39840400004)(376002)(346002)(396003)(136003)(199004)(189003)(2351001)(66476007)(66556008)(66946007)(64756008)(66446008)(107886003)(99286004)(6486002)(52116002)(5640700003)(6436002)(25786009)(478600001)(14454004)(76176011)(26005)(6512007)(5660300002)(71200400001)(71190400001)(1076003)(4326008)(186003)(42882007)(6506007)(11346002)(256004)(486006)(44832011)(476003)(2616005)(14444005)(446003)(54906003)(316002)(7736002)(305945005)(6116002)(2906002)(3846002)(81156014)(81166006)(102836004)(50226002)(6916009)(386003)(36756003)(8676002)(8936002)(66066001)(2501003);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1709;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: uxSaKN6eGf5LXd2MClFbFUKaY+bL0243GdcLdGY10favhYSiEYs+X6sPh48KNtcVRcwfmKZkdF7XdEeGz8gTfqACE8g4Eu65n7xPSTb2XE0JGK66+W/k8x4d0ViTgT8rBojZ4MBbVnEyXixHKqkdqqy3gwUzLCvN+WpOaTfGsvex0z3hLcnRDOn7quIqZveQKsBklfSyEXfMWQ1hcCBtbpku9LzVrp+lRMW7aofnGYoycxCWlGFyyUEvM5xKPaoEfEoXnX9d4gwhHozfr+iPyFeLcdp7HjVaLT0SUwacxLaQ4tWvpn4HCvUd7s9KcT5qSdv/JNCTfaSIYYOaRqm2CdwEaWczHC2gUVfOQA3JcEt2fzk1TzZ+SsF1VZAvNdW/FeEPkAG4duXTHqpA8qsfYRjvxRKfPkuNJkvVnL6xoHY= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0e672a2c-5249-42c0-2cfe-08d745fb12b8 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:15.1661 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: a2vXDTOHSXPvOWdjRUlkP0jpNnHxVeSwWleMAjarmzfT/WsrQqd57nGZaHHQMT85vA9yn9Eujku0l9D8Lo2Ogw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1709 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org We currently duplicate the definition of __scbeqz in asm/atomic.h & asm/cmpxchg.h. Move it to asm/llsc.h & rename it to __SC_BEQZ to fit better with the existing __SC macro provided there. We include a tab in the string in order to avoid the need for users to indent code any further to include whitespace of their own after the instruction mnemonic. Signed-off-by: Paul Burton --- arch/mips/include/asm/atomic.h | 28 +++++++++------------------- arch/mips/include/asm/cmpxchg.h | 20 ++++---------------- arch/mips/include/asm/llsc.h | 11 +++++++++++ 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h index bb8658cc7f12..7578c807ef98 100644 --- a/arch/mips/include/asm/atomic.h +++ b/arch/mips/include/asm/atomic.h @@ -20,19 +20,9 @@ #include #include #include +#include #include -/* - * Using a branch-likely instruction to check the result of an sc instruction - * works around a bug present in R10000 CPUs prior to revision 3.0 that could - * cause ll-sc sequences to execute non-atomically. - */ -#if R10000_LLSC_WAR -# define __scbeqz "beqzl" -#else -# define __scbeqz "beqz" -#endif - #define ATOMIC_INIT(i) { (i) } /* @@ -65,7 +55,7 @@ static __inline__ void atomic_##op(int i, atomic_t * v) \ "1: ll %0, %1 # atomic_" #op " \n" \ " " #asm_op " %0, %2 \n" \ " sc %0, %1 \n" \ - "\t" __scbeqz " %0, 1b \n" \ + "\t" __SC_BEQZ "%0, 1b \n" \ " .set pop \n" \ : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (v->counter) \ : "Ir" (i) : __LLSC_CLOBBER); \ @@ -93,7 +83,7 @@ static __inline__ int atomic_##op##_return_relaxed(int i, atomic_t * v) \ "1: ll %1, %2 # atomic_" #op "_return \n" \ " " #asm_op " %0, %1, %3 \n" \ " sc %0, %2 \n" \ - "\t" __scbeqz " %0, 1b \n" \ + "\t" __SC_BEQZ "%0, 1b \n" \ " " #asm_op " %0, %1, %3 \n" \ " .set pop \n" \ : "=&r" (result), "=&r" (temp), \ @@ -127,7 +117,7 @@ static __inline__ int atomic_fetch_##op##_relaxed(int i, atomic_t * v) \ "1: ll %1, %2 # atomic_fetch_" #op " \n" \ " " #asm_op " %0, %1, %3 \n" \ " sc %0, %2 \n" \ - "\t" __scbeqz " %0, 1b \n" \ + "\t" __SC_BEQZ "%0, 1b \n" \ " .set pop \n" \ " move %0, %1 \n" \ : "=&r" (result), "=&r" (temp), \ @@ -205,7 +195,7 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v) " .set push \n" " .set "MIPS_ISA_LEVEL" \n" " sc %1, %2 \n" - "\t" __scbeqz " %1, 1b \n" + "\t" __SC_BEQZ "%1, 1b \n" "2: \n" " .set pop \n" : "=&r" (result), "=&r" (temp), @@ -267,7 +257,7 @@ static __inline__ void atomic64_##op(s64 i, atomic64_t * v) \ "1: lld %0, %1 # atomic64_" #op " \n" \ " " #asm_op " %0, %2 \n" \ " scd %0, %1 \n" \ - "\t" __scbeqz " %0, 1b \n" \ + "\t" __SC_BEQZ "%0, 1b \n" \ " .set pop \n" \ : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (v->counter) \ : "Ir" (i) : __LLSC_CLOBBER); \ @@ -295,7 +285,7 @@ static __inline__ s64 atomic64_##op##_return_relaxed(s64 i, atomic64_t * v) \ "1: lld %1, %2 # atomic64_" #op "_return\n" \ " " #asm_op " %0, %1, %3 \n" \ " scd %0, %2 \n" \ - "\t" __scbeqz " %0, 1b \n" \ + "\t" __SC_BEQZ "%0, 1b \n" \ " " #asm_op " %0, %1, %3 \n" \ " .set pop \n" \ : "=&r" (result), "=&r" (temp), \ @@ -329,7 +319,7 @@ static __inline__ s64 atomic64_fetch_##op##_relaxed(s64 i, atomic64_t * v) \ "1: lld %1, %2 # atomic64_fetch_" #op "\n" \ " " #asm_op " %0, %1, %3 \n" \ " scd %0, %2 \n" \ - "\t" __scbeqz " %0, 1b \n" \ + "\t" __SC_BEQZ "%0, 1b \n" \ " move %0, %1 \n" \ " .set pop \n" \ : "=&r" (result), "=&r" (temp), \ @@ -404,7 +394,7 @@ static __inline__ s64 atomic64_sub_if_positive(s64 i, atomic64_t * v) " move %1, %0 \n" " bltz %0, 1f \n" " scd %1, %2 \n" - "\t" __scbeqz " %1, 1b \n" + "\t" __SC_BEQZ "%1, 1b \n" "1: \n" " .set pop \n" : "=&r" (result), "=&r" (temp), diff --git a/arch/mips/include/asm/cmpxchg.h b/arch/mips/include/asm/cmpxchg.h index 79bf34efbc04..5d3f0e3513b4 100644 --- a/arch/mips/include/asm/cmpxchg.h +++ b/arch/mips/include/asm/cmpxchg.h @@ -11,19 +11,9 @@ #include #include #include +#include #include -/* - * Using a branch-likely instruction to check the result of an sc instruction - * works around a bug present in R10000 CPUs prior to revision 3.0 that could - * cause ll-sc sequences to execute non-atomically. - */ -#if R10000_LLSC_WAR -# define __scbeqz "beqzl" -#else -# define __scbeqz "beqz" -#endif - /* * These functions doesn't exist, so if they are called you'll either: * @@ -57,7 +47,7 @@ extern unsigned long __xchg_called_with_bad_pointer(void) " move $1, %z3 \n" \ " .set " MIPS_ISA_ARCH_LEVEL " \n" \ " " st " $1, %1 \n" \ - "\t" __scbeqz " $1, 1b \n" \ + "\t" __SC_BEQZ "$1, 1b \n" \ " .set pop \n" \ : "=&r" (__ret), "=" GCC_OFF_SMALL_ASM() (*m) \ : GCC_OFF_SMALL_ASM() (*m), "Jr" (val) \ @@ -130,7 +120,7 @@ static inline unsigned long __xchg(volatile void *ptr, unsigned long x, " move $1, %z4 \n" \ " .set "MIPS_ISA_ARCH_LEVEL" \n" \ " " st " $1, %1 \n" \ - "\t" __scbeqz " $1, 1b \n" \ + "\t" __SC_BEQZ "$1, 1b \n" \ " .set pop \n" \ "2: \n" \ : "=&r" (__ret), "=" GCC_OFF_SMALL_ASM() (*m) \ @@ -268,7 +258,7 @@ static inline unsigned long __cmpxchg64(volatile void *ptr, /* Attempt to store new at ptr */ " scd %L1, %2 \n" /* If we failed, loop! */ - "\t" __scbeqz " %L1, 1b \n" + "\t" __SC_BEQZ "%L1, 1b \n" " .set pop \n" "2: \n" : "=&r"(ret), @@ -311,6 +301,4 @@ static inline unsigned long __cmpxchg64(volatile void *ptr, # endif /* !CONFIG_SMP */ #endif /* !CONFIG_64BIT */ -#undef __scbeqz - #endif /* __ASM_CMPXCHG_H */ diff --git a/arch/mips/include/asm/llsc.h b/arch/mips/include/asm/llsc.h index c6d17d171147..9b19f38562ac 100644 --- a/arch/mips/include/asm/llsc.h +++ b/arch/mips/include/asm/llsc.h @@ -25,4 +25,15 @@ #define __EXT "dext " #endif +/* + * Using a branch-likely instruction to check the result of an sc instruction + * works around a bug present in R10000 CPUs prior to revision 3.0 that could + * cause ll-sc sequences to execute non-atomically. + */ +#if R10000_LLSC_WAR +# define __SC_BEQZ "beqzl " +#else +# define __SC_BEQZ "beqz " +#endif + #endif /* __ASM_LLSC_H */ From patchwork Mon Sep 30 23:08:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167807 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9783D14DB for ; Mon, 30 Sep 2019 23:10:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6B62021855 for ; Mon, 30 Sep 2019 23:10:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="T1CYJW//" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731890AbfI3XKn (ORCPT ); Mon, 30 Sep 2019 19:10:43 -0400 Received: from mail-eopbgr710105.outbound.protection.outlook.com ([40.107.71.105]:33459 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726789AbfI3XIS (ORCPT ); Mon, 30 Sep 2019 19:08:18 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gEVR7se2Z3BRLw1jCX+mvLcGES+HhrGHl0NIncYhQooKk8kLVKnO013hlnaRXs93Uc00Oy1oX9/j0ngy9dcpkeXOdJq10oCxc5aJga+LcwxtVFidXJiHtdEYvVUqXuLBQDLgSsDIpoTa1fbQEiDb4LawOVWM8Vl3toVSFqsir/PAQNKa8ha/ceh2EPI51dSPlJM1cajQD6ENmOnmKbKvQhB2cv0Z358JaTbeuuUDHkTFKs4V7sRJ6z3OkmPYD8rBA5iKDrlW2QibQCZzfotDGtbZtqrvRq5FcEYSh+R6FselZM0cPp867HXqLSejiuqKmklEL4IpN9i/Dp97+8R0gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Bb5CGjJcO9JsblExHKeC5e8gn1nT23BsfTVgf0jISbo=; b=GYsqGZzjuY/sCCnvDNDdibjUdtPNA3u3YUCVody05F6Ac5A0ZbDbL4MgcpLI2SZp/u5Om2QtR+h6+Gkhb5axv+GhBCrmgItqTbbl72Hpw+uOuhQxOvDEKk45hYD1IN9L1CsxX5pJa+h35zpXq3Rln4v/xnvN8Pg7H7cIfdU5o6BaiL7wTx0wA/q6zkP7tY0h3yWjuqy8/EGdfvEPUsj7hURpV48eQ5xSJmHnexaJTURUS1fDMQVIrprZxMe9Q89N593WUxzYzZmleg13zOa1rK56gMigT/53wRmR980gvF5FbsaIcM/41BTm/I26LFtShmzy4vmyNVNwwA2rdm7qNg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Bb5CGjJcO9JsblExHKeC5e8gn1nT23BsfTVgf0jISbo=; b=T1CYJW//FrS3VdN0ArJeQEePtG2l3Hpz2wOoASaUwgYgcZdYB8JSEWeA3mpW2HAs35c97gSt1/kvxylrb8mNH9SfLKTIxcLi90uceEH8BFYGny/UQSCUdX8hLpsQLfIJl03vGbzoKlatWXUQtrohTBJWNk+nK6Exh3EGDEUHx04= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1709.namprd22.prod.outlook.com (10.164.206.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.20; Mon, 30 Sep 2019 23:08:16 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:16 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 02/37] MIPS: Use compact branch for LL/SC loops on MIPSr6+ Thread-Topic: [PATCH 02/37] MIPS: Use compact branch for LL/SC loops on MIPSr6+ Thread-Index: AQHVd+PwLwYhLPuiu0W9q5wn/sVxdw== Date: Mon, 30 Sep 2019 23:08:16 +0000 Message-ID: <20190930230806.2940505-3-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b1826e22-3325-4626-d08f-08d745fb1342 x-ms-traffictypediagnostic: MWHPR2201MB1709: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4125; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(39840400004)(376002)(346002)(396003)(136003)(199004)(189003)(2351001)(66476007)(66556008)(66946007)(64756008)(66446008)(107886003)(99286004)(6486002)(52116002)(5640700003)(6436002)(25786009)(478600001)(14454004)(76176011)(26005)(6512007)(5660300002)(71200400001)(71190400001)(4744005)(1076003)(4326008)(186003)(42882007)(6506007)(11346002)(256004)(486006)(44832011)(476003)(2616005)(446003)(54906003)(316002)(7736002)(305945005)(6116002)(2906002)(3846002)(81156014)(81166006)(102836004)(50226002)(6916009)(386003)(36756003)(8676002)(8936002)(66066001)(2501003);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1709;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: yUkh5+LC15kDahG+S2Q8hBXdcqn6LMMPwJUBuifrNN6TJG1DF/VSMOoirPXUo0TLye4OYn6NKLgDQ5BsVhjiPfoaVS0H/UaeUs+lLLZmltWKrA/1yfHJzIMadOlX8yPlhahzjDrTWinDNXsdky3+/IgKcMGrHxHr4x4YJCvHGJSQqoQHIh+82nTHNrutm74ZagmsDp6q/T9MfbKtBIV5OGxhtPoShkGV8bOQbgyOVV6rGy2HWR4JOtUnQooVUsfUlp0vHPQIIQH9JuxFavpjCZnk7Kd7cQVcXVILkDtLg6mZFznz8oJJQoU2L8ZFpgLj6zQPDK/AkRSF9ozfQ46jL4bRI758zS0m/9CwBUbmp8w/6PyOrlrhzJTGTRUZahk4LHdQG5+xJ/pQxN+VjUVwt6vwz0mW6oKarw+YuwrG+gA= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: b1826e22-3325-4626-d08f-08d745fb1342 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:16.1186 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: g058PfiKJbFDaRdEciRO14mvlGYy10cgJ3Qd7roMqvZAvBu0OaAPYFLIM6TPXxoYQ9JtfQA3qiOhpX+TysnMvA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1709 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org When targeting MIPSr6 or higher make use of a compact branch in LL/SC loops, preventing the insertion of a delay slot nop that only serves to waste space. Signed-off-by: Paul Burton --- arch/mips/include/asm/llsc.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/mips/include/asm/llsc.h b/arch/mips/include/asm/llsc.h index 9b19f38562ac..d240a4a2d1c4 100644 --- a/arch/mips/include/asm/llsc.h +++ b/arch/mips/include/asm/llsc.h @@ -9,6 +9,8 @@ #ifndef __ASM_LLSC_H #define __ASM_LLSC_H +#include + #if _MIPS_SZLONG == 32 #define SZLONG_LOG 5 #define SZLONG_MASK 31UL @@ -32,6 +34,8 @@ */ #if R10000_LLSC_WAR # define __SC_BEQZ "beqzl " +#elif MIPS_ISA_REV >= 6 +# define __SC_BEQZ "beqzc " #else # define __SC_BEQZ "beqz " #endif From patchwork Mon Sep 30 23:08:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167805 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C53B814DB for ; Mon, 30 Sep 2019 23:10:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 83B1F2081B for ; Mon, 30 Sep 2019 23:10:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="ZJH3o4jw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732183AbfI3XIU (ORCPT ); Mon, 30 Sep 2019 19:08:20 -0400 Received: from mail-eopbgr710105.outbound.protection.outlook.com ([40.107.71.105]:33459 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732018AbfI3XIU (ORCPT ); Mon, 30 Sep 2019 19:08:20 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YYJrIALkGXw7aXeyFp5tzLS1ORZIVaoEvBrv4RrYd4Na6tL3JegBsdRfJ88XDa140lKxFfq08WLSqX6Ci66djhaJF649i0TQx623GS/GeB3kv+LUMCLytlXJY97JDHneSpYwNrezbCD4OtdAAV7V1ewgXhGnTPbjvrLzdBwAYQO5aekulevUzmwCkfcOEWun3rka1WsRE3mPf/bLR4zY40nSEfS+QBpVgnSoa01oq0wTBHHSinRLxQUd5GHjx0NGikp1OPu+BKXyj+8IgRqZWGzZYqY5yA/AV51iig6EnCniBcD7n6KhQyQblkHdxQq3eUy9H3YnZYVIHh5S9puwZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=r0kVHJtqCqSGgZQ4CSJWQuUFBz9PcKWA85ys86gGzRY=; b=nQno/SnQyd27E2lye4eEgJ/5BWMgcKw1Zls+vIhO3EFLAcOXlOFmfbedJieJd0H6sRiDXZCmQOHkEtCjXyLqF07gk8mViGeCoTFiGJdmCS8Gw2/3vH/wk5D9Ir1xOUKcz2x6nM07SoTDnBAIGBQ8NKT2au3RV7l2Bk0jukIydes4dYjj3Fudd+9c3cpjEJ724AsbTxGtpNwUN+FBGKJ6iLJzm1z34UVfT8HBPQPJbiQ5lcRu88shy4ivLuk0AOsa0GTVPzf97KpcgJzhaQMy3KGzmproH5PUWoSgPGDG3dkxJAXRfsTJljbSIBjATQlEKJBxzPShFD5pH03lAIPH/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=r0kVHJtqCqSGgZQ4CSJWQuUFBz9PcKWA85ys86gGzRY=; b=ZJH3o4jwOWkAAOW+hVexmWtjrHtOEyiBf0f6soRsa1Yjocw6iVtBRUCm0EAfE8xtWJApV2sPlbzBLY2YiFZI8FB5mK8gLB7VN8q8nhbLPma8FmXZqw2d4nnl9E0a/7p2ZH8f1e38oKElp/m8dHVVVyCPkt8GDSdFM9JmSefoRwE= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1709.namprd22.prod.outlook.com (10.164.206.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.20; Mon, 30 Sep 2019 23:08:17 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:17 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 03/37] MIPS: barrier: Add __SYNC() infrastructure Thread-Topic: [PATCH 03/37] MIPS: barrier: Add __SYNC() infrastructure Thread-Index: AQHVd+PxU9Y+nx0fKkq2bchy7J628A== Date: Mon, 30 Sep 2019 23:08:16 +0000 Message-ID: <20190930230806.2940505-4-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: f726ee15-50b9-4e98-9b2a-08d745fb13cd x-ms-traffictypediagnostic: MWHPR2201MB1709: x-ms-exchange-purlcount: 1 x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(39840400004)(376002)(346002)(396003)(136003)(199004)(189003)(2351001)(66476007)(66556008)(66946007)(64756008)(66446008)(107886003)(99286004)(6306002)(6486002)(52116002)(5640700003)(6436002)(25786009)(478600001)(14454004)(76176011)(26005)(6512007)(966005)(5660300002)(71200400001)(71190400001)(30864003)(1076003)(4326008)(186003)(42882007)(6506007)(11346002)(256004)(486006)(44832011)(476003)(2616005)(14444005)(446003)(54906003)(316002)(7736002)(305945005)(6116002)(2906002)(3846002)(81156014)(81166006)(102836004)(50226002)(6916009)(386003)(36756003)(8676002)(8936002)(66066001)(2501003)(579004);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1709;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: z4y+6MFtWRfPFHASTJZ+ztBpYWLwdZI3OL4wBhN5u25qr1REegaWsZjK4BczQZVhCJSsPMXNCE4SmLbeYvS+VlmbkmQw1glPuc5mctyUOBfBruEyYXFMwUY1+jVlG4y+p1k7rr4ulpnpH1oAB007o0HncuQXcomwDOwnDsRXkpLJ4Pte33DOrv1UUR8FeotDmD0L5KHmPL7ipCTmHvZUmNF7CmktDC8TJhdIAqYxSjXBNYknCep1INfLwyvQwQN2Yl00ib5iT/rfeXGmGUbIBiKsbdDMt495rARjOBNFjU2oTPJXZJ0rDh6DfzPferYIzhdEWxqwKNxm6Ntf87OVdK20tl47gzNgRRW3OfFvqFDbabC8EHZiICa3Fx2xA0EJbQOf2l63zIMBS3DLGJIfukIX3sYwecfOemRYygCxW87fOadKeWG05R8xe7IAk3g8vSWqPcYZpP4rxFDGVMrZ0Q== MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: f726ee15-50b9-4e98-9b2a-08d745fb13cd X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:17.0562 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: bXduDvYA03AlTdJrEXRTt06ojISPzfcD+1Ud4vbMJ40KyqzKlb4VbsWQ2kt7leTKzcuA9DJN1eCFkPjEB7V7qg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1709 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Introduce an asm/sync.h header which provides infrastructure that can be used to generate sync instructions of various types, and for various reasons. For example if we need a sync instruction that provides a full completion barrier but only on systems which have weak memory ordering, we can generate the appropriate assembly code using: __SYNC(full, weak_ordering) When the kernel is configured to run on systems with weak memory ordering (ie. CONFIG_WEAK_ORDERING is selected) we'll emit a sync instruction. When the kernel is configured to run on systems with strong memory ordering (ie. CONFIG_WEAK_ORDERING is not selected) we'll emit nothing. The caller doesn't need to know which happened - it simply says what it needs & when, with no concern for checking the kernel configuration. There are some scenarios in which we may want to emit code only when we *didn't* emit a sync instruction. For example, some Loongson3 CPUs suffer from a bug that requires us to emit a sync instruction prior to each ll instruction (enabled by CONFIG_CPU_LOONGSON3_WORKAROUNDS). In cases where this bug workaround is enabled, it's wasteful to then have more generic code emit another sync instruction to provide barriers we need in general. A __SYNC_ELSE() macro allows for this, providing an extra argument that contains code to be assembled only in cases where the sync instruction was not emitted. For example if we have a scenario in which we generally want to emit a release barrier but for affected Loongson3 configurations upgrade that to a full completion barrier, we can do that like so: __SYNC_ELSE(full, loongson3_war, __SYNC(rl, always)) The assembly generated by these macros can be used either as inline assembly or in assembly source files. Differing types of sync as provided by MIPSr6 are defined, but currently they all generate a full completion barrier except in kernels configured for Cavium Octeon systems. There the wmb sync-type is used, and rmb syncs are omitted, as has been the case since commit 6b07d38aaa52 ("MIPS: Octeon: Use optimized memory barrier primitives."). Using __SYNC() with the wmb or rmb types will abstract away the Octeon specific behavior and allow us to later clean up asm/barrier.h code that currently includes a plethora of #ifdef's. Signed-off-by: Paul Burton --- arch/mips/include/asm/barrier.h | 113 +---------------- arch/mips/include/asm/sync.h | 207 ++++++++++++++++++++++++++++++++ arch/mips/kernel/pm-cps.c | 20 +-- 3 files changed, 219 insertions(+), 121 deletions(-) create mode 100644 arch/mips/include/asm/sync.h diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h index 9228f7386220..5ad39bfd3b6d 100644 --- a/arch/mips/include/asm/barrier.h +++ b/arch/mips/include/asm/barrier.h @@ -9,116 +9,7 @@ #define __ASM_BARRIER_H #include - -/* - * Sync types defined by the MIPS architecture (document MD00087 table 6.5) - * These values are used with the sync instruction to perform memory barriers. - * Types of ordering guarantees available through the SYNC instruction: - * - Completion Barriers - * - Ordering Barriers - * As compared to the completion barrier, the ordering barrier is a - * lighter-weight operation as it does not require the specified instructions - * before the SYNC to be already completed. Instead it only requires that those - * specified instructions which are subsequent to the SYNC in the instruction - * stream are never re-ordered for processing ahead of the specified - * instructions which are before the SYNC in the instruction stream. - * This potentially reduces how many cycles the barrier instruction must stall - * before it completes. - * Implementations that do not use any of the non-zero values of stype to define - * different barriers, such as ordering barriers, must make those stype values - * act the same as stype zero. - */ - -/* - * Completion barriers: - * - Every synchronizable specified memory instruction (loads or stores or both) - * that occurs in the instruction stream before the SYNC instruction must be - * already globally performed before any synchronizable specified memory - * instructions that occur after the SYNC are allowed to be performed, with - * respect to any other processor or coherent I/O module. - * - * - The barrier does not guarantee the order in which instruction fetches are - * performed. - * - * - A stype value of zero will always be defined such that it performs the most - * complete set of synchronization operations that are defined.This means - * stype zero always does a completion barrier that affects both loads and - * stores preceding the SYNC instruction and both loads and stores that are - * subsequent to the SYNC instruction. Non-zero values of stype may be defined - * by the architecture or specific implementations to perform synchronization - * behaviors that are less complete than that of stype zero. If an - * implementation does not use one of these non-zero values to define a - * different synchronization behavior, then that non-zero value of stype must - * act the same as stype zero completion barrier. This allows software written - * for an implementation with a lighter-weight barrier to work on another - * implementation which only implements the stype zero completion barrier. - * - * - A completion barrier is required, potentially in conjunction with SSNOP (in - * Release 1 of the Architecture) or EHB (in Release 2 of the Architecture), - * to guarantee that memory reference results are visible across operating - * mode changes. For example, a completion barrier is required on some - * implementations on entry to and exit from Debug Mode to guarantee that - * memory effects are handled correctly. - */ - -/* - * stype 0 - A completion barrier that affects preceding loads and stores and - * subsequent loads and stores. - * Older instructions which must reach the load/store ordering point before the - * SYNC instruction completes: Loads, Stores - * Younger instructions which must reach the load/store ordering point only - * after the SYNC instruction completes: Loads, Stores - * Older instructions which must be globally performed when the SYNC instruction - * completes: Loads, Stores - */ -#define STYPE_SYNC 0x0 - -/* - * Ordering barriers: - * - Every synchronizable specified memory instruction (loads or stores or both) - * that occurs in the instruction stream before the SYNC instruction must - * reach a stage in the load/store datapath after which no instruction - * re-ordering is possible before any synchronizable specified memory - * instruction which occurs after the SYNC instruction in the instruction - * stream reaches the same stage in the load/store datapath. - * - * - If any memory instruction before the SYNC instruction in program order, - * generates a memory request to the external memory and any memory - * instruction after the SYNC instruction in program order also generates a - * memory request to external memory, the memory request belonging to the - * older instruction must be globally performed before the time the memory - * request belonging to the younger instruction is globally performed. - * - * - The barrier does not guarantee the order in which instruction fetches are - * performed. - */ - -/* - * stype 0x10 - An ordering barrier that affects preceding loads and stores and - * subsequent loads and stores. - * Older instructions which must reach the load/store ordering point before the - * SYNC instruction completes: Loads, Stores - * Younger instructions which must reach the load/store ordering point only - * after the SYNC instruction completes: Loads, Stores - * Older instructions which must be globally performed when the SYNC instruction - * completes: N/A - */ -#define STYPE_SYNC_MB 0x10 - -/* - * stype 0x14 - A completion barrier specific to global invalidations - * - * When a sync instruction of this type completes any preceding GINVI or GINVT - * operation has been globalized & completed on all coherent CPUs. Anything - * that the GINV* instruction should invalidate will have been invalidated on - * all coherent CPUs when this instruction completes. It is implementation - * specific whether the GINV* instructions themselves will ensure completion, - * or this sync type will. - * - * In systems implementing global invalidates (ie. with Config5.GI == 2 or 3) - * this sync type also requires that previous SYNCI operations have completed. - */ -#define STYPE_GINV 0x14 +#include #ifdef CONFIG_CPU_HAS_SYNC #define __sync() \ @@ -286,7 +177,7 @@ static inline void sync_ginv(void) { - asm volatile("sync\t%0" :: "i"(STYPE_GINV)); + asm volatile("sync\t%0" :: "i"(__SYNC_ginv)); } #include diff --git a/arch/mips/include/asm/sync.h b/arch/mips/include/asm/sync.h new file mode 100644 index 000000000000..7c6a1095f556 --- /dev/null +++ b/arch/mips/include/asm/sync.h @@ -0,0 +1,207 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __MIPS_ASM_SYNC_H__ +#define __MIPS_ASM_SYNC_H__ + +/* + * sync types are defined by the MIPS64 Instruction Set documentation in Volume + * II-A of the MIPS Architecture Reference Manual, which can be found here: + * + * https://www.mips.com/?do-download=the-mips64-instruction-set-v6-06 + * + * Two types of barrier are provided: + * + * 1) Completion barriers, which ensure that a memory operation has actually + * completed & often involve stalling the CPU pipeline to do so. + * + * 2) Ordering barriers, which only ensure that affected memory operations + * won't be reordered in the CPU pipeline in a manner that violates the + * restrictions imposed by the barrier. + * + * Ordering barriers can be more efficient than completion barriers, since: + * + * a) Ordering barriers only require memory access instructions which preceed + * them in program order (older instructions) to reach a point in the + * load/store datapath beyond which reordering is not possible before + * allowing memory access instructions which follow them (younger + * instructions) to be performed. That is, older instructions don't + * actually need to complete - they just need to get far enough that all + * other coherent CPUs will observe their completion before they observe + * the effects of younger instructions. + * + * b) Multiple variants of ordering barrier are provided which allow the + * effects to be restricted to different combinations of older or younger + * loads or stores. By way of example, if we only care that stores older + * than a barrier are observed prior to stores that are younger than a + * barrier & don't care about the ordering of loads then the 'wmb' + * ordering barrier can be used. Limiting the barrier's effects to stores + * allows loads to continue unaffected & potentially allows the CPU to + * make progress faster than if younger loads had to wait for older stores + * to complete. + */ + +/* + * No sync instruction at all; used to allow code to nullify the effect of the + * __SYNC() macro without needing lots of #ifdefery. + */ +#define __SYNC_none -1 + +/* + * A full completion barrier; all memory accesses appearing prior to this sync + * instruction in program order must complete before any memory accesses + * appearing after this sync instruction in program order. + */ +#define __SYNC_full 0x00 + +/* + * For now we use a full completion barrier to implement all sync types, until + * we're satisfied that lightweight ordering barriers defined by MIPSr6 are + * sufficient to uphold our desired memory model. + */ +#define __SYNC_aq __SYNC_full +#define __SYNC_rl __SYNC_full +#define __SYNC_mb __SYNC_full + +/* + * ...except on Cavium Octeon CPUs, which have been using the 'wmb' ordering + * barrier since 2010 & omit 'rmb' barriers because the CPUs don't perform + * speculative reads. + */ +#ifdef CONFIG_CPU_CAVIUM_OCTEON +# define __SYNC_rmb __SYNC_none +# define __SYNC_wmb 0x04 +#else +# define __SYNC_rmb __SYNC_full +# define __SYNC_wmb __SYNC_full +#endif + +/* + * A GINV sync is a little different; it doesn't relate directly to loads or + * stores, but instead causes synchronization of an icache or TLB global + * invalidation operation triggered by the ginvi or ginvt instructions + * respectively. In cases where we need to know that a ginvi or ginvt operation + * has been performed by all coherent CPUs, we must issue a sync instruction of + * this type. Once this instruction graduates all coherent CPUs will have + * observed the invalidation. + */ +#define __SYNC_ginv 0x14 + +/* Trivial; indicate that we always need this sync instruction. */ +#define __SYNC_always (1 << 0) + +/* + * Indicate that we need this sync instruction only on systems with weakly + * ordered memory access. In general this is most MIPS systems, but there are + * exceptions which provide strongly ordered memory. + */ +#ifdef CONFIG_WEAK_ORDERING +# define __SYNC_weak_ordering (1 << 1) +#else +# define __SYNC_weak_ordering 0 +#endif + +/* + * Indicate that we need this sync instruction only on systems where LL/SC + * don't implicitly provide a memory barrier. In general this is most MIPS + * systems. + */ +#ifdef CONFIG_WEAK_REORDERING_BEYOND_LLSC +# define __SYNC_weak_llsc (1 << 2) +#else +# define __SYNC_weak_llsc 0 +#endif + +/* + * Some Loongson 3 CPUs have a bug wherein execution of a memory access (load, + * store or prefetch) in between an LL & SC can cause the SC instruction to + * erroneously succeed, breaking atomicity. Whilst it's unusual to write code + * containing such sequences, this bug bites harder than we might otherwise + * expect due to reordering & speculation: + * + * 1) A memory access appearing prior to the LL in program order may actually + * be executed after the LL - this is the reordering case. + * + * In order to avoid this we need to place a memory barrier (ie. a SYNC + * instruction) prior to every LL instruction, in between it and any earlier + * memory access instructions. + * + * This reordering case is fixed by 3A R2 CPUs, ie. 3A2000 models and later. + * + * 2) If a conditional branch exists between an LL & SC with a target outside + * of the LL-SC loop, for example an exit upon value mismatch in cmpxchg() + * or similar, then misprediction of the branch may allow speculative + * execution of memory accesses from outside of the LL-SC loop. + * + * In order to avoid this we need a memory barrier (ie. a SYNC instruction) + * at each affected branch target. + * + * This case affects all current Loongson 3 CPUs. + * + * The above described cases cause an error in the cache coherence protocol; + * such that the Invalidate of a competing LL-SC goes 'missing' and SC + * erroneously observes its core still has Exclusive state and lets the SC + * proceed. + * + * Therefore the error only occurs on SMP systems. + */ +#ifdef CONFIG_CPU_LOONGSON3_WORKAROUNDS +# define __SYNC_loongson3_war (1 << 31) +#else +# define __SYNC_loongson3_war 0 +#endif + +/* + * Some Cavium Octeon CPUs suffer from a bug that causes a single wmb ordering + * barrier to be ineffective, requiring the use of 2 in sequence to provide an + * effective barrier as noted by commit 6b07d38aaa52 ("MIPS: Octeon: Use + * optimized memory barrier primitives."). Here we specify that the affected + * sync instructions should be emitted twice. + */ +#ifdef CONFIG_CPU_CAVIUM_OCTEON +# define __SYNC_rpt(type) (1 + (type == __SYNC_wmb)) +#else +# define __SYNC_rpt(type) 1 +#endif + +/* + * The main event. Here we actually emit a sync instruction of a given type, if + * reason is non-zero. + * + * In future we have the option of emitting entries in a fixups-style table + * here that would allow us to opportunistically remove some sync instructions + * when we detect at runtime that we're running on a CPU that doesn't need + * them. + */ +#ifdef CONFIG_CPU_HAS_SYNC +# define ____SYNC(_type, _reason, _else) \ + .if (( _type ) != -1) && ( _reason ); \ + .set push; \ + .set MIPS_ISA_LEVEL_RAW; \ + .rept __SYNC_rpt(_type); \ + sync _type; \ + .endr; \ + .set pop; \ + .else; \ + _else; \ + .endif +#else +# define ____SYNC(_type, _reason, _else) +#endif + +/* + * Preprocessor magic to expand macros used as arguments before we insert them + * into assembly code. + */ +#ifdef __ASSEMBLY__ +# define ___SYNC(type, reason, else) \ + ____SYNC(type, reason, else) +#else +# define ___SYNC(type, reason, else) \ + __stringify(____SYNC(type, reason, else)) +#endif + +#define __SYNC(type, reason) \ + ___SYNC(__SYNC_##type, __SYNC_##reason, ) +#define __SYNC_ELSE(type, reason, else) \ + ___SYNC(__SYNC_##type, __SYNC_##reason, else) + +#endif /* __MIPS_ASM_SYNC_H__ */ diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c index a26f40db15d0..9bf60d7d44d3 100644 --- a/arch/mips/kernel/pm-cps.c +++ b/arch/mips/kernel/pm-cps.c @@ -307,7 +307,7 @@ static int cps_gen_flush_fsb(u32 **pp, struct uasm_label **pl, } /* Barrier ensuring previous cache invalidates are complete */ - uasm_i_sync(pp, STYPE_SYNC); + uasm_i_sync(pp, __SYNC_full); uasm_i_ehb(pp); /* Check whether the pipeline stalled due to the FSB being full */ @@ -397,7 +397,7 @@ static void *cps_gen_entry_code(unsigned cpu, enum cps_pm_state state) if (coupled_coherence) { /* Increment ready_count */ - uasm_i_sync(&p, STYPE_SYNC_MB); + uasm_i_sync(&p, __SYNC_mb); uasm_build_label(&l, p, lbl_incready); uasm_i_ll(&p, t1, 0, r_nc_count); uasm_i_addiu(&p, t2, t1, 1); @@ -406,7 +406,7 @@ static void *cps_gen_entry_code(unsigned cpu, enum cps_pm_state state) uasm_i_addiu(&p, t1, t1, 1); /* Barrier ensuring all CPUs see the updated r_nc_count value */ - uasm_i_sync(&p, STYPE_SYNC_MB); + uasm_i_sync(&p, __SYNC_mb); /* * If this is the last VPE to become ready for non-coherence @@ -473,7 +473,7 @@ static void *cps_gen_entry_code(unsigned cpu, enum cps_pm_state state) Index_Writeback_Inv_D, lbl_flushdcache); /* Barrier ensuring previous cache invalidates are complete */ - uasm_i_sync(&p, STYPE_SYNC); + uasm_i_sync(&p, __SYNC_full); uasm_i_ehb(&p); if (mips_cm_revision() < CM_REV_CM3) { @@ -487,7 +487,7 @@ static void *cps_gen_entry_code(unsigned cpu, enum cps_pm_state state) uasm_i_lw(&p, t0, 0, r_pcohctl); /* Barrier to ensure write to coherence control is complete */ - uasm_i_sync(&p, STYPE_SYNC); + uasm_i_sync(&p, __SYNC_full); uasm_i_ehb(&p); } @@ -534,7 +534,7 @@ static void *cps_gen_entry_code(unsigned cpu, enum cps_pm_state state) } /* Barrier to ensure write to CPC command is complete */ - uasm_i_sync(&p, STYPE_SYNC); + uasm_i_sync(&p, __SYNC_full); uasm_i_ehb(&p); } @@ -572,13 +572,13 @@ static void *cps_gen_entry_code(unsigned cpu, enum cps_pm_state state) uasm_i_lw(&p, t0, 0, r_pcohctl); /* Barrier to ensure write to coherence control is complete */ - uasm_i_sync(&p, STYPE_SYNC); + uasm_i_sync(&p, __SYNC_full); uasm_i_ehb(&p); if (coupled_coherence && (state == CPS_PM_NC_WAIT)) { /* Decrement ready_count */ uasm_build_label(&l, p, lbl_decready); - uasm_i_sync(&p, STYPE_SYNC_MB); + uasm_i_sync(&p, __SYNC_mb); uasm_i_ll(&p, t1, 0, r_nc_count); uasm_i_addiu(&p, t2, t1, -1); uasm_i_sc(&p, t2, 0, r_nc_count); @@ -586,7 +586,7 @@ static void *cps_gen_entry_code(unsigned cpu, enum cps_pm_state state) uasm_i_andi(&p, v0, t1, (1 << fls(smp_num_siblings)) - 1); /* Barrier ensuring all CPUs see the updated r_nc_count value */ - uasm_i_sync(&p, STYPE_SYNC_MB); + uasm_i_sync(&p, __SYNC_mb); } if (coupled_coherence && (state == CPS_PM_CLOCK_GATED)) { @@ -608,7 +608,7 @@ static void *cps_gen_entry_code(unsigned cpu, enum cps_pm_state state) uasm_build_label(&l, p, lbl_secondary_cont); /* Barrier ensuring all CPUs see the updated r_nc_count value */ - uasm_i_sync(&p, STYPE_SYNC_MB); + uasm_i_sync(&p, __SYNC_mb); } /* The core is coherent, time to return to C code */ From patchwork Mon Sep 30 23:08:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167737 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F36E614DB for ; Mon, 30 Sep 2019 23:08:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C747D2081B for ; Mon, 30 Sep 2019 23:08:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="R16BjZmw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732253AbfI3XIV (ORCPT ); Mon, 30 Sep 2019 19:08:21 -0400 Received: from mail-eopbgr710105.outbound.protection.outlook.com ([40.107.71.105]:33459 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726425AbfI3XIU (ORCPT ); Mon, 30 Sep 2019 19:08:20 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mU+jX0xITwclfsoMHiSvMaB4mrMvMm/PTdHgUSv5DtWt9oUdfU2PXR13dIViv2yHL+QUivpiPNyR9FoVimif8qiuU7MC/7ETAiTJaIdpkEAQtEZbKTR9PSq5qRZ0ng+bqo1SPHv8+M3CfSkbzvikzS1r34ro+LwoL5FzfsCDvIW3Wc7CmeUTZFFuwgoHEFuSVqGIJfbxvPrmnBCIFfBaqVsdsP166lESC6i5lOxbs1rzk28sET9ZaruYuI470xjqIw8LTCvxjefwzvCFUeXQzuxzoS/Hyy6G8V8RXum2zvmvENTXfNrYUAjYOrFgdK/r3SO19mLLn4HRvXNPzGP3aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/H7VFEgK5L2CSygsMdg95Dj2PplW8Nur2FDPObYfrHo=; b=eDhcJrRKx9xzXFeV/IBz6bBr4bm2T4twPrJYqzGGzq+RORq+/HENeNUqZnGLkW/l1k9OO/nBPHoEDsBOt3qr9o2ntuZWlpvOX13Vm8WQmVBloc7vG/Wb10+YqkYUKiEHw+WpfCU5qedApw1ZSSksLL7ctE9GJ04t0tfyFRkBph6HeyWYVLL7CODiPk3CMiE3Ag+ex8RU20yDainSyFr+TSTW8MWuCWO+DETiksWInvCQzvZERPDCxCG3J7sNjhWu+d8i5gYK6GL1SMmqP+9Mo/phfbI7uF0+n1bkxjAzLeX3TNOZD8ICQiPzxBdOPAlkrLFng2esZCgPacWA+1VuVQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/H7VFEgK5L2CSygsMdg95Dj2PplW8Nur2FDPObYfrHo=; b=R16BjZmwbgMC/Uh/F3bU+4gHn5PI/OutYC3fd0XTKn9Y3yT+k25ObE4vKqDxlpRzS9iHCafCCB1ju8uX4N3ADsWU2nAniCXWSzOqR5XW2RTD95lAfrTfw6BXot6rbegw/vxWJCACT7YFI2+b06vCIXau8VB5DKjHqEx2bFsgntg= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1709.namprd22.prod.outlook.com (10.164.206.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.20; Mon, 30 Sep 2019 23:08:18 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:18 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 04/37] MIPS: barrier: Clean up rmb() & wmb() definitions Thread-Topic: [PATCH 04/37] MIPS: barrier: Clean up rmb() & wmb() definitions Thread-Index: AQHVd+Py/lmEsltRXUiYsxgmO+g4aA== Date: Mon, 30 Sep 2019 23:08:17 +0000 Message-ID: <20190930230806.2940505-5-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 9d223693-1744-4959-7ac6-08d745fb1469 x-ms-traffictypediagnostic: MWHPR2201MB1709: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4941; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(39840400004)(376002)(346002)(396003)(136003)(199004)(189003)(2351001)(66476007)(66556008)(66946007)(64756008)(66446008)(107886003)(99286004)(6486002)(52116002)(5640700003)(6436002)(25786009)(478600001)(14454004)(76176011)(26005)(6512007)(5660300002)(71200400001)(71190400001)(1076003)(4326008)(186003)(42882007)(6506007)(11346002)(256004)(486006)(44832011)(476003)(2616005)(446003)(54906003)(316002)(7736002)(305945005)(6116002)(2906002)(3846002)(81156014)(81166006)(102836004)(50226002)(6916009)(386003)(36756003)(8676002)(8936002)(66066001)(2501003);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1709;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: j0OFVz7zG0ZIRqUHdOzZwnGQEMtoyStNLf670w+gigN3lDWs4zFQcrX0mLaRogtqFxfmQzsvzs8wEpe6ZSMSoq+Gyd8pVoYXLGFemvgyp51Bw3bWQLtWu5mJWvCqhHi+Iyi7W4p3qagDb7f1PHCeiJGOw/CcS7CTzUjgp514EjwMaw7xJL022wL0YxZGwLol64BIz21QnPsfI7fglFePUOIbloBUzjMXHc3NeSW4/y/pOJk/owpSGZoM0UoH6lOXzGf51EQMfKITrLl1o3JhKr4v23Jq2JTTw38eJIC7Vu48WsTc1phyDh7DbXwRjg93Ewg2UEVIuZ5Je3BFWwfxdWH2FYF0GUv2r68h9aGqbaEYWG85Hu/hH6BM0ceKOsmfK9bsm6oi1mDP3zjQBN5khcgTBFWu/KzaZ0F3uKwcaX8= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9d223693-1744-4959-7ac6-08d745fb1469 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:17.9208 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: zUKSsOeWCvoxqwzKRucMT9uDJa7i+ytFB/mglfqLyqdNQfi9z1uuLJbv2GZjW56RNNfLdwVkjexFb4ShMM+9Hw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1709 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Simplify our definitions of rmb() & wmb() using the new __SYNC() infrastructure. The fast_rmb() & fast_wmb() macros are removed, since they only provided a level of indirection that made the code less readable & weren't directly used anywhere in the kernel tree. The Octeon #ifdef'ery is removed, since the "syncw" instruction previously used is merely an alias for "sync 4" which __SYNC() will emit for the wmb sync type when the kernel is configured for an Octeon CPU. Similarly __SYNC() will emit nothing for the rmb sync type in Octeon configurations. Signed-off-by: Paul Burton --- arch/mips/include/asm/barrier.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h index 5ad39bfd3b6d..f36cab87cfde 100644 --- a/arch/mips/include/asm/barrier.h +++ b/arch/mips/include/asm/barrier.h @@ -26,6 +26,18 @@ #define __sync() do { } while(0) #endif +static inline void rmb(void) +{ + asm volatile(__SYNC(rmb, always) ::: "memory"); +} +#define rmb rmb + +static inline void wmb(void) +{ + asm volatile(__SYNC(wmb, always) ::: "memory"); +} +#define wmb wmb + #define __fast_iob() \ __asm__ __volatile__( \ ".set push\n\t" \ @@ -37,16 +49,9 @@ : "m" (*(int *)CKSEG1) \ : "memory") #ifdef CONFIG_CPU_CAVIUM_OCTEON -# define OCTEON_SYNCW_STR ".set push\n.set arch=octeon\nsyncw\nsyncw\n.set pop\n" -# define __syncw() __asm__ __volatile__(OCTEON_SYNCW_STR : : : "memory") - -# define fast_wmb() __syncw() -# define fast_rmb() barrier() # define fast_mb() __sync() # define fast_iob() do { } while (0) #else /* ! CONFIG_CPU_CAVIUM_OCTEON */ -# define fast_wmb() __sync() -# define fast_rmb() __sync() # define fast_mb() __sync() # ifdef CONFIG_SGI_IP28 # define fast_iob() \ @@ -83,19 +88,14 @@ #endif /* !CONFIG_CPU_HAS_WB */ -#define wmb() fast_wmb() -#define rmb() fast_rmb() - #if defined(CONFIG_WEAK_ORDERING) # ifdef CONFIG_CPU_CAVIUM_OCTEON # define __smp_mb() __sync() -# define __smp_rmb() barrier() -# define __smp_wmb() __syncw() # else # define __smp_mb() __asm__ __volatile__("sync" : : :"memory") -# define __smp_rmb() __asm__ __volatile__("sync" : : :"memory") -# define __smp_wmb() __asm__ __volatile__("sync" : : :"memory") # endif +# define __smp_rmb() rmb() +# define __smp_wmb() wmb() #else #define __smp_mb() barrier() #define __smp_rmb() barrier() From patchwork Mon Sep 30 23:08:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167739 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 175AD14DB for ; Mon, 30 Sep 2019 23:08:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DCD4E2168B for ; Mon, 30 Sep 2019 23:08:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="u2ykeHkt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732018AbfI3XIW (ORCPT ); Mon, 30 Sep 2019 19:08:22 -0400 Received: from mail-eopbgr710105.outbound.protection.outlook.com ([40.107.71.105]:33459 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732246AbfI3XIV (ORCPT ); Mon, 30 Sep 2019 19:08:21 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WJQHidDChIUG5gBiaChfpjcOlaYKcVdJD30ebkbA5CZvr2nKUvsCN3bvADYIQLd0HkSBJCdMjm5nuFgmrmT3nbpk2x59tljRODazfT8JmTypfO/OT12MOdAXki7RLhPrKfHVmD8B7JIZUiL1JL2jT8bHtjb7L2AAJ+6yo98Ga7CeZGYEK4+kROgKF0s2DdqJEv5q9r4F4L9CjbjGTd9z6xaapNKWwPLPR9PbKE2HXKFy8N1CJHo3uIx2JaGdDBb6kV1DzR8CNzv+61I6ne8XXl5VzjvtdmYA/hQiDIbvvMQKj53yDbtfOYluttPZPVsMXnEBqE8JuZP5hpl8hVWvDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XlgXrBWp7RH//htYCKYl6gXUEMhb1+7hgVOI3Od5iVs=; b=oXSs2FHtsa1Zu/5TNp3+CBFpItPfBtpRq41xmvFM3iYWiF5T2cucvxgNAhYvRCeD7oF+6+TBIeUZNQMpEFsUpkbgKzPCK2GYBMj3+OQcGdGFQDEksESq0ZOoirlOCI9QdUndK66Vea21goTVcyKeI+kVvySb4d+S1f4YeVHh9jp8opCvc3Lr4z/MfXOIQqjk03JGTtmJtQvFPGXiQ4f6Ju9DXbd99Hx5lo9D/iqMAnYs/W9AWWdZN7EwuOpEICqFNKb8ssMx//O6msBAy1WIV8r0gdN9poE6RfTgz+53T6NJi1EbcgLV+KWBa7qJ5GY4h7hCZ01R+G+9/tU86vMQkg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XlgXrBWp7RH//htYCKYl6gXUEMhb1+7hgVOI3Od5iVs=; b=u2ykeHkt4pQrkFOouKwyWB4gkiZVQui4U4WqziPfGqYYa3Hda/SxrPJtZkVYBHkAX/LKYusfjTb7vzRY1ImCTwlkMhhbdwkjwVksIKaVFEWQLDPPmSm8hzD0lzKBr9tTnw2GseQMt8oadpuwfnvkZLvlHDzddjxsVIB3yP0j2pk= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1709.namprd22.prod.outlook.com (10.164.206.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.20; Mon, 30 Sep 2019 23:08:18 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:18 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 05/37] MIPS: barrier: Clean up __smp_mb() definition Thread-Topic: [PATCH 05/37] MIPS: barrier: Clean up __smp_mb() definition Thread-Index: AQHVd+PyjeAR6CxZcka5NocqscHcuA== Date: Mon, 30 Sep 2019 23:08:18 +0000 Message-ID: <20190930230806.2940505-6-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 2b6e6f17-c0dc-41a9-420d-08d745fb14db x-ms-traffictypediagnostic: MWHPR2201MB1709: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(39840400004)(376002)(346002)(396003)(136003)(199004)(189003)(2351001)(66476007)(66556008)(66946007)(64756008)(66446008)(107886003)(99286004)(6486002)(52116002)(5640700003)(6436002)(25786009)(478600001)(14454004)(76176011)(26005)(6512007)(5660300002)(71200400001)(71190400001)(1076003)(4326008)(186003)(42882007)(6506007)(11346002)(256004)(486006)(44832011)(476003)(2616005)(14444005)(446003)(54906003)(316002)(7736002)(305945005)(6116002)(2906002)(3846002)(81156014)(81166006)(102836004)(50226002)(6916009)(386003)(36756003)(8676002)(8936002)(66066001)(2501003);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1709;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: SAj3usvMsSOu87ekDeX6Sdq0ZbGhmhZvJ6LNtH6XOZ58vbkRVJq6FVp7KBl6DOUEuy69fnzJQno7SCaAhIFk+nNIZmhdw0rMol1DvbqryI+pKa/dWOhqS5bUTGgzKX2dUTCx8RFI/8XZ/rsBexaeAsEyVWA/TohNKAH79SSo5dzpSZ1V6/5cVi9AHD/VWHUMl2YpZT2opLviPDuuOAKcmiBYTsDChtlxUGu+Vw32mRaXGf1bjg2fgoAK3iGbrIeKjpelFI51F9raSwpbGQiaji6QiD6KAfxsf4lTU4WJnKQq4xc3w0HkbjeC/Z9KWjW68vm1qkjwp13Rorq6Wn8z8MYMJDtIQXPraFBfcffufgRYh9N/FoS8efaUxiiRcWM1lpHlL3gtci8t07W757i5sWbzMllz65pI59X21ytTp+w= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b6e6f17-c0dc-41a9-420d-08d745fb14db X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:18.6925 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: L7FwRa+qfrSFtMVAx7TKH24Sx0D1FrkWZs8Es6HO+GieoEUd82EN63kCiqnvuhsaZBZuIb4+R958ERlfw+pYmw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1709 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org We #ifdef on Cavium Octeon CPUs, but emit the same sync instruction in both cases. Remove the #ifdef & simply expand to the __sync() macro. Whilst here indent the strong ordering case definitions to match the indentation of the weak ordering ones, helping readability. Signed-off-by: Paul Burton --- arch/mips/include/asm/barrier.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h index f36cab87cfde..8a5abc1c85a6 100644 --- a/arch/mips/include/asm/barrier.h +++ b/arch/mips/include/asm/barrier.h @@ -89,17 +89,13 @@ static inline void wmb(void) #endif /* !CONFIG_CPU_HAS_WB */ #if defined(CONFIG_WEAK_ORDERING) -# ifdef CONFIG_CPU_CAVIUM_OCTEON -# define __smp_mb() __sync() -# else -# define __smp_mb() __asm__ __volatile__("sync" : : :"memory") -# endif +# define __smp_mb() __sync() # define __smp_rmb() rmb() # define __smp_wmb() wmb() #else -#define __smp_mb() barrier() -#define __smp_rmb() barrier() -#define __smp_wmb() barrier() +# define __smp_mb() barrier() +# define __smp_rmb() barrier() +# define __smp_wmb() barrier() #endif /* From patchwork Mon Sep 30 23:08:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167803 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 707CD912 for ; Mon, 30 Sep 2019 23:10:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 441FB21855 for ; Mon, 30 Sep 2019 23:10:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="OX1gPlU+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732390AbfI3XIW (ORCPT ); Mon, 30 Sep 2019 19:08:22 -0400 Received: from mail-eopbgr710105.outbound.protection.outlook.com ([40.107.71.105]:33459 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732301AbfI3XIW (ORCPT ); Mon, 30 Sep 2019 19:08:22 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J9yoKIqH+QohUvMOgVTcmIogDgYZMeArd7GUChxv2d8xbqZJZLzfaa3KCxkJruDcD+1Yg9rmCWo+lgA+A2SpuIFgwOt+oi4JzxWCnUpve8fTkTZlKsMENTZgo7zo7mRGkv/2NI5eOp/NBiIXifsi9tg4VCdXrnJimM/HbjFS82QBLFni7j8BMCwRwEFi4InWIH/cFF2DQImOIjO/cXBiPMtegLA9okaxmMSJ/b7YCvd4qvsPA/RfXS0/y83t8Z3ca5Y1+wmLWyF9slP5gwNi9IWpo5ae5DewEywY3g8j19lli7JmxrlJFL9W+qdZaDHD3mGxwF+KGgnViEaRj/qRkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BrqnYEjdQEijKACbW1P8uI4u8aL+ZvFCd0DStIFNSws=; b=BU7VyWy3VglB+R5znueEOt9WWQkUUOS+DdSAjdI0SFb7vK4lt9XR4e+imf0fimwxvFv1wbWq7v4QD23GgcK6WeRzx8abWhLZVP9wf/q6p+YUv03+1Zl4hncWDwHVEp3MYO1vEhxTgYMAChPvm6vcI4odPavgAsokvL54YUOceuJornYdNKe0vy0iGB9eiRauz1VezuhpaLSjfNAs0JOZ9KsfnPd98WarVxe3bFW0GKDjqDBfuKFs2c7dUj0FlKGbK5qEyyuwej9tUg/vAAeRGCU2G25XC51clrReiG/ccY5lAams6SzK9y9ihlI/uhIyc3C2oiSiUfYeGh1HcfONnw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BrqnYEjdQEijKACbW1P8uI4u8aL+ZvFCd0DStIFNSws=; b=OX1gPlU+VoPFTSPITy0s1PSctNddHJ19pAGYnMsgGrmWa/Ab3QcXgruOW/40plFOMM7H9MYAYLE2EMQRxC7DqHBeuVkQTfD6dhF0t2U4YFO90JhaRxkq5NdKINhSmvD/nRbBeUNzeo+zWapPit51WoAdT91ZKKnxMG7L6I6Jly4= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1709.namprd22.prod.outlook.com (10.164.206.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.20; Mon, 30 Sep 2019 23:08:20 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:20 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 06/37] MIPS: barrier: Remove fast_mb() Octeon #ifdef'ery Thread-Topic: [PATCH 06/37] MIPS: barrier: Remove fast_mb() Octeon #ifdef'ery Thread-Index: AQHVd+PzeVq9kAt290WIqEOScOBiuA== Date: Mon, 30 Sep 2019 23:08:19 +0000 Message-ID: <20190930230806.2940505-7-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 462dc3b8-25f4-48af-bdd4-08d745fb1577 x-ms-traffictypediagnostic: MWHPR2201MB1709: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4125; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(39840400004)(376002)(346002)(396003)(136003)(199004)(189003)(2351001)(66476007)(66556008)(66946007)(64756008)(66446008)(107886003)(99286004)(6486002)(52116002)(5640700003)(6436002)(25786009)(478600001)(14454004)(76176011)(26005)(6512007)(5660300002)(71200400001)(71190400001)(4744005)(1076003)(4326008)(186003)(42882007)(6506007)(11346002)(256004)(486006)(44832011)(476003)(2616005)(446003)(54906003)(316002)(7736002)(305945005)(6116002)(2906002)(3846002)(81156014)(81166006)(102836004)(50226002)(6916009)(386003)(36756003)(8676002)(8936002)(66066001)(2501003);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1709;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: TSeAAwVMTDamfjnekE9MTVrove26oLUakIo5xAuoKaBWInpICqpP3a8Ys+9f9glKYQiYWEd/7du97Rof814MR1Z/VFh6gpD2VTRqp8rFQOmB/CmV3vQt2CeQp+qWw9PRLFpggsMIuf3Uyx9bncynMCjSwGPrUPIpliEPXMc5YrluY4RkDeSnfkC1KNbbwxmvdl1CIPshtTirZxQJBIB1DFvJgvDAF/TCZAaE3L5GNWhysLMQN+EpQJU3BcOKw1EEfVvxVfeAn7tQssK3jUJFpxzvACLmloMGSRtBAqB7j9MxtONiwzsxjEZ25uJpHwWTrUO36/pQnBhVBGcnFTA3IR173g2YM0Igl4o0Rh+Tv8eNlWAbTKeM17DFZcUiHGoWrw0Se2sghaZfARZkAA2RVzNrWRF4sP2i2VEmdlUfZuQ= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 462dc3b8-25f4-48af-bdd4-08d745fb1577 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:19.7620 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 8PV6JSwNSgI4qL2LsuPVaFLYMKTCXuK40B6WD3joP1tW5s3Fj06rvk95ZjrXOz5K1e+FOYeEbl6nB96+dobpCw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1709 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org The definition of fast_mb() is the same in both the Octeon & non-Octeon cases, so remove the duplication & define it only once. Signed-off-by: Paul Burton --- arch/mips/include/asm/barrier.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h index 8a5abc1c85a6..657ec01120a4 100644 --- a/arch/mips/include/asm/barrier.h +++ b/arch/mips/include/asm/barrier.h @@ -38,6 +38,8 @@ static inline void wmb(void) } #define wmb wmb +#define fast_mb() __sync() + #define __fast_iob() \ __asm__ __volatile__( \ ".set push\n\t" \ @@ -49,10 +51,8 @@ static inline void wmb(void) : "m" (*(int *)CKSEG1) \ : "memory") #ifdef CONFIG_CPU_CAVIUM_OCTEON -# define fast_mb() __sync() # define fast_iob() do { } while (0) #else /* ! CONFIG_CPU_CAVIUM_OCTEON */ -# define fast_mb() __sync() # ifdef CONFIG_SGI_IP28 # define fast_iob() \ __asm__ __volatile__( \ From patchwork Mon Sep 30 23:08:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167801 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C812A912 for ; Mon, 30 Sep 2019 23:10:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9D5D1218DE for ; Mon, 30 Sep 2019 23:10:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="i5E8/C4f" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732301AbfI3XKc (ORCPT ); Mon, 30 Sep 2019 19:10:32 -0400 Received: from mail-eopbgr710108.outbound.protection.outlook.com ([40.107.71.108]:6114 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732384AbfI3XIX (ORCPT ); Mon, 30 Sep 2019 19:08:23 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mj42OKhRSbHW0bmsvQ/gWlVW7Z5eRq3YnJeNZqhNRmYMCRTjtxe4VlWssYOcKnTSlZ4EBYy/w6+MG2v761DOxUawzD9BT5gYP6WGYJqaViX+QWEyJbgKP+4WO+Vg6JqaJ9+R7lO2G8a/EWWiErrGlnWYn4hWvBoLO+WGQKw1XtKmiEoBZnO/Fzzo5aUJNNJcb9AZPG3BFf4VHtfy0JRSCFYgtIRaDGAvmxpgVvSf+p8jDBWaXxoOghW4ZFQFtLfH6CxuNC0HWI/IRdqz9xXkrR9lNDt59PBubXKRq5BUNYWTUHSAmIq3jM6V+w0F+rOUSMsg5IyJJb2Ptzhmha05+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Sj0N9tgKe3Xgp9DvCFSq/7QXgi9lOry5y2YcyKp6Vu8=; b=OX8/q1FyRiNaqx1pYvmtjCOYimOyqs0RmfeydzP2oRJ1eIHpXdkH5gdd4gQHdp3mtN72IK8gzFOdXenTRUU/AXZR5tTL8OsPecSVzyfATKCNEzqZxvvQPxk/QGPdUu98DQ7AN0JHvmYHUbikRVPSCGOf002M3S0TdW+a4558oJR9p7xo/hCqZIYIsZNsSsy7aRZDhTqLg2ydf1LbN3hGZ12onQxpIyu5IoJZr/3s6bTEJil//XJOiq3yXP0VSMafXTlNgZnPqXHF5sG/463y0EPg+/REqaS58+wjs0WpYySqKFBO46jtsAB0wcaJzAFo82YU8mDMEnbXUqUwB0ZNzg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Sj0N9tgKe3Xgp9DvCFSq/7QXgi9lOry5y2YcyKp6Vu8=; b=i5E8/C4fhCafDK+uNTEpu+OKzzx7ySKf+sO5oqQl+IQ7G88dLTpR43zsAS4IbWYztx4v93IlLNEuggK+6vNaqpAhWMyNNVkqEpqgQzF1CNpx3UkqSWBg4vA3vrtluUrm7+aZAuDKCfgho13JwfqhTrwLkP22496kilKhCtNA8LY= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1709.namprd22.prod.outlook.com (10.164.206.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.20; Mon, 30 Sep 2019 23:08:21 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:21 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 07/37] MIPS: barrier: Clean up __sync() definition Thread-Topic: [PATCH 07/37] MIPS: barrier: Clean up __sync() definition Thread-Index: AQHVd+PzVVIdvKywjkGdJ87RMl/84A== Date: Mon, 30 Sep 2019 23:08:20 +0000 Message-ID: <20190930230806.2940505-8-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0b152cfa-63df-4a53-06be-08d745fb15f6 x-ms-traffictypediagnostic: MWHPR2201MB1709: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5236; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(39840400004)(376002)(346002)(396003)(136003)(199004)(189003)(43544003)(2351001)(66476007)(66556008)(66946007)(64756008)(66446008)(107886003)(99286004)(6486002)(52116002)(5640700003)(6436002)(25786009)(478600001)(14454004)(76176011)(26005)(6512007)(5660300002)(71200400001)(71190400001)(1076003)(4326008)(186003)(42882007)(6506007)(11346002)(256004)(486006)(44832011)(476003)(2616005)(446003)(54906003)(316002)(7736002)(305945005)(6116002)(2906002)(3846002)(81156014)(81166006)(102836004)(50226002)(6916009)(386003)(36756003)(8676002)(8936002)(66066001)(2501003);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1709;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: lxCgdqeQV5jGYRdCVhit9T76cKJRFcPZRqwx//NUEHw0IcJmVQQITQK27YUzgtDND0/fsdy8hejizTl9yHe2fe/S2OgfgfPlzX58aWGSyw6xEzJmsjlI5E3Csocuk8uAIprMuRJhRN2VK0hhHNY4CLWqaVutXf5xp7V/Y+ul2TyZ7fIJDMtga5MLiNaKUxLtAMscXZrjIV1hi3ad95tO10tc1whCRK29mrRc+GyxtQSd44pDW4nVOiOKEsdz4nrgjd8tHOWp8MWKMR7chl6Gfp1FQAsqCLkGJ78cEkpmmJ9yX40rf6oYfKukXkZKGOvT3ccqcQlNENpJZS+0t7WDnu7WMFEhmwBQAKlzWB5F5j6/M3JjX5KIs+vPA8BQWX+5aQZdLs6cO5mzd1k5wFpT8WOZHqwNZrcbSnSbfwYrDdI= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0b152cfa-63df-4a53-06be-08d745fb15f6 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:20.6866 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: P9HDup82Bq4LPZrO5645n8/mDzOCmNhvsaL54kU+G5XyMDZxUNWKM2UKy+Fe8tbPQAS+RimC3lSqrzJAgPuB8Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1709 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Implement __sync() using the new __SYNC() infrastructure, which will take care of not emitting an instruction for old R3k CPUs that don't support it. The only behavioral difference is that __sync() will now provide a compiler barrier on these old CPUs, but that seems like reasonable behavior anyway. Signed-off-by: Paul Burton --- arch/mips/include/asm/barrier.h | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h index 657ec01120a4..a117c6d95038 100644 --- a/arch/mips/include/asm/barrier.h +++ b/arch/mips/include/asm/barrier.h @@ -11,20 +11,10 @@ #include #include -#ifdef CONFIG_CPU_HAS_SYNC -#define __sync() \ - __asm__ __volatile__( \ - ".set push\n\t" \ - ".set noreorder\n\t" \ - ".set mips2\n\t" \ - "sync\n\t" \ - ".set pop" \ - : /* no output */ \ - : /* no input */ \ - : "memory") -#else -#define __sync() do { } while(0) -#endif +static inline void __sync(void) +{ + asm volatile(__SYNC(full, always) ::: "memory"); +} static inline void rmb(void) { From patchwork Mon Sep 30 23:08:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167797 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 64F7314DB for ; Mon, 30 Sep 2019 23:10:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 43D582086A for ; Mon, 30 Sep 2019 23:10:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="IoDBS8JW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732449AbfI3XI0 (ORCPT ); Mon, 30 Sep 2019 19:08:26 -0400 Received: from mail-eopbgr820107.outbound.protection.outlook.com ([40.107.82.107]:31072 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732442AbfI3XIZ (ORCPT ); Mon, 30 Sep 2019 19:08:25 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZmkH5iBoqeTWwS4LppIFhQMNw/n4+j7qG8Tb37lD5bX6NnI+4l0NYjhtAcJTf/S0zYt7L4VVD4ahqg41urQbYEYrK9oQj4npcXD9bVDb8T0GZExnq6i9aPr/bp4QXvyVx/8by2oepx3fQvpV3pqZ2sKEJ2vsbwARYSf014IDknMfeMg4hPDaAwZ7xJHcZGAztzOsW4egu39p1kjfSQTGwHe1cEWF9RCPIvhTI5mrMbnu7lQN1CbfEztZPgKM/1pz0vOv83JKp4Rz8IwcMuABNwL6n498DfrbGyJ2dxNZNgfDqe0nva/0DXsdAX0HxBzwlbcqz/wKlQXw2kFwksZNOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fYcC9mKEo46j5Wg4Fl2eCtfvmNKEM9uZlKj0eAO/wJo=; b=JBLEC1pnQWPFDZovatV6jaEsbDCPbPBpKffPkDvkneORDkoaKDp7MFgPEG6WAy9g98o7Qj19Fsa1oFVr6F6oKUHZRRKfYlDek0kG9VUvLqPeMP9+lOfVoX59pSA6Xor88Cgf2YZnnYI5c8v/VLd/V7SOtFXCGkB0SVLk65Mw2lwydr0OVbtThUDnwLPdQUTpnBDs4U2iTIPbr0O3cgdEy4hb2v1gXFaxYf51SFRBwt5ta7fNo/L8mv9j+LWjyGVQg+oIbFaPfq2QHhFsgq1THNUzAFWMGjll4do2wD7GgrTPs0cIVNXnCc+t3zEOKk/2rKzrd/3xUZqaJ2T2wLhWeA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fYcC9mKEo46j5Wg4Fl2eCtfvmNKEM9uZlKj0eAO/wJo=; b=IoDBS8JWM7Xtq9i4BbSEOqOzKzZ/psU0B1aes2I3SCVErVkoaESsKw2Dxk3jXwGzEELRFGKuZV74Yfgow1AS87J16vFTnFtdLiuuZqyDl7u7L6AVecWIpZTNvRtw3nS8Uobuh4cFPgiQuqnAsl6LsOtA167WLKapM73ezE4tJ7g= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:22 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:22 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 08/37] MIPS: barrier: Clean up sync_ginv() Thread-Topic: [PATCH 08/37] MIPS: barrier: Clean up sync_ginv() Thread-Index: AQHVd+P0/JqjG+YzWkiVbYN4mNb0LA== Date: Mon, 30 Sep 2019 23:08:21 +0000 Message-ID: <20190930230806.2940505-9-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ee453716-8953-4883-393d-08d745fb1687 x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2958; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(376002)(136003)(366004)(189003)(199004)(14454004)(508600001)(256004)(6512007)(81166006)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(4744005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 94azVCmm9mpsEcjOw0iRoL/2B/trP6Yk4L1ATO4u0rTmqO26VCY/mzX1ZcB4UjHdxoLfzuoEvmyixwXDKI7drDW9EVnVtR6l1Okd1ipIeloo/m1hU7gJGrHnkKOi02gIONayYiMhFNoCVDQYrN0KtCQoAYyOkMchtLhe0mpgCfB2tDp8puA7T1MBlUY7eNG3vgDGadpTsNmqC46bB019FrkccQwuJJbSqHXU93aNpY8O0AZ5XqgFJnJNRNsabVg1HlABv0OMF646fiMgw38iX1hT7zIzkOtOtuN0vVZaBsIuY5WRloYCNwGYWaUkfh6OjY8v/8grineF8IYa1tAHdXCrz3PltuxCqY1Bey8qgP2UuGdKJ3fxX95z4K5cVpv8b9z80MuF+h/uT6J0BdPJBkopdn7C3TzcbXuKmVebnj0= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: ee453716-8953-4883-393d-08d745fb1687 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:21.5592 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: rRc5YqPDAf05E0AjEh+njN/lK4D32aVh1PccH4qkWqL1Svljg2bU5ZhqsDVdBgsuDjIVUlxfPuyyQFc0/PcIDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Use the new __SYNC() infrastructure to implement sync_ginv(), for consistency with much of the rest of the asm/barrier.h. Signed-off-by: Paul Burton --- arch/mips/include/asm/barrier.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h index a117c6d95038..c7e05e832da9 100644 --- a/arch/mips/include/asm/barrier.h +++ b/arch/mips/include/asm/barrier.h @@ -163,7 +163,7 @@ static inline void wmb(void) static inline void sync_ginv(void) { - asm volatile("sync\t%0" :: "i"(__SYNC_ginv)); + asm volatile(__SYNC(ginv, always)); } #include From patchwork Mon Sep 30 23:08:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167795 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1DAFB912 for ; Mon, 30 Sep 2019 23:10:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E59202086A for ; Mon, 30 Sep 2019 23:10:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="ipuNaaF+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732469AbfI3XI2 (ORCPT ); Mon, 30 Sep 2019 19:08:28 -0400 Received: from mail-eopbgr820107.outbound.protection.outlook.com ([40.107.82.107]:31072 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732465AbfI3XI1 (ORCPT ); Mon, 30 Sep 2019 19:08:27 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FApIFlUVwxdoIcNUwAVbdMx4hnH0PmvQMFKxSywQzVLcSzgFKWBmDG8KMiW4ZuVLyL541jr7gUI8EN+Bc6uNfrceoAkQGBCNBiAlkjWVr3PIpj0Ge4qeZ0bR/R8giXDtOJyR+ahSWNN94boUjvIKeeuDwwqTI2MoKSD6Yc1k8H81Pri0h6V9JoHV1D7YDiZEbMCIjwAbMx7t4Obyy/u4pV5zrgPQrUVhvM7VxHLeIraJwh+ORDQOH+bD0xrKFCWg+JWSWh2X4MFog/8Gr5WbIKymEKw1hEuSfiFIZ16V0tK8Fz4Z8dDc/O1ps9XBfGyIzjcigILH4cAImUlpRCGMrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Cmuuw90m6VKvCRrNPGLStO7w4ycAue1K5cdAUukTOvQ=; b=Xv4P7EBpAMfEfLiaju9hqSyluJnuV2mUgmNNAvrxOkHgp7kC7aloZY7qB4nYrLNvakk8prbZuhOqH8ncSS5oPRlY6N0crbtPYheiI9UeKETBRnD7dQv02b8eh0sfcMfgjKqaBv+i1UAkCMgglMuWKeR4adTIwY/mRCPiEC024wNpQSwY+0NsK6SWDiFHGgnuIVb/uho+MlUOiagW9X4A77OiYn3iVyRRzhXwEvAW2FLBPpWeWqTVpzcgjenxdLsoPYOH4q8vP3BcnyLtSxlmC/qtoaGC8NGJH2pAirTgEWda8nFCqXdIPqHWiDBxPFkoRzpn1uUZr6YqMZJ90yLu/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Cmuuw90m6VKvCRrNPGLStO7w4ycAue1K5cdAUukTOvQ=; b=ipuNaaF+OebEZ34HojGkZOv3azfvpx3D9OwptbtH3IIEz/Asn/7kXCjHs+utMZeDssAHKf1IGuoSyWq/iJPKJplU+fW2s/AAIaM62Gwl26C7B5x1lbSkOiJaQX94CrvEVgi9VZrSUJ7Zx2eOJNFAhuFOvWMQvSh/nwYDLoUdLZs= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:22 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:22 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 09/37] MIPS: atomic: Fix whitespace in ATOMIC_OP macros Thread-Topic: [PATCH 09/37] MIPS: atomic: Fix whitespace in ATOMIC_OP macros Thread-Index: AQHVd+P0L0Ik2goEok+JOiw7Ifofdg== Date: Mon, 30 Sep 2019 23:08:22 +0000 Message-ID: <20190930230806.2940505-10-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e8a50c42-6779-41e6-f6ed-08d745fb170e x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1169; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(376002)(136003)(366004)(189003)(199004)(14454004)(508600001)(256004)(6512007)(81166006)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: jm+vXwUtf/vmumtKI2u1MTu1/qJqYFItQMwdvLVd8IysM/RX9JvwwB4mzBDDMbJjwnmPcdGCJ0E9xug+ix/osIKuOV4MlhWhWdBsGg6cYPKBPbSOXY4eSPpXaY6R/Z5NJHF33p4+vmsLL4hp/9QXbhLUKwt2kr4if4txQg4zXlXOeLCr6hqcRBHHhtTZuDwu/pns+G0AhPAfDX/2YI6ftx6ukQfJDo3YbVV60JZEa0G+Odh48aZycyF1wM8gvWVN2CM2Bm88f5jdVDM7E2+OHBYEpvmt44X4aG7SDwVEjKc3nMiAcjBq/DNKtOEgb1NP7o5LEcF4vozTmZ0HcK+JM+pi9WG6NQY8XYJuvSRnXqnB8CctzQAfBWB6Sv0DHT5OYKf3wyVFbHKF/owN+UTLljJZG3VW81rYGmFSrUFoR18= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: e8a50c42-6779-41e6-f6ed-08d745fb170e X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:22.3658 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: KrpDh1oE2cOqZKtCzbd82XCHBAiX3mV4P4CWyUVmNb0MaZ8E3PQZrQTZQLIO8DAK7wScsCqs6Hp0OgRNx3TU0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org We define macros in asm/atomic.h which end each line with space characters before a backslash to continue on the next line. Remove the space characters leaving tabs as the whitespace used for conformity with coding convention. Signed-off-by: Paul Burton --- arch/mips/include/asm/atomic.h | 184 ++++++++++++++++----------------- 1 file changed, 92 insertions(+), 92 deletions(-) diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h index 7578c807ef98..2d2a8a74c51b 100644 --- a/arch/mips/include/asm/atomic.h +++ b/arch/mips/include/asm/atomic.h @@ -42,102 +42,102 @@ */ #define atomic_set(v, i) WRITE_ONCE((v)->counter, (i)) -#define ATOMIC_OP(op, c_op, asm_op) \ -static __inline__ void atomic_##op(int i, atomic_t * v) \ -{ \ - if (kernel_uses_llsc) { \ - int temp; \ - \ - loongson_llsc_mb(); \ - __asm__ __volatile__( \ - " .set push \n" \ - " .set "MIPS_ISA_LEVEL" \n" \ - "1: ll %0, %1 # atomic_" #op " \n" \ - " " #asm_op " %0, %2 \n" \ - " sc %0, %1 \n" \ - "\t" __SC_BEQZ "%0, 1b \n" \ - " .set pop \n" \ - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (v->counter) \ - : "Ir" (i) : __LLSC_CLOBBER); \ - } else { \ - unsigned long flags; \ - \ - raw_local_irq_save(flags); \ - v->counter c_op i; \ - raw_local_irq_restore(flags); \ - } \ +#define ATOMIC_OP(op, c_op, asm_op) \ +static __inline__ void atomic_##op(int i, atomic_t * v) \ +{ \ + if (kernel_uses_llsc) { \ + int temp; \ + \ + loongson_llsc_mb(); \ + __asm__ __volatile__( \ + " .set push \n" \ + " .set "MIPS_ISA_LEVEL" \n" \ + "1: ll %0, %1 # atomic_" #op " \n" \ + " " #asm_op " %0, %2 \n" \ + " sc %0, %1 \n" \ + "\t" __SC_BEQZ "%0, 1b \n" \ + " .set pop \n" \ + : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (v->counter) \ + : "Ir" (i) : __LLSC_CLOBBER); \ + } else { \ + unsigned long flags; \ + \ + raw_local_irq_save(flags); \ + v->counter c_op i; \ + raw_local_irq_restore(flags); \ + } \ } -#define ATOMIC_OP_RETURN(op, c_op, asm_op) \ -static __inline__ int atomic_##op##_return_relaxed(int i, atomic_t * v) \ -{ \ - int result; \ - \ - if (kernel_uses_llsc) { \ - int temp; \ - \ - loongson_llsc_mb(); \ - __asm__ __volatile__( \ - " .set push \n" \ - " .set "MIPS_ISA_LEVEL" \n" \ - "1: ll %1, %2 # atomic_" #op "_return \n" \ - " " #asm_op " %0, %1, %3 \n" \ - " sc %0, %2 \n" \ - "\t" __SC_BEQZ "%0, 1b \n" \ - " " #asm_op " %0, %1, %3 \n" \ - " .set pop \n" \ - : "=&r" (result), "=&r" (temp), \ - "+" GCC_OFF_SMALL_ASM() (v->counter) \ - : "Ir" (i) : __LLSC_CLOBBER); \ - } else { \ - unsigned long flags; \ - \ - raw_local_irq_save(flags); \ - result = v->counter; \ - result c_op i; \ - v->counter = result; \ - raw_local_irq_restore(flags); \ - } \ - \ - return result; \ +#define ATOMIC_OP_RETURN(op, c_op, asm_op) \ +static __inline__ int atomic_##op##_return_relaxed(int i, atomic_t * v) \ +{ \ + int result; \ + \ + if (kernel_uses_llsc) { \ + int temp; \ + \ + loongson_llsc_mb(); \ + __asm__ __volatile__( \ + " .set push \n" \ + " .set "MIPS_ISA_LEVEL" \n" \ + "1: ll %1, %2 # atomic_" #op "_return \n" \ + " " #asm_op " %0, %1, %3 \n" \ + " sc %0, %2 \n" \ + "\t" __SC_BEQZ "%0, 1b \n" \ + " " #asm_op " %0, %1, %3 \n" \ + " .set pop \n" \ + : "=&r" (result), "=&r" (temp), \ + "+" GCC_OFF_SMALL_ASM() (v->counter) \ + : "Ir" (i) : __LLSC_CLOBBER); \ + } else { \ + unsigned long flags; \ + \ + raw_local_irq_save(flags); \ + result = v->counter; \ + result c_op i; \ + v->counter = result; \ + raw_local_irq_restore(flags); \ + } \ + \ + return result; \ } -#define ATOMIC_FETCH_OP(op, c_op, asm_op) \ -static __inline__ int atomic_fetch_##op##_relaxed(int i, atomic_t * v) \ -{ \ - int result; \ - \ - if (kernel_uses_llsc) { \ - int temp; \ - \ - loongson_llsc_mb(); \ - __asm__ __volatile__( \ - " .set push \n" \ - " .set "MIPS_ISA_LEVEL" \n" \ - "1: ll %1, %2 # atomic_fetch_" #op " \n" \ - " " #asm_op " %0, %1, %3 \n" \ - " sc %0, %2 \n" \ - "\t" __SC_BEQZ "%0, 1b \n" \ - " .set pop \n" \ - " move %0, %1 \n" \ - : "=&r" (result), "=&r" (temp), \ - "+" GCC_OFF_SMALL_ASM() (v->counter) \ - : "Ir" (i) : __LLSC_CLOBBER); \ - } else { \ - unsigned long flags; \ - \ - raw_local_irq_save(flags); \ - result = v->counter; \ - v->counter c_op i; \ - raw_local_irq_restore(flags); \ - } \ - \ - return result; \ +#define ATOMIC_FETCH_OP(op, c_op, asm_op) \ +static __inline__ int atomic_fetch_##op##_relaxed(int i, atomic_t * v) \ +{ \ + int result; \ + \ + if (kernel_uses_llsc) { \ + int temp; \ + \ + loongson_llsc_mb(); \ + __asm__ __volatile__( \ + " .set push \n" \ + " .set "MIPS_ISA_LEVEL" \n" \ + "1: ll %1, %2 # atomic_fetch_" #op " \n" \ + " " #asm_op " %0, %1, %3 \n" \ + " sc %0, %2 \n" \ + "\t" __SC_BEQZ "%0, 1b \n" \ + " .set pop \n" \ + " move %0, %1 \n" \ + : "=&r" (result), "=&r" (temp), \ + "+" GCC_OFF_SMALL_ASM() (v->counter) \ + : "Ir" (i) : __LLSC_CLOBBER); \ + } else { \ + unsigned long flags; \ + \ + raw_local_irq_save(flags); \ + result = v->counter; \ + v->counter c_op i; \ + raw_local_irq_restore(flags); \ + } \ + \ + return result; \ } -#define ATOMIC_OPS(op, c_op, asm_op) \ - ATOMIC_OP(op, c_op, asm_op) \ - ATOMIC_OP_RETURN(op, c_op, asm_op) \ +#define ATOMIC_OPS(op, c_op, asm_op) \ + ATOMIC_OP(op, c_op, asm_op) \ + ATOMIC_OP_RETURN(op, c_op, asm_op) \ ATOMIC_FETCH_OP(op, c_op, asm_op) ATOMIC_OPS(add, +=, addu) @@ -149,8 +149,8 @@ ATOMIC_OPS(sub, -=, subu) #define atomic_fetch_sub_relaxed atomic_fetch_sub_relaxed #undef ATOMIC_OPS -#define ATOMIC_OPS(op, c_op, asm_op) \ - ATOMIC_OP(op, c_op, asm_op) \ +#define ATOMIC_OPS(op, c_op, asm_op) \ + ATOMIC_OP(op, c_op, asm_op) \ ATOMIC_FETCH_OP(op, c_op, asm_op) ATOMIC_OPS(and, &=, and) From patchwork Mon Sep 30 23:08:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167793 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 08C0E912 for ; Mon, 30 Sep 2019 23:10:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D07B72086A for ; Mon, 30 Sep 2019 23:10:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="p9VlviHo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732465AbfI3XIb (ORCPT ); Mon, 30 Sep 2019 19:08:31 -0400 Received: from mail-eopbgr820107.outbound.protection.outlook.com ([40.107.82.107]:31072 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732442AbfI3XIa (ORCPT ); Mon, 30 Sep 2019 19:08:30 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Efb0CpuDdhiIPnTnUsVbEUJ6ub5Ml3l6aEKnOYzZN+kl3apzz9+NLnRzpvrw6b6Exqby23oKWEO9s1+J0OKlib3QlEDedvtjVKSG+9q0SZHg2eY0vtDJHoHgHcYkbud8W1k35DtGf+NuvmQB8KDnJf1/cOvolOpyiyZiLrCQOxucyRuvhA5s2qvVIXQGAX9zahOuqPEVOWJw6N5grVbXybqpkPa8ZT5mw8JbzNDRGbk3Xk66yVP/2IhF2wdMtI0Y1vzZmgfoyCWA42inr3rgDwvwmVKFeY0sPMRcFb9xFD9ldtAtthfH9FyfTANrTikKLgYpDZ7MBvobtBNnR2+bHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ah2k+zkbqTqhr690CKGvSZSI7ugQNvjVIW57u5CEK2w=; b=F5UHUwN/ynXKtZlUqeBcwez0S+BKqW9ST8uyuqo4cI6xuZ95p9/zQ9i6AFqtiUPIO/mzZvcYomHJRIAtCsWvAicZU05pEdmkhvl3SQYBrLJdj+rT2lyHlgaPyR+uC4E5HCF24X2NyAKjF82nDRE/EpfIAiVrbXl+xKJ1JBnaf1IPyXVOot0vdIVJs5R864/PY2MCLZ66+Qj449Tt8Vac+JJcs3K6UcMAf+k58YSEsSEJbJNlXc43rN9oQeCPYKZAKZFZS7U7FD3AHcmlvK8UH6RmnUyx2FDE8Gw3QApzpQqGLW+nA9chgifOvoHj6orx9Lk6CRQ1+3kGo6y684wS7w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ah2k+zkbqTqhr690CKGvSZSI7ugQNvjVIW57u5CEK2w=; b=p9VlviHoG4ZJsXxlb0Zu2+oFMfXBiPSQab7OebpOnkF21GOWzW+ZyULkFGxnOaR/lDxPr7BP3d00NIbiql77+neKEBZbZPK1VECx9mhbP2xqethAnYw6Iwvvsay2pnnmiGvcR/ay81KYjoTLfEiMbCTUTlbHat+j18VEvpKd+fM= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:23 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:23 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 10/37] MIPS: atomic: Handle !kernel_uses_llsc first Thread-Topic: [PATCH 10/37] MIPS: atomic: Handle !kernel_uses_llsc first Thread-Index: AQHVd+P1xkAisMuQ50+vtEJHejn45w== Date: Mon, 30 Sep 2019 23:08:23 +0000 Message-ID: <20190930230806.2940505-11-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: fbc6eac6-cff2-4222-5e6e-08d745fb1788 x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:849; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(376002)(136003)(366004)(189003)(199004)(14454004)(508600001)(256004)(6512007)(81166006)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: GYco+SGa6qTn9BdJRWPfATta8sV9klTiRTH1OZLRYxMmW5Mczr8s5mO3p6hKmaedEqPxnqI1AOnbYxH9/1km89vBBJkLcR3ox6YyIFa8iij4qYNWygKW1QPbeeoiV1ZPElKub2HmJDtwNniyzLRUJytjH+tW57NR2SDeXFSVaL/HyIVKKRmgHzTANuKw7p0vbr9FgPKf7gjNBq0ielf5ctz/i073G30tOQ6OcmDH1TT4phZluO+7ZFUdU/UkhPd4B9mrmjC8HIOoRMl+/bLe3wEYD7Lrsah2V6NTXcwPIa5skgmZJtpwZDkTfyI1OHY+bdg22+tqSYVEAEyDivybGjWBkrylsJMf6D7ikqOqFJQs6okGSXKo3WnA7ZwJuG6OlPShH+n8Xy6GhQ7F/q4r5qdmftl1YO4HwJrewBg62cg= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: fbc6eac6-cff2-4222-5e6e-08d745fb1788 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:23.1734 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Vv0cM2cvou/CpSYgophny4ErMr0pn7ZwjWW19//bMCzu8amAcGPwooDwffv9otM3S4VBDldQTOxXhMHRA5DEsQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Handle the !kernel_uses_llsc path first in our ATOMIC_OP(), ATOMIC_OP_RETURN() & ATOMIC_FETCH_OP() macros & return from within the block. This allows us to de-indent the kernel_uses_llsc path by one level which will be useful when making further changes. Signed-off-by: Paul Burton --- arch/mips/include/asm/atomic.h | 99 +++++++++++++++++----------------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h index 2d2a8a74c51b..ace2ea005588 100644 --- a/arch/mips/include/asm/atomic.h +++ b/arch/mips/include/asm/atomic.h @@ -45,51 +45,36 @@ #define ATOMIC_OP(op, c_op, asm_op) \ static __inline__ void atomic_##op(int i, atomic_t * v) \ { \ - if (kernel_uses_llsc) { \ - int temp; \ + int temp; \ \ - loongson_llsc_mb(); \ - __asm__ __volatile__( \ - " .set push \n" \ - " .set "MIPS_ISA_LEVEL" \n" \ - "1: ll %0, %1 # atomic_" #op " \n" \ - " " #asm_op " %0, %2 \n" \ - " sc %0, %1 \n" \ - "\t" __SC_BEQZ "%0, 1b \n" \ - " .set pop \n" \ - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (v->counter) \ - : "Ir" (i) : __LLSC_CLOBBER); \ - } else { \ + if (!kernel_uses_llsc) { \ unsigned long flags; \ \ raw_local_irq_save(flags); \ v->counter c_op i; \ raw_local_irq_restore(flags); \ + return; \ } \ + \ + loongson_llsc_mb(); \ + __asm__ __volatile__( \ + " .set push \n" \ + " .set " MIPS_ISA_LEVEL " \n" \ + "1: ll %0, %1 # atomic_" #op " \n" \ + " " #asm_op " %0, %2 \n" \ + " sc %0, %1 \n" \ + "\t" __SC_BEQZ "%0, 1b \n" \ + " .set pop \n" \ + : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (v->counter) \ + : "Ir" (i) : __LLSC_CLOBBER); \ } #define ATOMIC_OP_RETURN(op, c_op, asm_op) \ static __inline__ int atomic_##op##_return_relaxed(int i, atomic_t * v) \ { \ - int result; \ - \ - if (kernel_uses_llsc) { \ - int temp; \ + int temp, result; \ \ - loongson_llsc_mb(); \ - __asm__ __volatile__( \ - " .set push \n" \ - " .set "MIPS_ISA_LEVEL" \n" \ - "1: ll %1, %2 # atomic_" #op "_return \n" \ - " " #asm_op " %0, %1, %3 \n" \ - " sc %0, %2 \n" \ - "\t" __SC_BEQZ "%0, 1b \n" \ - " " #asm_op " %0, %1, %3 \n" \ - " .set pop \n" \ - : "=&r" (result), "=&r" (temp), \ - "+" GCC_OFF_SMALL_ASM() (v->counter) \ - : "Ir" (i) : __LLSC_CLOBBER); \ - } else { \ + if (!kernel_uses_llsc) { \ unsigned long flags; \ \ raw_local_irq_save(flags); \ @@ -97,41 +82,55 @@ static __inline__ int atomic_##op##_return_relaxed(int i, atomic_t * v) \ result c_op i; \ v->counter = result; \ raw_local_irq_restore(flags); \ + return result; \ } \ \ + loongson_llsc_mb(); \ + __asm__ __volatile__( \ + " .set push \n" \ + " .set " MIPS_ISA_LEVEL " \n" \ + "1: ll %1, %2 # atomic_" #op "_return \n" \ + " " #asm_op " %0, %1, %3 \n" \ + " sc %0, %2 \n" \ + "\t" __SC_BEQZ "%0, 1b \n" \ + " " #asm_op " %0, %1, %3 \n" \ + " .set pop \n" \ + : "=&r" (result), "=&r" (temp), \ + "+" GCC_OFF_SMALL_ASM() (v->counter) \ + : "Ir" (i) : __LLSC_CLOBBER); \ + \ return result; \ } #define ATOMIC_FETCH_OP(op, c_op, asm_op) \ static __inline__ int atomic_fetch_##op##_relaxed(int i, atomic_t * v) \ { \ - int result; \ + int temp, result; \ \ - if (kernel_uses_llsc) { \ - int temp; \ - \ - loongson_llsc_mb(); \ - __asm__ __volatile__( \ - " .set push \n" \ - " .set "MIPS_ISA_LEVEL" \n" \ - "1: ll %1, %2 # atomic_fetch_" #op " \n" \ - " " #asm_op " %0, %1, %3 \n" \ - " sc %0, %2 \n" \ - "\t" __SC_BEQZ "%0, 1b \n" \ - " .set pop \n" \ - " move %0, %1 \n" \ - : "=&r" (result), "=&r" (temp), \ - "+" GCC_OFF_SMALL_ASM() (v->counter) \ - : "Ir" (i) : __LLSC_CLOBBER); \ - } else { \ + if (!kernel_uses_llsc) { \ unsigned long flags; \ \ raw_local_irq_save(flags); \ result = v->counter; \ v->counter c_op i; \ raw_local_irq_restore(flags); \ + return result; \ } \ \ + loongson_llsc_mb(); \ + __asm__ __volatile__( \ + " .set push \n" \ + " .set "MIPS_ISA_LEVEL" \n" \ + "1: ll %1, %2 # atomic_fetch_" #op " \n" \ + " " #asm_op " %0, %1, %3 \n" \ + " sc %0, %2 \n" \ + "\t" __SC_BEQZ "%0, 1b \n" \ + " .set pop \n" \ + " move %0, %1 \n" \ + : "=&r" (result), "=&r" (temp), \ + "+" GCC_OFF_SMALL_ASM() (v->counter) \ + : "Ir" (i) : __LLSC_CLOBBER); \ + \ return result; \ } From patchwork Mon Sep 30 23:08:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167789 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E5F814DB for ; Mon, 30 Sep 2019 23:10:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3363F2086A for ; Mon, 30 Sep 2019 23:10:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="qaNMvq7x" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732528AbfI3XIf (ORCPT ); Mon, 30 Sep 2019 19:08:35 -0400 Received: from mail-eopbgr690120.outbound.protection.outlook.com ([40.107.69.120]:5486 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732492AbfI3XIe (ORCPT ); Mon, 30 Sep 2019 19:08:34 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DnQ9MKdUyNnUOwQsbSxUzsE41Xb9finS+jLuXmgn36SlQ/cYu+/gA8X89T1TCFSzTwHR2s50o/MvGHgTgB/OiwjpSyHx11srtVDYy+L0/q0cjNxIBUCu6WBUn0Hx40ftt4qN5GG8WSimIoByNpaL9YBhdnqUOeYLA+xbyUl+GRzvuMFG//dYI0VHc7jNkzsRHLOrgeDhbPF/z5o0ipu6RLNiPn3ONKYKJnv5qOPxjsSLp37aU84c9MMDacQkKKp+A5/cVo5s/ZPcxBjbZYKGCJu1JUVt8DlfOn20H+aMIRmL2pE4kJTFzr7GbYgSfzXOc68xLJyfiyc4XYQhoCxblQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZtFUuxNtGyKgTm8sYtvx7wErdP2YS57JTXaHkESRX2w=; b=RDLHBOyD5jT3y4cRoC9Y5+g+n29nHJR3U+jTrS276QPH/zoQ8b/M6vzRCTn6bnNd/jz0+W8u7AoP5S+3JSWkxYCbp8CaZhY9iUhescR0pNxzzgXNn/1UfgyJlS5/M57YpNZ9tYAdJSW2UwINZEXit/oWrjiKqtwOxjkAYuRHqDGkQ8O8Q/b8VfuZ12YbtjiW6hx+zEY3yLBkF8e6eWK9iFd5YL8ToBsiT2+ypXaFreqywrgrR3bnmbvHqqaMGn+1wEfh3H7H474+/eb1i39eI/nSQASEZqf0ZNTAwXjrr/q0sOet8syK5Gcw1eQW7/lJH3eZDFB4RW5EsxcrP8tM8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZtFUuxNtGyKgTm8sYtvx7wErdP2YS57JTXaHkESRX2w=; b=qaNMvq7xuf2Whg5bnVecwARjydnUsiwefxo0QPJa+iPZqTVSaBgufi4a0UpdjghRULM5T8pV0uPzCG0yigjE42t41/DAWmzkQiNXBRvvVfv0M1qv5J551scNwblq/13dnpKmQzh2FHC/iu2XDCC5JAc98zP3T9aGQTc/OUepx2o= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:24 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:24 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 11/37] MIPS: atomic: Use one macro to generate 32b & 64b functions Thread-Topic: [PATCH 11/37] MIPS: atomic: Use one macro to generate 32b & 64b functions Thread-Index: AQHVd+P1wlbGJw6/50+AxU3guQTeDA== Date: Mon, 30 Sep 2019 23:08:23 +0000 Message-ID: <20190930230806.2940505-12-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6bd73448-4a2a-4f47-2968-08d745fb180a x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:298; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(376002)(136003)(366004)(189003)(199004)(14454004)(508600001)(256004)(6512007)(81166006)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 9xA6VK9OpHOgV/U1Nuf9S5oINtEhOkSVur1g6VoYseZGSex9kSSACcc3KixqxTL3Nt1afEpb8slCcQNQ8GDYRfbgo66hX9iZgubBZ4WGVlEdIYe+5PBiX4dmVWT4UMwXMEPBmbdJznvTCIAvFWUh2xY5W6ja2ncfk/5sDVbPuztBC6IH5qB1B7i3s2FAj5I7pDSOYmuogxBx9QRDyVeSV2cxJJBkPlQatf6iW252l2tN0LRTVU6BsFE07N2WYRPTbVEfYahjF1OKLjmBZINN3//x0MR17of6RuD3c7d9aY0QzhAAcCfrXSZ5qrNxFlFsyvmkHn7U8p0Ii94gaY4u6T0v48+kWACsG4idlC7c9wqiFQUe6njxldi5Q3qjNZHawKm11gSEs0+GzZOi1WRKOenirUDUwVHqSAg+4Q7YWIQ= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6bd73448-4a2a-4f47-2968-08d745fb180a X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:24.0220 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: l7A30GShd4fj9rMMqQVYa83zufXwqJp/HL4h5GmLnZ6qMnz/Qf8ySRG6LbtvMeGjzLQIIrVD0LA4G1fqlQOwWQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Cut down on duplication by generalizing the ATOMIC_OP(), ATOMIC_OP_RETURN() & ATOMIC_FETCH_OP() macros to work for both 32b & 64b atomics, and removing the ATOMIC64_ variants. This ensures consistency between our atomic_* & atomic64_* functions. Signed-off-by: Paul Burton --- arch/mips/include/asm/atomic.h | 196 ++++++++------------------------- 1 file changed, 45 insertions(+), 151 deletions(-) diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h index ace2ea005588..b834af5a7382 100644 --- a/arch/mips/include/asm/atomic.h +++ b/arch/mips/include/asm/atomic.h @@ -42,10 +42,10 @@ */ #define atomic_set(v, i) WRITE_ONCE((v)->counter, (i)) -#define ATOMIC_OP(op, c_op, asm_op) \ -static __inline__ void atomic_##op(int i, atomic_t * v) \ +#define ATOMIC_OP(pfx, op, type, c_op, asm_op, ll, sc) \ +static __inline__ void pfx##_##op(type i, pfx##_t * v) \ { \ - int temp; \ + type temp; \ \ if (!kernel_uses_llsc) { \ unsigned long flags; \ @@ -60,19 +60,19 @@ static __inline__ void atomic_##op(int i, atomic_t * v) \ __asm__ __volatile__( \ " .set push \n" \ " .set " MIPS_ISA_LEVEL " \n" \ - "1: ll %0, %1 # atomic_" #op " \n" \ + "1: " #ll " %0, %1 # " #pfx "_" #op " \n" \ " " #asm_op " %0, %2 \n" \ - " sc %0, %1 \n" \ + " " #sc " %0, %1 \n" \ "\t" __SC_BEQZ "%0, 1b \n" \ " .set pop \n" \ : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (v->counter) \ : "Ir" (i) : __LLSC_CLOBBER); \ } -#define ATOMIC_OP_RETURN(op, c_op, asm_op) \ -static __inline__ int atomic_##op##_return_relaxed(int i, atomic_t * v) \ +#define ATOMIC_OP_RETURN(pfx, op, type, c_op, asm_op, ll, sc) \ +static __inline__ type pfx##_##op##_return_relaxed(type i, pfx##_t * v) \ { \ - int temp, result; \ + type temp, result; \ \ if (!kernel_uses_llsc) { \ unsigned long flags; \ @@ -89,9 +89,9 @@ static __inline__ int atomic_##op##_return_relaxed(int i, atomic_t * v) \ __asm__ __volatile__( \ " .set push \n" \ " .set " MIPS_ISA_LEVEL " \n" \ - "1: ll %1, %2 # atomic_" #op "_return \n" \ + "1: " #ll " %1, %2 # " #pfx "_" #op "_return\n" \ " " #asm_op " %0, %1, %3 \n" \ - " sc %0, %2 \n" \ + " " #sc " %0, %2 \n" \ "\t" __SC_BEQZ "%0, 1b \n" \ " " #asm_op " %0, %1, %3 \n" \ " .set pop \n" \ @@ -102,8 +102,8 @@ static __inline__ int atomic_##op##_return_relaxed(int i, atomic_t * v) \ return result; \ } -#define ATOMIC_FETCH_OP(op, c_op, asm_op) \ -static __inline__ int atomic_fetch_##op##_relaxed(int i, atomic_t * v) \ +#define ATOMIC_FETCH_OP(pfx, op, type, c_op, asm_op, ll, sc) \ +static __inline__ type pfx##_fetch_##op##_relaxed(type i, pfx##_t * v) \ { \ int temp, result; \ \ @@ -120,10 +120,10 @@ static __inline__ int atomic_fetch_##op##_relaxed(int i, atomic_t * v) \ loongson_llsc_mb(); \ __asm__ __volatile__( \ " .set push \n" \ - " .set "MIPS_ISA_LEVEL" \n" \ - "1: ll %1, %2 # atomic_fetch_" #op " \n" \ + " .set " MIPS_ISA_LEVEL " \n" \ + "1: " #ll " %1, %2 # " #pfx "_fetch_" #op "\n" \ " " #asm_op " %0, %1, %3 \n" \ - " sc %0, %2 \n" \ + " " #sc " %0, %2 \n" \ "\t" __SC_BEQZ "%0, 1b \n" \ " .set pop \n" \ " move %0, %1 \n" \ @@ -134,32 +134,50 @@ static __inline__ int atomic_fetch_##op##_relaxed(int i, atomic_t * v) \ return result; \ } -#define ATOMIC_OPS(op, c_op, asm_op) \ - ATOMIC_OP(op, c_op, asm_op) \ - ATOMIC_OP_RETURN(op, c_op, asm_op) \ - ATOMIC_FETCH_OP(op, c_op, asm_op) +#define ATOMIC_OPS(pfx, op, type, c_op, asm_op, ll, sc) \ + ATOMIC_OP(pfx, op, type, c_op, asm_op, ll, sc) \ + ATOMIC_OP_RETURN(pfx, op, type, c_op, asm_op, ll, sc) \ + ATOMIC_FETCH_OP(pfx, op, type, c_op, asm_op, ll, sc) -ATOMIC_OPS(add, +=, addu) -ATOMIC_OPS(sub, -=, subu) +ATOMIC_OPS(atomic, add, int, +=, addu, ll, sc) +ATOMIC_OPS(atomic, sub, int, -=, subu, ll, sc) #define atomic_add_return_relaxed atomic_add_return_relaxed #define atomic_sub_return_relaxed atomic_sub_return_relaxed #define atomic_fetch_add_relaxed atomic_fetch_add_relaxed #define atomic_fetch_sub_relaxed atomic_fetch_sub_relaxed +#ifdef CONFIG_64BIT +ATOMIC_OPS(atomic64, add, s64, +=, daddu, lld, scd) +ATOMIC_OPS(atomic64, sub, s64, -=, dsubu, lld, scd) +# define atomic64_add_return_relaxed atomic64_add_return_relaxed +# define atomic64_sub_return_relaxed atomic64_sub_return_relaxed +# define atomic64_fetch_add_relaxed atomic64_fetch_add_relaxed +# define atomic64_fetch_sub_relaxed atomic64_fetch_sub_relaxed +#endif /* CONFIG_64BIT */ + #undef ATOMIC_OPS -#define ATOMIC_OPS(op, c_op, asm_op) \ - ATOMIC_OP(op, c_op, asm_op) \ - ATOMIC_FETCH_OP(op, c_op, asm_op) +#define ATOMIC_OPS(pfx, op, type, c_op, asm_op, ll, sc) \ + ATOMIC_OP(pfx, op, type, c_op, asm_op, ll, sc) \ + ATOMIC_FETCH_OP(pfx, op, type, c_op, asm_op, ll, sc) -ATOMIC_OPS(and, &=, and) -ATOMIC_OPS(or, |=, or) -ATOMIC_OPS(xor, ^=, xor) +ATOMIC_OPS(atomic, and, int, &=, and, ll, sc) +ATOMIC_OPS(atomic, or, int, |=, or, ll, sc) +ATOMIC_OPS(atomic, xor, int, ^=, xor, ll, sc) #define atomic_fetch_and_relaxed atomic_fetch_and_relaxed #define atomic_fetch_or_relaxed atomic_fetch_or_relaxed #define atomic_fetch_xor_relaxed atomic_fetch_xor_relaxed +#ifdef CONFIG_64BIT +ATOMIC_OPS(atomic64, and, s64, &=, and, lld, scd) +ATOMIC_OPS(atomic64, or, s64, |=, or, lld, scd) +ATOMIC_OPS(atomic64, xor, s64, ^=, xor, lld, scd) +# define atomic64_fetch_and_relaxed atomic64_fetch_and_relaxed +# define atomic64_fetch_or_relaxed atomic64_fetch_or_relaxed +# define atomic64_fetch_xor_relaxed atomic64_fetch_xor_relaxed +#endif + #undef ATOMIC_OPS #undef ATOMIC_FETCH_OP #undef ATOMIC_OP_RETURN @@ -243,130 +261,6 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v) */ #define atomic64_set(v, i) WRITE_ONCE((v)->counter, (i)) -#define ATOMIC64_OP(op, c_op, asm_op) \ -static __inline__ void atomic64_##op(s64 i, atomic64_t * v) \ -{ \ - if (kernel_uses_llsc) { \ - s64 temp; \ - \ - loongson_llsc_mb(); \ - __asm__ __volatile__( \ - " .set push \n" \ - " .set "MIPS_ISA_LEVEL" \n" \ - "1: lld %0, %1 # atomic64_" #op " \n" \ - " " #asm_op " %0, %2 \n" \ - " scd %0, %1 \n" \ - "\t" __SC_BEQZ "%0, 1b \n" \ - " .set pop \n" \ - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (v->counter) \ - : "Ir" (i) : __LLSC_CLOBBER); \ - } else { \ - unsigned long flags; \ - \ - raw_local_irq_save(flags); \ - v->counter c_op i; \ - raw_local_irq_restore(flags); \ - } \ -} - -#define ATOMIC64_OP_RETURN(op, c_op, asm_op) \ -static __inline__ s64 atomic64_##op##_return_relaxed(s64 i, atomic64_t * v) \ -{ \ - s64 result; \ - \ - if (kernel_uses_llsc) { \ - s64 temp; \ - \ - loongson_llsc_mb(); \ - __asm__ __volatile__( \ - " .set push \n" \ - " .set "MIPS_ISA_LEVEL" \n" \ - "1: lld %1, %2 # atomic64_" #op "_return\n" \ - " " #asm_op " %0, %1, %3 \n" \ - " scd %0, %2 \n" \ - "\t" __SC_BEQZ "%0, 1b \n" \ - " " #asm_op " %0, %1, %3 \n" \ - " .set pop \n" \ - : "=&r" (result), "=&r" (temp), \ - "+" GCC_OFF_SMALL_ASM() (v->counter) \ - : "Ir" (i) : __LLSC_CLOBBER); \ - } else { \ - unsigned long flags; \ - \ - raw_local_irq_save(flags); \ - result = v->counter; \ - result c_op i; \ - v->counter = result; \ - raw_local_irq_restore(flags); \ - } \ - \ - return result; \ -} - -#define ATOMIC64_FETCH_OP(op, c_op, asm_op) \ -static __inline__ s64 atomic64_fetch_##op##_relaxed(s64 i, atomic64_t * v) \ -{ \ - s64 result; \ - \ - if (kernel_uses_llsc) { \ - s64 temp; \ - \ - loongson_llsc_mb(); \ - __asm__ __volatile__( \ - " .set push \n" \ - " .set "MIPS_ISA_LEVEL" \n" \ - "1: lld %1, %2 # atomic64_fetch_" #op "\n" \ - " " #asm_op " %0, %1, %3 \n" \ - " scd %0, %2 \n" \ - "\t" __SC_BEQZ "%0, 1b \n" \ - " move %0, %1 \n" \ - " .set pop \n" \ - : "=&r" (result), "=&r" (temp), \ - "+" GCC_OFF_SMALL_ASM() (v->counter) \ - : "Ir" (i) : __LLSC_CLOBBER); \ - } else { \ - unsigned long flags; \ - \ - raw_local_irq_save(flags); \ - result = v->counter; \ - v->counter c_op i; \ - raw_local_irq_restore(flags); \ - } \ - \ - return result; \ -} - -#define ATOMIC64_OPS(op, c_op, asm_op) \ - ATOMIC64_OP(op, c_op, asm_op) \ - ATOMIC64_OP_RETURN(op, c_op, asm_op) \ - ATOMIC64_FETCH_OP(op, c_op, asm_op) - -ATOMIC64_OPS(add, +=, daddu) -ATOMIC64_OPS(sub, -=, dsubu) - -#define atomic64_add_return_relaxed atomic64_add_return_relaxed -#define atomic64_sub_return_relaxed atomic64_sub_return_relaxed -#define atomic64_fetch_add_relaxed atomic64_fetch_add_relaxed -#define atomic64_fetch_sub_relaxed atomic64_fetch_sub_relaxed - -#undef ATOMIC64_OPS -#define ATOMIC64_OPS(op, c_op, asm_op) \ - ATOMIC64_OP(op, c_op, asm_op) \ - ATOMIC64_FETCH_OP(op, c_op, asm_op) - -ATOMIC64_OPS(and, &=, and) -ATOMIC64_OPS(or, |=, or) -ATOMIC64_OPS(xor, ^=, xor) - -#define atomic64_fetch_and_relaxed atomic64_fetch_and_relaxed -#define atomic64_fetch_or_relaxed atomic64_fetch_or_relaxed -#define atomic64_fetch_xor_relaxed atomic64_fetch_xor_relaxed - -#undef ATOMIC64_OPS -#undef ATOMIC64_FETCH_OP -#undef ATOMIC64_OP_RETURN -#undef ATOMIC64_OP - /* * atomic64_sub_if_positive - conditionally subtract integer from atomic * variable From patchwork Mon Sep 30 23:08:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167799 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C0EA14DB for ; Mon, 30 Sep 2019 23:10:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1F2AC2081B for ; Mon, 30 Sep 2019 23:10:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="alNIxFLk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732894AbfI3XK1 (ORCPT ); Mon, 30 Sep 2019 19:10:27 -0400 Received: from mail-eopbgr710120.outbound.protection.outlook.com ([40.107.71.120]:26432 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732301AbfI3XI0 (ORCPT ); Mon, 30 Sep 2019 19:08:26 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OrqyB217Zsg1jTUFDrycLyvGlkUUcmY5cGzHjbPyQmb9U4aObnVRoRV404M2XganAVPZg6+b/yMRVaYVjuOGcvw0yWSjTdg2Yes8O96UmOeF9IQbYrwuiNNa6i1yiIf0Kanciu39kaLWrFcPfCGgaE9/p/+WR6y/stnBzVOj7D4QwFqWzw464ttxMobTKVdSxC7LOySOtlhwVVzSntXAntfKJvIgSg6IaRtdLHbTtaLAA1bC7PxC2m4ePerSl22/TvkSRNj6A/W6BKGnZxhIreZsrfEiZZ6UuFC/rK5sjDOaq3tzPaMen458hyTt/6+wV6IBYB54s2o3GexuDDdXjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fm6FPvZH8hxf+zAzpzsntcS0rkuB6XfnOtezk+/vkWA=; b=Z7GOS+2ihdFZ4pphBa6UGnZmRJIHHZUUEgJOoVV3Tg7M5tINnkwPNkzjTOz+NyUTDLTMiK1wSb0jNjImkjjTAsdLKMuSLzGBvwXrZNR7QFKbWu1uz6NRhV/jG6Jk+Q2YAhi9dbQsdvTFM4boNtbTk5dYx4tW09u3pU+fMuLmu0eZN7KEz8LCkhQQag+ZDaUHzeZ3ExVeX//yLIjtZQl6nNtqkttUxVw4Q7IQvCUqI9bRgp36BMeMG+AV/lKe6oExbW8z9ETIHRvaKLHjzNJ2H/9tB0qAH+NoqXatvdeGeQ08iIek7frGhkFZ4IAxTTVJ3pyENKtTOUdC2/zDVjn+pA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fm6FPvZH8hxf+zAzpzsntcS0rkuB6XfnOtezk+/vkWA=; b=alNIxFLkgxtO30gCg2dyF2xh6SeaIPmV2eELP0cMofJl5PdLh1OnhSwSLATtcSpoYFXbfc45EmR3533/YXSNXgRXj8E0RBo2nDdTb9BV8U2sP6NO7eHCfh8o2DP9plX/qiLdrqNWgmdIEaQZ9s80vaI6cUrwlAmz6bg4HmZsuN4= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1709.namprd22.prod.outlook.com (10.164.206.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.20; Mon, 30 Sep 2019 23:08:24 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:24 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 12/37] MIPS: atomic: Emit Loongson3 sync workarounds within asm Thread-Topic: [PATCH 12/37] MIPS: atomic: Emit Loongson3 sync workarounds within asm Thread-Index: AQHVd+P2LHb7bttF2kuoIZMMsxRr2Q== Date: Mon, 30 Sep 2019 23:08:24 +0000 Message-ID: <20190930230806.2940505-13-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b2b90aa2-97df-40b2-2d1a-08d745fb1884 x-ms-traffictypediagnostic: MWHPR2201MB1709: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1186; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(39840400004)(376002)(346002)(396003)(136003)(199004)(189003)(2351001)(66476007)(66556008)(66946007)(64756008)(66446008)(107886003)(99286004)(6486002)(52116002)(5640700003)(6436002)(25786009)(478600001)(14454004)(76176011)(26005)(6512007)(5660300002)(71200400001)(71190400001)(1076003)(4326008)(186003)(42882007)(6506007)(11346002)(256004)(486006)(44832011)(476003)(2616005)(14444005)(446003)(54906003)(316002)(7736002)(305945005)(6116002)(2906002)(3846002)(81156014)(81166006)(102836004)(50226002)(6916009)(386003)(36756003)(8676002)(8936002)(66066001)(2501003);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1709;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: YFcCf4+6fBzEaCN0IeyP6/8d/qYudt+JvKxsIjv1z37/CAKsdqP0WLbZTbpFPy1SWf6/bF7YaILL7hGyAsfphdg1Xdlz3Ju53gr6q9qxK9AabJH8hb35ElVYSbPD99A5he9fPNadoWqDpwWp3ZAyIifdgTP/aIpbNMo7lK4WomzVlVtKwvjGGNQdZaQH2Tz9Cut6u6qIIXiB5pooX0PIp9BJhxpEah7AkivWRJpuOLQVdYuZHz9GzqYXnvuikUsQE8Dwi7c5XxDg1vNeCYp9QplJBgTm83FdJvCsEBMaU7B5GP10GBUay5hwi7i0IXiBqTG5LE2tfzCP5xS/WQPA2PatctMGM84BmoY9BMIYWoyP2YqgHXviE5YUIMSnhnwuHlCrArpjRzuCJ6VRFOZRjd8pkXiQf4bUgX5mCPnm+8o= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: b2b90aa2-97df-40b2-2d1a-08d745fb1884 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:24.8297 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: XjC0DEfcgWtBq3Tx8SsUz1mIiueYr9NZHTe40D8ZICyOTkC4l4RaCoGLFPBVblpN5TAAMzNrPKZTXIDRTg2QLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1709 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Generate the sync instructions required to workaround Loongson3 LL/SC errata within inline asm blocks, which feels a little safer than doing it from C where strictly speaking the compiler would be well within its rights to insert a memory access between the separate asm statements we previously had, containing sync & ll instructions respectively. Signed-off-by: Paul Burton --- arch/mips/include/asm/atomic.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h index b834af5a7382..841ff274ada6 100644 --- a/arch/mips/include/asm/atomic.h +++ b/arch/mips/include/asm/atomic.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #define ATOMIC_INIT(i) { (i) } @@ -56,10 +57,10 @@ static __inline__ void pfx##_##op(type i, pfx##_t * v) \ return; \ } \ \ - loongson_llsc_mb(); \ __asm__ __volatile__( \ " .set push \n" \ " .set " MIPS_ISA_LEVEL " \n" \ + " " __SYNC(full, loongson3_war) " \n" \ "1: " #ll " %0, %1 # " #pfx "_" #op " \n" \ " " #asm_op " %0, %2 \n" \ " " #sc " %0, %1 \n" \ @@ -85,10 +86,10 @@ static __inline__ type pfx##_##op##_return_relaxed(type i, pfx##_t * v) \ return result; \ } \ \ - loongson_llsc_mb(); \ __asm__ __volatile__( \ " .set push \n" \ " .set " MIPS_ISA_LEVEL " \n" \ + " " __SYNC(full, loongson3_war) " \n" \ "1: " #ll " %1, %2 # " #pfx "_" #op "_return\n" \ " " #asm_op " %0, %1, %3 \n" \ " " #sc " %0, %2 \n" \ @@ -117,10 +118,10 @@ static __inline__ type pfx##_fetch_##op##_relaxed(type i, pfx##_t * v) \ return result; \ } \ \ - loongson_llsc_mb(); \ __asm__ __volatile__( \ " .set push \n" \ " .set " MIPS_ISA_LEVEL " \n" \ + " " __SYNC(full, loongson3_war) " \n" \ "1: " #ll " %1, %2 # " #pfx "_fetch_" #op "\n" \ " " #asm_op " %0, %1, %3 \n" \ " " #sc " %0, %2 \n" \ @@ -200,10 +201,10 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v) if (kernel_uses_llsc) { int temp; - loongson_llsc_mb(); __asm__ __volatile__( " .set push \n" " .set "MIPS_ISA_LEVEL" \n" + " " __SYNC(full, loongson3_war) " \n" "1: ll %1, %2 # atomic_sub_if_positive\n" " .set pop \n" " subu %0, %1, %3 \n" @@ -213,7 +214,7 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v) " .set "MIPS_ISA_LEVEL" \n" " sc %1, %2 \n" "\t" __SC_BEQZ "%1, 1b \n" - "2: \n" + "2: " __SYNC(full, loongson3_war) " \n" " .set pop \n" : "=&r" (result), "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (v->counter) @@ -229,7 +230,14 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v) raw_local_irq_restore(flags); } - smp_llsc_mb(); + /* + * In the Loongson3 workaround case we already have a completion + * barrier at 2: above, which is needed due to the bltz that can branch + * to code outside of the LL/SC loop. As such, we don't need to emit + * another barrier here. + */ + if (!__SYNC_loongson3_war) + smp_llsc_mb(); return result; } From patchwork Mon Sep 30 23:08:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167791 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5FB817E1 for ; Mon, 30 Sep 2019 23:10:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A3CA02086A for ; Mon, 30 Sep 2019 23:10:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="YsGPy7Hr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732515AbfI3XIe (ORCPT ); Mon, 30 Sep 2019 19:08:34 -0400 Received: from mail-eopbgr820094.outbound.protection.outlook.com ([40.107.82.94]:14848 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732495AbfI3XId (ORCPT ); Mon, 30 Sep 2019 19:08:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OxO7Vv2OwjZH9DPWNYnMHtZpdIP5cgSJpMO8VHKhm/ZEwP/sUrg9U7tZF0Uz75lqmKXPoXiXkLo2+1K8LkEsdKI++tF2VDm4/Ns5GoHsNcSz1rz54b01J5q6Xl0yIfqHsVQV2QdMqnjqDoYCkgi8Jn8igA8az3UtcJfh26bfiIr5AJ0oIKBxuQOjITQTnDnzbkJCy8+yXDAeyz3cDUCvLMIiFkDsMn7QoN0OPP5/rAr+SvXwbqL6CSpayNPumRYfsLB2y9Dd8Qx4r5mam7onWpXQvlEW6FO8ZUvXkKAQv3dd0laM+qCUvCnVx15GmJzvZclVGAKwEFNAyDkaGoQGwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IfFkFFyX4dZVqXccoMFyxLU1QIZHdxm2ySnEWOas+FE=; b=C3pfc8lL0Tn6nA7hbZ+XV4wuQIoT6hiCkJkPqHTIKg8GoZ+J+1SAdtJXvF5gPyc6n35hIKcM/auzbbPe1FMYRNoFracMFP9rHAcscBv5/Ed0okBQXsBZOF08PSCev+j5qLbCA3/zpMo7kjlRjbNtNIKjWq8yPRLQVIeU4BjIKbBJS6I7gW5MqO/VQkr9Yu31NEkxfgRqM0LZoY7pUIPx8tbDZTESPoKijG1Xrer6DkWEPSS0Eyl+QEzFKvAoO/S1o8MS7DvIImRsXcTEsctFVTrEucq5Xbn1Gntic+2e7vpC32liKvMlUD8w1698sUgE3eui16de+U03UejYnppptw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IfFkFFyX4dZVqXccoMFyxLU1QIZHdxm2ySnEWOas+FE=; b=YsGPy7HrMtPg2g8QyK/ZTgXKYfxLVeAimfbjXNubnlq1gwdmDh4qpwrCWWkdbUX5p+lwRsehgnlEo4c3vVYUO/vVFpudqb9MFke23M2kbXTK3OaocPBdx/kUPsQypTpBEKyhpqKDwHyMruq7nsxMnaiEeLpUOQwZ3Fy3b42+jUs= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:25 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:25 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 13/37] MIPS: atomic: Use _atomic barriers in atomic_sub_if_positive() Thread-Topic: [PATCH 13/37] MIPS: atomic: Use _atomic barriers in atomic_sub_if_positive() Thread-Index: AQHVd+P2NMRzSLbeOE2Dihp5C2GVWg== Date: Mon, 30 Sep 2019 23:08:25 +0000 Message-ID: <20190930230806.2940505-14-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 5ad43eb9-0a5c-493d-421b-08d745fb18ff x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3276; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(376002)(136003)(366004)(189003)(199004)(14454004)(508600001)(256004)(6512007)(81166006)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(186003)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(4744005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: yBWvKHClNVX44CNiMysbB/O2iu2jPSi+wDFGrs9Ta1/khIl3Qyd5hP2JzEfCMlPeGiM85inb/8vEqJnzz/ozkx9lNW73AcPfpMQUsqX1CxnbdZDGzAdIWR4GyfaH+/kNkJR7i4abQ4kuS3kDNb44Latyti+p7nghYqdpuZrstGdM3RtQQH3nqu3VSt2jBJUvRHLAFgNALtD44BttWqsjfhzHyishQEiCNs+vOZUjbzNf002gCySQYOv5n1jp3DHZZL6LK5+kaApB872SQ/0iCNrsha/XtReSBqGU/echZMh8z8Oqol7r034iYEJS5Jvx7/Mu1zjfLAst/bxmRGIieEGJkG5JPxnNAMOafvkNzWw0bDuSPylwhsUx/pCQ8HzgnDlz2c50In++o4puzsWYIa6JwrjYUGq2YvKlFG3Wyhg= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5ad43eb9-0a5c-493d-421b-08d745fb18ff X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:25.6503 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: KorPUaUHMf6sIzVklDMrF7LDX3nHI5NR5KiixxTiODosFa1aVDVQ5486Q/GSlpnnM4pikM31Y5clpBh26xRohQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Use smp_mb__before_atomic() & smp_mb__after_atomic() in atomic_sub_if_positive() rather than the equivalent smp_mb__before_llsc() & smp_llsc_mb(). The former are more standard & this preps us for avoiding redundant duplicate barriers on Loongson3 in a later patch. Signed-off-by: Paul Burton --- arch/mips/include/asm/atomic.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h index 841ff274ada6..24443ef29337 100644 --- a/arch/mips/include/asm/atomic.h +++ b/arch/mips/include/asm/atomic.h @@ -196,7 +196,7 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v) { int result; - smp_mb__before_llsc(); + smp_mb__before_atomic(); if (kernel_uses_llsc) { int temp; @@ -237,7 +237,7 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v) * another barrier here. */ if (!__SYNC_loongson3_war) - smp_llsc_mb(); + smp_mb__after_atomic(); return result; } From patchwork Mon Sep 30 23:08:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167785 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63AA1912 for ; Mon, 30 Sep 2019 23:10:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2D8742086A for ; Mon, 30 Sep 2019 23:10:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="rf8yOL/0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732566AbfI3XIg (ORCPT ); Mon, 30 Sep 2019 19:08:36 -0400 Received: from mail-eopbgr820094.outbound.protection.outlook.com ([40.107.82.94]:14848 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732442AbfI3XIf (ORCPT ); Mon, 30 Sep 2019 19:08:35 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CKSiPINiG1dgTHdiMqzw134f68OvbIcqfl0x8/PWxAHRZ618XElLf3EWwg8AyVAZL+dBsIvQk6Nmp5Cs6mPvHaG5WPky71EYtpDqXrRNLWHffoFvzV0jmrd2NHFo+SbiWxalwuakYZ9mDy7gi9Lpn2QeL7wo4a1/QKzAHVtAKawZZ1oKEiztM/ntlbD6JOWMKzZ4B3CRV5BC46rSLpNFe7fkxFgamOWWdcp5mNhSQafVkQiaRZMMSTALHXZKIW9/fDRU3MsURdb4dowuIE8uL14ar67Gw0f3MQqPZShZH/us4GF2uaz60E6RTJs0+uVa5/yDdkMoCLgMttNvFLCNiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JcgA+itlK1YNuZoFXAB+qA5g1HU3tXjbDM5vRUIi+oU=; b=UG3BCi55pkqfZ/8Hh0nOLUj/CihqnNwQc+y7iGWXnIFQNNVKQCfyh/1UOpZ7R+4F/j1Zvra9+K2HCaE5gouUwYSSH7LnOycuL0crdhaUXhyunvNFmJE/RfoCLpfiGraZnk4etJ8SsLquffzfpsZQdeR+548IQXVXfDh2qi9amMfhlZC+O4QG5ue1FX0OlDF0icQbmwIyrIXUtB/Oa5NgzHFsY99Bx5dzsMvs5Cn0zWX86p10pKlqmBXmlsFPBOjMvc9HgdnF/ka5XO20lz3N1CCdzC0Gizkq94k/z5cvvsPOdso0O5p6OfL2EKQLV/nhmahPjfZebE4iXGXXSc1Jnw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JcgA+itlK1YNuZoFXAB+qA5g1HU3tXjbDM5vRUIi+oU=; b=rf8yOL/0O8SNb6TcQRDY06rTM3VqMAnbL6BAfCkb+3El5A9lONSbm/1ftKXnMBhXFu/NX67TLUTYGj7k34zsMTAMWVI1ihyeyXs5PRse6/EP5PTmbc6l0pRet3w1l9fwUL208Yn26t7rMjz3IUofMRfX6+UEYO9D6FLSg58fXm4= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:26 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:26 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 14/37] MIPS: atomic: Unify 32b & 64b sub_if_positive Thread-Topic: [PATCH 14/37] MIPS: atomic: Unify 32b & 64b sub_if_positive Thread-Index: AQHVd+P3bFYVrsF/RkKQr9JneB8VKw== Date: Mon, 30 Sep 2019 23:08:26 +0000 Message-ID: <20190930230806.2940505-15-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1b324e64-94ba-48f0-273a-08d745fb197e x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4303; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(376002)(136003)(366004)(189003)(199004)(14454004)(508600001)(256004)(6512007)(81166006)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: eooLJqn/vha0TmCg5lvN8+Xx9mbJlz8gE+zc7xP8VG+yMItA01mHsfu3W0a6loUHIQMDGDjn02fvrKhYqcEIePFb5QMy/Yn9p7BjhevdKpZoE2KWL8/BGQ+7H1yeeX2d0Xl99jxSzi5eg7VPbyl+xRXsb1aJjrNPe3PNOdu0LqmpIrXjm8+iyUDGpBmSvsXRnwPV2rBk1BVOFsP3Y04QIifUc5aoM21vfy7VcVLhY6oFN72SSIuwaKKXo0AhUvNbvQ/tbo9ch7j42lM+6+7Fk9Chyah2jKY9lmXt0/r1Kib4lyZVjQof4Nhg7aRIkPjk1Bf1Dgq/2ctgtC+y6vtpsziOpqnxTTELKBkCrSuZ0kimSyFphDjdB9ZtGiM6pKTskfQtF3k/Ah+ss8LsgFDtZ3m0gsjKuvCDmV4WYJ5y/EU= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b324e64-94ba-48f0-273a-08d745fb197e X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:26.5229 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: JxhXk2Er6bhd2po8pe/n8j589wJ7OuhO7hB31lt3WyrceIH36aKCBF1iTPKY+GcIV7AgDPOrjlpwpZItlwpTaA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Unify the definitions of atomic_sub_if_positive() & atomic64_sub_if_positive() using a macro like we do for most other atomic functions. This allows us to share the implementation ensuring consistency between the two. Notably this provides the appropriate loongson3_war barriers in the atomic64_sub_if_positive() case which were previously missing. The code is rearranged a little to handle the !kernel_uses_llsc case first in order to de-indent the LL/SC case & allow us not to go over 80 characters per line. Signed-off-by: Paul Burton --- arch/mips/include/asm/atomic.h | 164 ++++++++++++--------------------- 1 file changed, 58 insertions(+), 106 deletions(-) diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h index 24443ef29337..96ef50fa2817 100644 --- a/arch/mips/include/asm/atomic.h +++ b/arch/mips/include/asm/atomic.h @@ -192,65 +192,71 @@ ATOMIC_OPS(atomic64, xor, s64, ^=, xor, lld, scd) * Atomically test @v and subtract @i if @v is greater or equal than @i. * The function returns the old value of @v minus @i. */ -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v) -{ - int result; - - smp_mb__before_atomic(); - - if (kernel_uses_llsc) { - int temp; - - __asm__ __volatile__( - " .set push \n" - " .set "MIPS_ISA_LEVEL" \n" - " " __SYNC(full, loongson3_war) " \n" - "1: ll %1, %2 # atomic_sub_if_positive\n" - " .set pop \n" - " subu %0, %1, %3 \n" - " move %1, %0 \n" - " bltz %0, 2f \n" - " .set push \n" - " .set "MIPS_ISA_LEVEL" \n" - " sc %1, %2 \n" - "\t" __SC_BEQZ "%1, 1b \n" - "2: " __SYNC(full, loongson3_war) " \n" - " .set pop \n" - : "=&r" (result), "=&r" (temp), - "+" GCC_OFF_SMALL_ASM() (v->counter) - : "Ir" (i) : __LLSC_CLOBBER); - } else { - unsigned long flags; +#define ATOMIC_SIP_OP(pfx, type, op, ll, sc) \ +static __inline__ int pfx##_sub_if_positive(type i, pfx##_t * v) \ +{ \ + type temp, result; \ + \ + smp_mb__before_atomic(); \ + \ + if (!kernel_uses_llsc) { \ + unsigned long flags; \ + \ + raw_local_irq_save(flags); \ + result = v->counter; \ + result -= i; \ + if (result >= 0) \ + v->counter = result; \ + raw_local_irq_restore(flags); \ + smp_mb__after_atomic(); \ + return result; \ + } \ + \ + __asm__ __volatile__( \ + " .set push \n" \ + " .set " MIPS_ISA_LEVEL " \n" \ + " " __SYNC(full, loongson3_war) " \n" \ + "1: " #ll " %1, %2 # atomic_sub_if_positive\n" \ + " .set pop \n" \ + " " #op " %0, %1, %3 \n" \ + " move %1, %0 \n" \ + " bltz %0, 2f \n" \ + " .set push \n" \ + " .set " MIPS_ISA_LEVEL " \n" \ + " " #sc " %1, %2 \n" \ + " " __SC_BEQZ "%1, 1b \n" \ + "2: " __SYNC(full, loongson3_war) " \n" \ + " .set pop \n" \ + : "=&r" (result), "=&r" (temp), \ + "+" GCC_OFF_SMALL_ASM() (v->counter) \ + : "Ir" (i) \ + : __LLSC_CLOBBER); \ + \ + /* \ + * In the Loongson3 workaround case we already have a \ + * completion barrier at 2: above, which is needed due to the \ + * bltz that can branch to code outside of the LL/SC loop. As \ + * such, we don't need to emit another barrier here. \ + */ \ + if (!__SYNC_loongson3_war) \ + smp_mb__after_atomic(); \ + \ + return result; \ +} - raw_local_irq_save(flags); - result = v->counter; - result -= i; - if (result >= 0) - v->counter = result; - raw_local_irq_restore(flags); - } +ATOMIC_SIP_OP(atomic, int, subu, ll, sc) +#define atomic_dec_if_positive(v) atomic_sub_if_positive(1, v) - /* - * In the Loongson3 workaround case we already have a completion - * barrier at 2: above, which is needed due to the bltz that can branch - * to code outside of the LL/SC loop. As such, we don't need to emit - * another barrier here. - */ - if (!__SYNC_loongson3_war) - smp_mb__after_atomic(); +#ifdef CONFIG_64BIT +ATOMIC_SIP_OP(atomic64, s64, dsubu, lld, scd) +#define atomic64_dec_if_positive(v) atomic64_sub_if_positive(1, v) +#endif - return result; -} +#undef ATOMIC_SIP_OP #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n))) #define atomic_xchg(v, new) (xchg(&((v)->counter), (new))) -/* - * atomic_dec_if_positive - decrement by 1 if old value positive - * @v: pointer of type atomic_t - */ -#define atomic_dec_if_positive(v) atomic_sub_if_positive(1, v) - #ifdef CONFIG_64BIT #define ATOMIC64_INIT(i) { (i) } @@ -269,64 +275,10 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v) */ #define atomic64_set(v, i) WRITE_ONCE((v)->counter, (i)) -/* - * atomic64_sub_if_positive - conditionally subtract integer from atomic - * variable - * @i: integer value to subtract - * @v: pointer of type atomic64_t - * - * Atomically test @v and subtract @i if @v is greater or equal than @i. - * The function returns the old value of @v minus @i. - */ -static __inline__ s64 atomic64_sub_if_positive(s64 i, atomic64_t * v) -{ - s64 result; - - smp_mb__before_llsc(); - - if (kernel_uses_llsc) { - s64 temp; - - __asm__ __volatile__( - " .set push \n" - " .set "MIPS_ISA_LEVEL" \n" - "1: lld %1, %2 # atomic64_sub_if_positive\n" - " dsubu %0, %1, %3 \n" - " move %1, %0 \n" - " bltz %0, 1f \n" - " scd %1, %2 \n" - "\t" __SC_BEQZ "%1, 1b \n" - "1: \n" - " .set pop \n" - : "=&r" (result), "=&r" (temp), - "+" GCC_OFF_SMALL_ASM() (v->counter) - : "Ir" (i)); - } else { - unsigned long flags; - - raw_local_irq_save(flags); - result = v->counter; - result -= i; - if (result >= 0) - v->counter = result; - raw_local_irq_restore(flags); - } - - smp_llsc_mb(); - - return result; -} - #define atomic64_cmpxchg(v, o, n) \ ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n))) #define atomic64_xchg(v, new) (xchg(&((v)->counter), (new))) -/* - * atomic64_dec_if_positive - decrement by 1 if old value positive - * @v: pointer of type atomic64_t - */ -#define atomic64_dec_if_positive(v) atomic64_sub_if_positive(1, v) - #endif /* CONFIG_64BIT */ #endif /* _ASM_ATOMIC_H */ From patchwork Mon Sep 30 23:08:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167787 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8FF1614DB for ; Mon, 30 Sep 2019 23:10:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6E4252081B for ; Mon, 30 Sep 2019 23:10:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="n2n7I+Xa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732553AbfI3XIg (ORCPT ); Mon, 30 Sep 2019 19:08:36 -0400 Received: from mail-eopbgr690120.outbound.protection.outlook.com ([40.107.69.120]:5486 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732524AbfI3XIf (ORCPT ); Mon, 30 Sep 2019 19:08:35 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FecrNjBf701D8OEGBBAlLgW164YoxuKol4NQIH3ZiVuRV5yX2VFgkEBJg7lQOltbMCOX3OFQXC7Doj4ges5xN1L8Vir9hfRZQcAQTmsOMyB4XsTb7CEzMdhq36yPpfTiZdpXPVNXszY3gvDMOD9cXYr4eay8K9GQyCpycZfnvR+XG54gRZjF1j8/uJj2jcSFvhOqIKc/unNhhcg1BSIdKr1i3e4ruviBeJ1dP6Dmaiv5hkIFYV4IJvGzeZd1OsKRTwvOOvZeJD0sxr+0UuwBmckYX2f6DbJ0NZzWFM6o4kZWgTYxNRTa2roEgW+ExRrSsgxY7mMgZv/amh5gINT++w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=J3uKaoCO7FzQJHIbI0DhZFwrC+UyLgiCc6+uwJwRO5o=; b=GCYkOVmrGQcT1o38m+9XVOGDQu2g1Zl9OXmwMWSUfHYyQmeUFEY90mwBTMDi10His/yb4hklFGdgbof4IJwYCnQyuw36SGRO+VjTI1rNcT2MDvtbu0Fvbo5MAUk5WrJ1KDOCVzpX8iTzcakkDSYZWIZYpYhz4hHCWGnC6eBujBHy22pn0cFjJcJgRKKHKDVI/hfSdgHclflCrMptCBAsX1BexqoaLKUCJj0zFNSDsDIPqJQZaoA6XpxU+zA8gXQpL+8NHCcinuk7vMIVwSYqSvrbtd1hsYsJZJVXv0T9pqKhpx0+ZzHXFE02BxAQiHss6YDfmYSRzyCiVABWNWj9dQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=J3uKaoCO7FzQJHIbI0DhZFwrC+UyLgiCc6+uwJwRO5o=; b=n2n7I+XaEi7dp1dqpP0QR+D38UcZF43TJhbFl6KvLsfiklY/64/CUHAj1eLegf1lDdy5Y36hIsS0LA6KtO2qiTj9SRI64SigkkFx3HkItEXD8oa2rwBPtKlmnjO20+pH6q83UQsK64mPpc4Bc64oifed0B26xtd1s+wvcBOn1a4= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:27 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:27 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 15/37] MIPS: atomic: Deduplicate 32b & 64b read, set, xchg, cmpxchg Thread-Topic: [PATCH 15/37] MIPS: atomic: Deduplicate 32b & 64b read, set, xchg, cmpxchg Thread-Index: AQHVd+P3/LviTIzozkW5FHZOcasyGw== Date: Mon, 30 Sep 2019 23:08:27 +0000 Message-ID: <20190930230806.2940505-16-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4e7fb17f-6c83-42fd-7436-08d745fb1a03 x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4502; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(376002)(136003)(366004)(189003)(199004)(14454004)(508600001)(256004)(6512007)(81166006)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(186003)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002)(17423001)(156123004);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: LkTOYwvQiBygneB0U8I6lcwIk+8gWZieQHboF7jXEyb1Qg1CQsNk6iZ/beExSrMx2SMn6ZxkWj3rFzm411zw1uuvhaMlsqxgGns9bJ7EkMrcbmeZhOULG/c0QDuvMXOZpHb3CiqVx2JSjnli5VL5aI8C5KZqcgOOsBFcz+jove65Ft743QlARWTp8f5is8MjQht3bJz9cW6pIS1A87fZ6p9d/ktU0DJSj/wsvmolfVgvVrHKK21HYNLQrLu2wG/DXz8Z21HnUN/EjYduvUFtmdur5YCi7TFlSDiHPgTzzcywzshdng/4qcFOwTmegFlboYpx2/tbHNPagHbaSrWnhbKxN79MUGxXzIsog9vPlbMO/JMFkg1vbFSQP2KPPyCUkk+U7fEiMbtHYtNv6CYa6Ei9R3nA/fX7UT5tw8+Vgeg= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e7fb17f-6c83-42fd-7436-08d745fb1a03 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:27.3295 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: SSebEwfI5rO5uWxjV/U754BDx4kI5mY22r/74G0ELP8RfXK0UmHECqjr7eTqWkm+hqYfxIvko08YhmoapjQauQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Remove the remaining duplication between 32b & 64b in asm/atomic.h by making use of an ATOMIC_OPS() macro to generate: - atomic_read()/atomic64_read() - atomic_set()/atomic64_set() - atomic_cmpxchg()/atomic64_cmpxchg() - atomic_xchg()/atomic64_xchg() This is consistent with the way all other functions in asm/atomic.h are generated, and ensures consistency between the 32b & 64b functions. Of note is that this results in the above now being static inline functions rather than macros. Signed-off-by: Paul Burton --- arch/mips/include/asm/atomic.h | 70 +++++++++++++--------------------- 1 file changed, 27 insertions(+), 43 deletions(-) diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h index 96ef50fa2817..e5ac88392d1f 100644 --- a/arch/mips/include/asm/atomic.h +++ b/arch/mips/include/asm/atomic.h @@ -24,24 +24,34 @@ #include #include -#define ATOMIC_INIT(i) { (i) } +#define ATOMIC_OPS(pfx, type) \ +static __always_inline type pfx##_read(const pfx##_t *v) \ +{ \ + return READ_ONCE(v->counter); \ +} \ + \ +static __always_inline void pfx##_set(pfx##_t *v, type i) \ +{ \ + WRITE_ONCE(v->counter, i); \ +} \ + \ +static __always_inline type pfx##_cmpxchg(pfx##_t *v, type o, type n) \ +{ \ + return cmpxchg(&v->counter, o, n); \ +} \ + \ +static __always_inline type pfx##_xchg(pfx##_t *v, type n) \ +{ \ + return xchg(&v->counter, n); \ +} -/* - * atomic_read - read atomic variable - * @v: pointer of type atomic_t - * - * Atomically reads the value of @v. - */ -#define atomic_read(v) READ_ONCE((v)->counter) +#define ATOMIC_INIT(i) { (i) } +ATOMIC_OPS(atomic, int) -/* - * atomic_set - set atomic variable - * @v: pointer of type atomic_t - * @i: required value - * - * Atomically sets the value of @v to @i. - */ -#define atomic_set(v, i) WRITE_ONCE((v)->counter, (i)) +#ifdef CONFIG_64BIT +# define ATOMIC64_INIT(i) { (i) } +ATOMIC_OPS(atomic64, s64) +#endif #define ATOMIC_OP(pfx, op, type, c_op, asm_op, ll, sc) \ static __inline__ void pfx##_##op(type i, pfx##_t * v) \ @@ -135,6 +145,7 @@ static __inline__ type pfx##_fetch_##op##_relaxed(type i, pfx##_t * v) \ return result; \ } +#undef ATOMIC_OPS #define ATOMIC_OPS(pfx, op, type, c_op, asm_op, ll, sc) \ ATOMIC_OP(pfx, op, type, c_op, asm_op, ll, sc) \ ATOMIC_OP_RETURN(pfx, op, type, c_op, asm_op, ll, sc) \ @@ -254,31 +265,4 @@ ATOMIC_SIP_OP(atomic64, s64, dsubu, lld, scd) #undef ATOMIC_SIP_OP -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n))) -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new))) - -#ifdef CONFIG_64BIT - -#define ATOMIC64_INIT(i) { (i) } - -/* - * atomic64_read - read atomic variable - * @v: pointer of type atomic64_t - * - */ -#define atomic64_read(v) READ_ONCE((v)->counter) - -/* - * atomic64_set - set atomic variable - * @v: pointer of type atomic64_t - * @i: required value - */ -#define atomic64_set(v, i) WRITE_ONCE((v)->counter, (i)) - -#define atomic64_cmpxchg(v, o, n) \ - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n))) -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new))) - -#endif /* CONFIG_64BIT */ - #endif /* _ASM_ATOMIC_H */ From patchwork Mon Sep 30 23:08:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167765 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A66B3912 for ; Mon, 30 Sep 2019 23:09:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7246E2086A for ; Mon, 30 Sep 2019 23:09:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="r1/J0cyr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730573AbfI3XJm (ORCPT ); Mon, 30 Sep 2019 19:09:42 -0400 Received: from mail-eopbgr690120.outbound.protection.outlook.com ([40.107.69.120]:5486 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732495AbfI3XJl (ORCPT ); Mon, 30 Sep 2019 19:09:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H94x+5/eLp3RhaZxu6ai5ErJfhzu4u489AbCBDP3Owolct8O0Cp1zvuuEQfgq9/PEdzeu1RNDbAjQCN6lMMFsYz3G1tuvBxVitaFYsNAn62CAHSGdbjC95yqLL0sS1QqPWAie7DLQ3haAf0STDBoJG0q+cPkvin9EuRk2DaW/m+bhadJVkfYC6E9ylqdhSxF+xpOA/JN6gq6UPwHkSQiuU9I+rnbhsGjvM3TolXN815deSA2lyiscsTgNRtsDTLw207/ujaHxzco9ZwsuITEHr+7rMWySbcYZ11bjFdcKGpZwCP+7wB+f2HXppZ3iyxujz0UzTxmBKbQ4Me3sxP1Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=teHP17IFWXIfuZRdFHCsldo74h/QIqpIXn+WjpeR/aA=; b=SRznxDMz6D19RCVGdnVLsZQ/hnr4FU3vKVQJuLszSpn66YrMXGMatf+wYHohCfRKNwNo+FatXwrUweBDer2hCMIz3uLYWO6DWTsqjUGpNylsBzig+lRdNw4rE7BcQ90Lkrd4eEv8tdeRkyFvU2m99X/qAyd4LGMeCe8nXJYc0g/Q4ERcM14Nvh7YXsOXzDBabw0NQklyin6LadwxxNH5aQ3UwfuUW35FGsWSMmahNr/EvmGnAfM24sTimcndE4EoaugyRU1dVsIDdRGN+9aAr4DgDby2sP5U0EvMe0tt/qpieIrBk/yrIYNcyutlXQS1iQJS4XoQ/a479zQcfQT0rA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=teHP17IFWXIfuZRdFHCsldo74h/QIqpIXn+WjpeR/aA=; b=r1/J0cyruvY/J+/l6EKDTb5RUfyWJV9u80R69bmtHmARSJHqMbyTJhgWWg0XhfQUa9n9rmPtuEwWfzFwfwb8s46CxNjnKp2uIT0fMHgq0ABAqNtOpBSspbn76JFjZVfh4wCtiPvvA6Upt3wbtE9Hcbaub0ymgITdYwlZyqCB1Nc= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:28 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:28 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 16/37] MIPS: bitops: Use generic builtin ffs/fls; drop cpu_has_clo_clz Thread-Topic: [PATCH 16/37] MIPS: bitops: Use generic builtin ffs/fls; drop cpu_has_clo_clz Thread-Index: AQHVd+P4sxZAmDQwJUGcaxRTKS+8Gg== Date: Mon, 30 Sep 2019 23:08:28 +0000 Message-ID: <20190930230806.2940505-17-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 8fc58cc5-2f85-4292-622f-08d745fb1a7e x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(376002)(136003)(366004)(189003)(199004)(14454004)(508600001)(256004)(6512007)(81166006)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(186003)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002)(41533002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: DErhcZ1UuLtrsYEZRVxIWVBs/dvnPMXLhMIYVb0urDw0caV0dDMonr2nQwHglZKxQuWOhKP36YrTAuzjRHET3zwRMZH0IxaJSgwZ1jZZ/qhJ8/TiVBSGWkrF1Q6cTh1duCPvabw1pXlTJOaWjmxqtCmy3mGOIQ5gzkS9WB7x034SXQ6G4dBGHh0NIu1oiHWtT8kNDVzF4RKG65sE4oCW1Ob9vkXMXVHXcidagDUz/xBBiRFXZGtJ8T6409OhnC/2EfAmaEl6Lzye5v6QbhbiYKkdZ0KngezDt7CWVxgbnTM8djiDNSE5ifGO0TBxi5qRJVwJpArMjXgFzc1Z00pWFRsAjkPzcPWZ1j9YLRyToxxIqCUzdUhDUWqIeAxPt+a+Tka7MTpPolBazECbRxiVh4xiXpy+LxnBLDNvVexgzqw= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8fc58cc5-2f85-4292-622f-08d745fb1a7e X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:28.1751 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: X+WEHG9E2n8mqTKNslxi2ndQnyn6bQbKzAtny12rOaNKk1qbzN+KOrcFNiMn/AqIhxsVyT81Vsuqz/D1Dkn7PQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org The MIPS-specific implementations of __ffs(), ffs(), __fls() & fls() make use of the MIPS clz instruction where possible. They do this via inline asm, but in any configuration in which the kernel is built for a MIPS32 or MIPS64 release 1 or higher instruction set we know that these instructions are available & can be emitted using the __builtin_clz() function & other associated builtins which are provided by all currently supported versions of gcc. When targeting an older instruction set GCC will generate a longer code sequence similar to the fallback cases we have in our implementations. As such, remove our custom implementations of these functions & use the generic versions built atop compiler builtins. This allows us to drop a significant chunk of code, along with the cpu_has_clo_clz feature macro which was only used by these functions. The only thing we lose here is the ability for kernels built to target a pre-r1 ISA to opportunistically make use of clz when running on a CPU that implements it. This seems like a small cost, and well worth paying to simplify the code. Signed-off-by: Paul Burton --- arch/mips/include/asm/bitops.h | 146 +----------------- arch/mips/include/asm/cpu-features.h | 10 -- .../asm/mach-malta/cpu-feature-overrides.h | 2 - 3 files changed, 4 insertions(+), 154 deletions(-) diff --git a/arch/mips/include/asm/bitops.h b/arch/mips/include/asm/bitops.h index 985d6a02f9ea..4b618afbfa5b 100644 --- a/arch/mips/include/asm/bitops.h +++ b/arch/mips/include/asm/bitops.h @@ -491,149 +491,11 @@ static inline void __clear_bit_unlock(unsigned long nr, volatile unsigned long * nudge_writes(); } -/* - * Return the bit position (0..63) of the most significant 1 bit in a word - * Returns -1 if no 1 bit exists - */ -static __always_inline unsigned long __fls(unsigned long word) -{ - int num; - - if (BITS_PER_LONG == 32 && !__builtin_constant_p(word) && - __builtin_constant_p(cpu_has_clo_clz) && cpu_has_clo_clz) { - __asm__( - " .set push \n" - " .set "MIPS_ISA_LEVEL" \n" - " clz %0, %1 \n" - " .set pop \n" - : "=r" (num) - : "r" (word)); - - return 31 - num; - } - - if (BITS_PER_LONG == 64 && !__builtin_constant_p(word) && - __builtin_constant_p(cpu_has_mips64) && cpu_has_mips64) { - __asm__( - " .set push \n" - " .set "MIPS_ISA_LEVEL" \n" - " dclz %0, %1 \n" - " .set pop \n" - : "=r" (num) - : "r" (word)); - - return 63 - num; - } - - num = BITS_PER_LONG - 1; - -#if BITS_PER_LONG == 64 - if (!(word & (~0ul << 32))) { - num -= 32; - word <<= 32; - } -#endif - if (!(word & (~0ul << (BITS_PER_LONG-16)))) { - num -= 16; - word <<= 16; - } - if (!(word & (~0ul << (BITS_PER_LONG-8)))) { - num -= 8; - word <<= 8; - } - if (!(word & (~0ul << (BITS_PER_LONG-4)))) { - num -= 4; - word <<= 4; - } - if (!(word & (~0ul << (BITS_PER_LONG-2)))) { - num -= 2; - word <<= 2; - } - if (!(word & (~0ul << (BITS_PER_LONG-1)))) - num -= 1; - return num; -} - -/* - * __ffs - find first bit in word. - * @word: The word to search - * - * Returns 0..SZLONG-1 - * Undefined if no bit exists, so code should check against 0 first. - */ -static __always_inline unsigned long __ffs(unsigned long word) -{ - return __fls(word & -word); -} - -/* - * fls - find last bit set. - * @word: The word to search - * - * This is defined the same way as ffs. - * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. - */ -static inline int fls(unsigned int x) -{ - int r; - - if (!__builtin_constant_p(x) && - __builtin_constant_p(cpu_has_clo_clz) && cpu_has_clo_clz) { - __asm__( - " .set push \n" - " .set "MIPS_ISA_LEVEL" \n" - " clz %0, %1 \n" - " .set pop \n" - : "=r" (x) - : "r" (x)); - - return 32 - x; - } - - r = 32; - if (!x) - return 0; - if (!(x & 0xffff0000u)) { - x <<= 16; - r -= 16; - } - if (!(x & 0xff000000u)) { - x <<= 8; - r -= 8; - } - if (!(x & 0xf0000000u)) { - x <<= 4; - r -= 4; - } - if (!(x & 0xc0000000u)) { - x <<= 2; - r -= 2; - } - if (!(x & 0x80000000u)) { - x <<= 1; - r -= 1; - } - return r; -} - +#include +#include +#include +#include #include - -/* - * ffs - find first bit set. - * @word: The word to search - * - * This is defined the same way as - * the libc and compiler builtin ffs routines, therefore - * differs in spirit from the above ffz (man ffs). - */ -static inline int ffs(int word) -{ - if (!word) - return 0; - - return fls(word & -word); -} - #include #include diff --git a/arch/mips/include/asm/cpu-features.h b/arch/mips/include/asm/cpu-features.h index 983a6a7f43a1..274a35ae15af 100644 --- a/arch/mips/include/asm/cpu-features.h +++ b/arch/mips/include/asm/cpu-features.h @@ -362,16 +362,6 @@ }) #endif -/* - * MIPS32, MIPS64, VR5500, IDT32332, IDT32334 and maybe a few other - * pre-MIPS32/MIPS64 processors have CLO, CLZ. The IDT RC64574 is 64-bit and - * has CLO and CLZ but not DCLO nor DCLZ. For 64-bit kernels - * cpu_has_clo_clz also indicates the availability of DCLO and DCLZ. - */ -#ifndef cpu_has_clo_clz -#define cpu_has_clo_clz cpu_has_mips_r -#endif - /* * MIPS32 R2, MIPS64 R2, Loongson 3A and Octeon have WSBH. * MIPS64 R2, Loongson 3A and Octeon have WSBH, DSBH and DSHD. diff --git a/arch/mips/include/asm/mach-malta/cpu-feature-overrides.h b/arch/mips/include/asm/mach-malta/cpu-feature-overrides.h index de3b66a3723e..193c0912d38e 100644 --- a/arch/mips/include/asm/mach-malta/cpu-feature-overrides.h +++ b/arch/mips/include/asm/mach-malta/cpu-feature-overrides.h @@ -32,7 +32,6 @@ /* #define cpu_has_vtag_icache ? */ /* #define cpu_has_dc_aliases ? */ /* #define cpu_has_ic_fills_f_dc ? */ -#define cpu_has_clo_clz 1 #define cpu_has_nofpuex 0 /* #define cpu_has_64bits ? */ /* #define cpu_has_64bit_zero_reg ? */ @@ -59,7 +58,6 @@ /* #define cpu_has_vtag_icache ? */ /* #define cpu_has_dc_aliases ? */ /* #define cpu_has_ic_fills_f_dc ? */ -#define cpu_has_clo_clz 1 #define cpu_has_nofpuex 0 /* #define cpu_has_64bits ? */ /* #define cpu_has_64bit_zero_reg ? */ From patchwork Mon Sep 30 23:08:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167743 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F3D0A14DB for ; Mon, 30 Sep 2019 23:08:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BE8E721855 for ; Mon, 30 Sep 2019 23:08:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="WUmHQoyP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732625AbfI3XIp (ORCPT ); Mon, 30 Sep 2019 19:08:45 -0400 Received: from mail-eopbgr820094.outbound.protection.outlook.com ([40.107.82.94]:14848 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732541AbfI3XIj (ORCPT ); Mon, 30 Sep 2019 19:08:39 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TdgQtKANOmTpQWn6R1gdb9mseCN45OivmHVAsruSs5z0pTlD4OoghYjvVchKl8XRvcdoOZsM2NSxzGCBPWZ7AMyJoleGts33/JssW/OWr56Te41inFFL0C7d2igRW6hicZUYOwxM30DQbtXY1TauegtJ5KvMFq8f2808PV3jL3jln3rDU4vfA8QlSdDJOiwqRG7Ly5lahfInKbVWvIq01N/sgHCo29AD3oLkfvQC6zfx0Gg3MYwwGEIUMClymRoabI/WHglrPIuW5AzTkbqeb7su9WVYj1NhBFU9CAAEY+gHxfnTGjRAyKlMhrtMKYd225bmpUDkXlAUwgwGR0LqBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WwCHP8f9vEEqF1DOMB5/K7kyiVoVkxQPBMeJvvZV5TQ=; b=jyBI8RI1+ozP15kI4nXJ0i3x2DhoXplRDphQnJhNbPNrPvxqdw15IAT7FojuHWVAbP9L3Ok4QhIQ6+jJ9helxPbdnFtush09LdUh+Nn89irZ0bnr1xwk9xAV1m0ZNiVdnRAlC4ZXE5y0ZmlxSij8T4Pju+yU1PPJ8Q7SdAgbnJRyF3EdRWks0dJ6HgtD3prFagkNDD03OUqPF8aBcU/VZo/NWPxDp9QCOjmlLY/Fez2Ciju4QAr1rz7Jn+L6Z/Gg3hZodQAtW/HpU1dz0/gR0PFGemkpdaIiPPxdaDi4INW2Flgc8k3pZ5YD/NyzBg6v1PBsCBK2164pzPjvJY6RtQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WwCHP8f9vEEqF1DOMB5/K7kyiVoVkxQPBMeJvvZV5TQ=; b=WUmHQoyPp6+63Fto2wIvA3FKjcgmPNe73H7jZcglzE83MxiqFQanOIhFRYEPx/27NUk5gN+YwOiz5TdXD7Qzht7SHl16980jeBTSd1ZQPF5mYbrddsfJ78JMzl/mmDaW4et8Tj8FODEik5gJ5rYVccrLPCA+zQ0kOuSIquZUR3k= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:29 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:29 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 17/37] MIPS: bitops: Handle !kernel_uses_llsc first Thread-Topic: [PATCH 17/37] MIPS: bitops: Handle !kernel_uses_llsc first Thread-Index: AQHVd+P4EAlteNxBukiF3XGmYDe6Yg== Date: Mon, 30 Sep 2019 23:08:28 +0000 Message-ID: <20190930230806.2940505-18-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d20ec455-e8bb-460c-65e3-08d745fb1af8 x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2399; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(376002)(136003)(366004)(189003)(199004)(14454004)(508600001)(256004)(6512007)(81166006)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(30864003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: GKmbXYzMoY32hNd77uIXKdML7Qy4kZyiPhbN6Hsk4XKJFasSyyvvIlbJ08+7weXNWSgxsZC4P0y3H+vSoKmKAnNK3A2EurWM1sT3Q/YMOoKt1fGEhDOLfrcni6ihZDuXdc7PULsbzEMWobCu0Ow4bBa3jNwryFeBG9O2eVzzfpM/IeVixLzOIJCk0f0cIbaAono1Z9yn0qnF/nmnZUrBnxcV/vaUjzh4ZECRuNgHN01huORofeECazWBvqzwyIdLQ0D7B0lzVqBoNbM6LsSPp62/YP0PIZAo7+DBlSB4sbh/ET77tUYQZd/I5BuESRiT1j2msUj3uuUZmH6MkVdOw0j/3jXPlxvOgsVHNiep126OYyj1m9BZDqYiuKblrQus1YvRQuU6vukdHxxntJI4tHf3mktKs9vpnc8ZjCnGUZs= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: d20ec455-e8bb-460c-65e3-08d745fb1af8 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:28.9688 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Z8j0rAxC9uYMKpbITzy8bvpsHnQm5srFUK7UPHJLb7XGG+gerhGZRRO9q+IgH6Pizg+d4PRB4+Iws4DWc4BpJg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Reorder conditions in our various bitops functions that check kernel_uses_llsc such that they handle the !kernel_uses_llsc case first. This allows us to avoid the need to duplicate the kernel_uses_llsc check in all the other cases. For functions that don't involve barriers common to the various implementations, we switch to returning from within each if block making each case easier to read in isolation. Signed-off-by: Paul Burton --- arch/mips/include/asm/bitops.h | 213 ++++++++++++++++----------------- 1 file changed, 105 insertions(+), 108 deletions(-) diff --git a/arch/mips/include/asm/bitops.h b/arch/mips/include/asm/bitops.h index 4b618afbfa5b..d3f3f37ca0b1 100644 --- a/arch/mips/include/asm/bitops.h +++ b/arch/mips/include/asm/bitops.h @@ -52,11 +52,16 @@ int __mips_test_and_change_bit(unsigned long nr, */ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) { - unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG); + unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); int bit = nr & SZLONG_MASK; unsigned long temp; - if (kernel_uses_llsc && R10000_LLSC_WAR) { + if (!kernel_uses_llsc) { + __mips_set_bit(nr, addr); + return; + } + + if (R10000_LLSC_WAR) { __asm__ __volatile__( " .set push \n" " .set arch=r4000 \n" @@ -68,8 +73,11 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) : "=&r" (temp), "=" GCC_OFF_SMALL_ASM() (*m) : "ir" (1UL << bit), GCC_OFF_SMALL_ASM() (*m) : __LLSC_CLOBBER); + return; + } + #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) - } else if (kernel_uses_llsc && __builtin_constant_p(bit)) { + if (__builtin_constant_p(bit)) { loongson_llsc_mb(); do { __asm__ __volatile__( @@ -80,23 +88,23 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) : "ir" (bit), "r" (~0) : __LLSC_CLOBBER); } while (unlikely(!temp)); + return; + } #endif /* CONFIG_CPU_MIPSR2 || CONFIG_CPU_MIPSR6 */ - } else if (kernel_uses_llsc) { - loongson_llsc_mb(); - do { - __asm__ __volatile__( - " .set push \n" - " .set "MIPS_ISA_ARCH_LEVEL" \n" - " " __LL "%0, %1 # set_bit \n" - " or %0, %2 \n" - " " __SC "%0, %1 \n" - " .set pop \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "ir" (1UL << bit) - : __LLSC_CLOBBER); - } while (unlikely(!temp)); - } else - __mips_set_bit(nr, addr); + + loongson_llsc_mb(); + do { + __asm__ __volatile__( + " .set push \n" + " .set "MIPS_ISA_ARCH_LEVEL" \n" + " " __LL "%0, %1 # set_bit \n" + " or %0, %2 \n" + " " __SC "%0, %1 \n" + " .set pop \n" + : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) + : "ir" (1UL << bit) + : __LLSC_CLOBBER); + } while (unlikely(!temp)); } /* @@ -111,11 +119,16 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) */ static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) { - unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG); + unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); int bit = nr & SZLONG_MASK; unsigned long temp; - if (kernel_uses_llsc && R10000_LLSC_WAR) { + if (!kernel_uses_llsc) { + __mips_clear_bit(nr, addr); + return; + } + + if (R10000_LLSC_WAR) { __asm__ __volatile__( " .set push \n" " .set arch=r4000 \n" @@ -127,8 +140,11 @@ static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) : "ir" (~(1UL << bit)) : __LLSC_CLOBBER); + return; + } + #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) - } else if (kernel_uses_llsc && __builtin_constant_p(bit)) { + if (__builtin_constant_p(bit)) { loongson_llsc_mb(); do { __asm__ __volatile__( @@ -139,23 +155,23 @@ static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) : "ir" (bit) : __LLSC_CLOBBER); } while (unlikely(!temp)); + return; + } #endif /* CONFIG_CPU_MIPSR2 || CONFIG_CPU_MIPSR6 */ - } else if (kernel_uses_llsc) { - loongson_llsc_mb(); - do { - __asm__ __volatile__( - " .set push \n" - " .set "MIPS_ISA_ARCH_LEVEL" \n" - " " __LL "%0, %1 # clear_bit \n" - " and %0, %2 \n" - " " __SC "%0, %1 \n" - " .set pop \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "ir" (~(1UL << bit)) - : __LLSC_CLOBBER); - } while (unlikely(!temp)); - } else - __mips_clear_bit(nr, addr); + + loongson_llsc_mb(); + do { + __asm__ __volatile__( + " .set push \n" + " .set "MIPS_ISA_ARCH_LEVEL" \n" + " " __LL "%0, %1 # clear_bit \n" + " and %0, %2 \n" + " " __SC "%0, %1 \n" + " .set pop \n" + : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) + : "ir" (~(1UL << bit)) + : __LLSC_CLOBBER); + } while (unlikely(!temp)); } /* @@ -183,12 +199,16 @@ static inline void clear_bit_unlock(unsigned long nr, volatile unsigned long *ad */ static inline void change_bit(unsigned long nr, volatile unsigned long *addr) { + unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); int bit = nr & SZLONG_MASK; + unsigned long temp; - if (kernel_uses_llsc && R10000_LLSC_WAR) { - unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG); - unsigned long temp; + if (!kernel_uses_llsc) { + __mips_change_bit(nr, addr); + return; + } + if (R10000_LLSC_WAR) { __asm__ __volatile__( " .set push \n" " .set arch=r4000 \n" @@ -200,25 +220,22 @@ static inline void change_bit(unsigned long nr, volatile unsigned long *addr) : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) : "ir" (1UL << bit) : __LLSC_CLOBBER); - } else if (kernel_uses_llsc) { - unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG); - unsigned long temp; + return; + } - loongson_llsc_mb(); - do { - __asm__ __volatile__( - " .set push \n" - " .set "MIPS_ISA_ARCH_LEVEL" \n" - " " __LL "%0, %1 # change_bit \n" - " xor %0, %2 \n" - " " __SC "%0, %1 \n" - " .set pop \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "ir" (1UL << bit) - : __LLSC_CLOBBER); - } while (unlikely(!temp)); - } else - __mips_change_bit(nr, addr); + loongson_llsc_mb(); + do { + __asm__ __volatile__( + " .set push \n" + " .set "MIPS_ISA_ARCH_LEVEL" \n" + " " __LL "%0, %1 # change_bit \n" + " xor %0, %2 \n" + " " __SC "%0, %1 \n" + " .set pop \n" + : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) + : "ir" (1UL << bit) + : __LLSC_CLOBBER); + } while (unlikely(!temp)); } /* @@ -232,15 +249,15 @@ static inline void change_bit(unsigned long nr, volatile unsigned long *addr) static inline int test_and_set_bit(unsigned long nr, volatile unsigned long *addr) { + unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); int bit = nr & SZLONG_MASK; - unsigned long res; + unsigned long res, temp; smp_mb__before_llsc(); - if (kernel_uses_llsc && R10000_LLSC_WAR) { - unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG); - unsigned long temp; - + if (!kernel_uses_llsc) { + res = __mips_test_and_set_bit(nr, addr); + } else if (R10000_LLSC_WAR) { __asm__ __volatile__( " .set push \n" " .set arch=r4000 \n" @@ -253,10 +270,7 @@ static inline int test_and_set_bit(unsigned long nr, : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) : "r" (1UL << bit) : __LLSC_CLOBBER); - } else if (kernel_uses_llsc) { - unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG); - unsigned long temp; - + } else { loongson_llsc_mb(); do { __asm__ __volatile__( @@ -272,8 +286,7 @@ static inline int test_and_set_bit(unsigned long nr, } while (unlikely(!res)); res = temp & (1UL << bit); - } else - res = __mips_test_and_set_bit(nr, addr); + } smp_llsc_mb(); @@ -291,13 +304,13 @@ static inline int test_and_set_bit(unsigned long nr, static inline int test_and_set_bit_lock(unsigned long nr, volatile unsigned long *addr) { + unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); int bit = nr & SZLONG_MASK; - unsigned long res; - - if (kernel_uses_llsc && R10000_LLSC_WAR) { - unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG); - unsigned long temp; + unsigned long res, temp; + if (!kernel_uses_llsc) { + res = __mips_test_and_set_bit_lock(nr, addr); + } else if (R10000_LLSC_WAR) { __asm__ __volatile__( " .set push \n" " .set arch=r4000 \n" @@ -310,11 +323,7 @@ static inline int test_and_set_bit_lock(unsigned long nr, : "=&r" (temp), "+m" (*m), "=&r" (res) : "r" (1UL << bit) : __LLSC_CLOBBER); - } else if (kernel_uses_llsc) { - unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG); - unsigned long temp; - - loongson_llsc_mb(); + } else { do { __asm__ __volatile__( " .set push \n" @@ -329,8 +338,7 @@ static inline int test_and_set_bit_lock(unsigned long nr, } while (unlikely(!res)); res = temp & (1UL << bit); - } else - res = __mips_test_and_set_bit_lock(nr, addr); + } smp_llsc_mb(); @@ -347,15 +355,15 @@ static inline int test_and_set_bit_lock(unsigned long nr, static inline int test_and_clear_bit(unsigned long nr, volatile unsigned long *addr) { + unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); int bit = nr & SZLONG_MASK; - unsigned long res; + unsigned long res, temp; smp_mb__before_llsc(); - if (kernel_uses_llsc && R10000_LLSC_WAR) { - unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG); - unsigned long temp; - + if (!kernel_uses_llsc) { + res = __mips_test_and_clear_bit(nr, addr); + } else if (R10000_LLSC_WAR) { __asm__ __volatile__( " .set push \n" " .set arch=r4000 \n" @@ -370,10 +378,7 @@ static inline int test_and_clear_bit(unsigned long nr, : "r" (1UL << bit) : __LLSC_CLOBBER); #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) - } else if (kernel_uses_llsc && __builtin_constant_p(nr)) { - unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG); - unsigned long temp; - + } else if (__builtin_constant_p(nr)) { loongson_llsc_mb(); do { __asm__ __volatile__( @@ -386,10 +391,7 @@ static inline int test_and_clear_bit(unsigned long nr, : __LLSC_CLOBBER); } while (unlikely(!temp)); #endif - } else if (kernel_uses_llsc) { - unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG); - unsigned long temp; - + } else { loongson_llsc_mb(); do { __asm__ __volatile__( @@ -406,8 +408,7 @@ static inline int test_and_clear_bit(unsigned long nr, } while (unlikely(!res)); res = temp & (1UL << bit); - } else - res = __mips_test_and_clear_bit(nr, addr); + } smp_llsc_mb(); @@ -425,15 +426,15 @@ static inline int test_and_clear_bit(unsigned long nr, static inline int test_and_change_bit(unsigned long nr, volatile unsigned long *addr) { + unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); int bit = nr & SZLONG_MASK; - unsigned long res; + unsigned long res, temp; smp_mb__before_llsc(); - if (kernel_uses_llsc && R10000_LLSC_WAR) { - unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG); - unsigned long temp; - + if (!kernel_uses_llsc) { + res = __mips_test_and_change_bit(nr, addr); + } else if (R10000_LLSC_WAR) { __asm__ __volatile__( " .set push \n" " .set arch=r4000 \n" @@ -446,10 +447,7 @@ static inline int test_and_change_bit(unsigned long nr, : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) : "r" (1UL << bit) : __LLSC_CLOBBER); - } else if (kernel_uses_llsc) { - unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG); - unsigned long temp; - + } else { loongson_llsc_mb(); do { __asm__ __volatile__( @@ -465,8 +463,7 @@ static inline int test_and_change_bit(unsigned long nr, } while (unlikely(!res)); res = temp & (1UL << bit); - } else - res = __mips_test_and_change_bit(nr, addr); + } smp_llsc_mb(); From patchwork Mon Sep 30 23:08:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167779 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F6C0912 for ; Mon, 30 Sep 2019 23:10:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E0D492081B for ; Mon, 30 Sep 2019 23:10:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="K5sGSiuF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731781AbfI3XKF (ORCPT ); Mon, 30 Sep 2019 19:10:05 -0400 Received: from mail-eopbgr820094.outbound.protection.outlook.com ([40.107.82.94]:14848 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732602AbfI3XIx (ORCPT ); Mon, 30 Sep 2019 19:08:53 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VjE1sS7cZI4JqjaX2vfR+Hkj7pZ4y1eOmRBDmwZ+/YvZUZJw/UcEHhJOqioAMJkiZwc+CHGfTCzqoRSwgzzZDvS4pNwBRiSDUADDx4Xt6jA8Yf1IYyNpXhVsI0bXreZD8Y5NmIJJKL36iepaUXmJEiUWVsP/NSMz3cme2/yQ147uV8y6VTjrX1XkdhFGLkkkUR/UFSN4wesH4rXA4JLvRKT4rTViUjbJvtvR0z3l6Y2xwwNd+cwpBzyBE5o1Uep3AvpD1zrxKdYj0/MZFlXXe0FmvauGIxYJTRmbRd0ptpZ7HnrSGC+BaB4mL2S3aSyMu5SNtWpQKKwH8qLCi6/rEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Z8h4x6IZHVrHGXCy+MhCVSH+owuj567idbwxbt7smwE=; b=WSfyA23i+yTuzlKbDFxJCwlWzb2JQttpZ//yeAt4GiDE9jRIL4zQoQuoQNkyYUfo10fPokfJBtURwBHvuHOHSQ2MKKzli4vbR3OcgUmM06riLOSdTUf5KF0ZynzRbKH/JO/yzHH/1PKpMvKgsFIy+qzaZeYBnvPetZ6d9QS48uGur6iZ7tJJDAWIBjI+zfaeQ9NVckqgUnmrob1CDY6oSJ6M5QpEptL1XmyR+Nvn3hbie2erh1ItzrI0lRzYsdDxkvz2iOzFjqj6+7OVX8tidHUVP/Co1ywcH6iXX6tgm4GfZNCCBq68aA9n2mLTwZAGm/oSly8MJSqlxh24xPdA8g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Z8h4x6IZHVrHGXCy+MhCVSH+owuj567idbwxbt7smwE=; b=K5sGSiuFgV+/2zXkF52DVuo+58J6ry9JNLAXk7a1eGTXsNdu33zvW6JUk97GMpmwJQk+cUL9Fb52keh1Sg73uW0LkG8zr6NP+5NeBJqJm6xV5fVjrKLyadFh9LV2yO3hNilYDViKmXvNmSttQlFRbYB5p0qacVHEsudJv985HZQ= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:29 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:29 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 18/37] MIPS: bitops: Only use ins for bit 16 or higher Thread-Topic: [PATCH 18/37] MIPS: bitops: Only use ins for bit 16 or higher Thread-Index: AQHVd+P52h8wulv6i0O0I9TbdXtkog== Date: Mon, 30 Sep 2019 23:08:29 +0000 Message-ID: <20190930230806.2940505-19-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 061f7950-b6b5-4f63-f002-08d745fb1b73 x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6790; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(376002)(136003)(366004)(189003)(199004)(14454004)(508600001)(256004)(6512007)(81166006)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 92ebSJFmhjWC3VgI5seaEqiaqHssWTHFtaxVlz1ezRxDWwVZDbZRl/VnivWAhaZbJfrLSJebNRgqvh9y6KjX19tk4YYZTqHGQDq/CpzAxOCjVLJM+1mUuSKxRt272wO66aG0s3HJq80t67FRvIDbuCPH/X+oq72HYPhke8SZ+rpCHy08FBXIYk/KWT3MigMMPx6u+gAMYObKD3T9raNtJommlzUlMGrSdPI/NLnquzV7HsS/pz0hb9m9VWv8VqaDPu1GrytWhYzdAoSXhs7IYOQ1dT8W5xI37swSHa1hKy1Tf8ZeV/fs8yNwj+hV2pQMnUfbVLGLkWZXSJlbK4c5OaTsm3e3AmuN5/85PifLcMsWrGh7lyN5IrShTZPra4YQ5hxbtnWJKp3dqr6snV+lq6XsbaGUMeTSxmZCVXyCBmg= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 061f7950-b6b5-4f63-f002-08d745fb1b73 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:29.7734 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: a160e0JPoppPtidL8UdBaZPxnT2cwn81VM+A9tY5poHwFBFpcf2pHh7Jq3bvkZ5o3HJPCiAb6zJeMMbkrlIJIA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org set_bit() can set bits 0-15 using an ori instruction, rather than loading the value -1 into a register & then using an ins instruction. That is, rather than the following: li t0, -1 ll t1, 0(t2) ins t1, t0, 4, 1 sc t1, 0(t2) We can have the simpler: ll t1, 0(t2) ori t1, t1, 0x10 sc t1, 0(t2) The or path already allows immediates to be used, so simply restricting the ins path to bits that don't fit in immediates is sufficient to take advantage of this. Signed-off-by: Paul Burton --- arch/mips/include/asm/bitops.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/mips/include/asm/bitops.h b/arch/mips/include/asm/bitops.h index d3f3f37ca0b1..3ea4f172ac08 100644 --- a/arch/mips/include/asm/bitops.h +++ b/arch/mips/include/asm/bitops.h @@ -77,7 +77,7 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) } #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) - if (__builtin_constant_p(bit)) { + if (__builtin_constant_p(bit) && (bit >= 16)) { loongson_llsc_mb(); do { __asm__ __volatile__( From patchwork Mon Sep 30 23:08:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167741 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 69FFC912 for ; Mon, 30 Sep 2019 23:08:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3F1F82168B for ; Mon, 30 Sep 2019 23:08:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="GUc17W6/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732619AbfI3XIo (ORCPT ); Mon, 30 Sep 2019 19:08:44 -0400 Received: from mail-eopbgr690119.outbound.protection.outlook.com ([40.107.69.119]:48448 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732613AbfI3XIn (ORCPT ); Mon, 30 Sep 2019 19:08:43 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hS9eys8wfHo6jTIju2NX8oBMShKpAbswepAE2e2yVC9YK94mOh6b76SG+Kbem18RGAh1WaE2Qo52dUqZt/sp7huXPWierIPoYrdV9soL8Pz5JaB3UHAfuFN+/WzDG1W2J6XYfcEoj/nfihiMx6BN1JbsDw22FughdwjllRzGU/CvLEnRs0ktcU+6q+fJaqCoZLaOLixcYta+3MiGc+RCv73DtU+fIcVtlof7LdkhzVcm/wiyu0KRv7+9CCKptS6Pq6bvmUxe6DqwdnhA0SMRibavWNZQ8LgcTFT8Al0FBJyC0rz++psRkVwvfRMXEeSa1WUm4CkVr64MCBP4tqBwlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OSyB7GHykUnfUEZB4BGbdX9bewQ3q5pARr130wTJK3g=; b=JgDTy5dw4mOysjif7XhAICgzffXiTTqixHeFBk78WF+CkUcuCpk7V/psscj/BYfWXDQ0tfx3wuMmgmAoeA96bd79ozHOBc4J8xpSp9fcA5VVPW+mJzwdsU01DZmH3ySlX3oT4R3JCBA9RWigTNCaV3Xf+JARy4lEyFigsYHZJw9wLXX9M799VoQ7fvkYGGZR35f9UmECTYf9V7weiyFzLYLkGQr4sHra7wsW9XYKsPjHJscPWgbyU5Z3WpyUAA8GAz46iTj1JfmkDesCxVZpF5wdNvCQ1c4UzQP/EJHLnH+2CimApIowFSjp+pwLDBSne9inZk1xb9fqUNG/DGkPjQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OSyB7GHykUnfUEZB4BGbdX9bewQ3q5pARr130wTJK3g=; b=GUc17W6/lInA2K1VXm/+gsUzHcKssXXqqFY9vGhlKp/DjmlRkIN1cE6caYMgXKoQB/tgcyQYuATfQlgaxSfdQK3t/2fnorldkPFB6SydlCoPJJrW8DWLezeG9ZxnMojuSbVdf8j1QjKF07IG2oF80W/FlQtJomXIrGUK/DdgrxY= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:30 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:30 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 19/37] MIPS: bitops: Use MIPS_ISA_REV, not #ifdefs Thread-Topic: [PATCH 19/37] MIPS: bitops: Use MIPS_ISA_REV, not #ifdefs Thread-Index: AQHVd+P5kxB47wj2YEm+Ca+Rab8Jgg== Date: Mon, 30 Sep 2019 23:08:30 +0000 Message-ID: <20190930230806.2940505-20-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d8ec46ed-5859-4dac-e204-08d745fb1bf5 x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2657; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(376002)(136003)(366004)(189003)(199004)(14454004)(508600001)(256004)(6512007)(81166006)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: uO55gWxhUXsfY9doV59OUEFYMG0Qdu5gbrfgx6qmfb1LuHJUen1B2ptnc14tCBPf2juy8/PHy0Mui6c0qBqEkJ9wl4GxQU9bswygVrN0s6JclodD2GHB4FbvlAsPsVEkBorS2FdJ/ebvwdOgU6wYTsrLYQRaMgfNZYq0pqRe6PTVthFGb8OkzVoeQ5ZSIN/5JFYPQTeL+LLY3CxTHvcfC+qqEDqyoJ6T+YHDGZVZZmtO/0YlHSyEMoaDL1t+EDZ+/jZPA+3KIlQZgkxdB4KgvdhfEwPwFNZoFnQ0ZlWBvrfbNCHCtVkKeU9qZd5cgeId0Mz+w9gHEFFudngo0jhvh/yOLcD5KZlZf88TF5R5pvC3CXeMbg8/2YsE/+KGl8Kt/JDssPdeaTyW6Qjck6106v/9kfirFp8xbOVTzSM/L3g= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: d8ec46ed-5859-4dac-e204-08d745fb1bf5 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:30.6650 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: qiVgGIQEu+SgVj4buqM1nTiaYHEcMn8t3KZ7LCq2N0KlUz+IHZhuprsF2BwPUPsvCe/elfm6vHVzFJphSdsuow== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Rather than #ifdef on CONFIG_CPU_* to determine whether the ins instruction is supported we can simply check MIPS_ISA_REV to discover whether we're targeting MIPSr2 or higher. Do so in order to clean up the code. Signed-off-by: Paul Burton --- arch/mips/include/asm/bitops.h | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/arch/mips/include/asm/bitops.h b/arch/mips/include/asm/bitops.h index 3ea4f172ac08..b8785bdf3507 100644 --- a/arch/mips/include/asm/bitops.h +++ b/arch/mips/include/asm/bitops.h @@ -19,6 +19,7 @@ #include /* sigh ... */ #include #include +#include #include #include #include @@ -76,8 +77,7 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) return; } -#if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) - if (__builtin_constant_p(bit) && (bit >= 16)) { + if ((MIPS_ISA_REV >= 2) && __builtin_constant_p(bit) && (bit >= 16)) { loongson_llsc_mb(); do { __asm__ __volatile__( @@ -90,7 +90,6 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) } while (unlikely(!temp)); return; } -#endif /* CONFIG_CPU_MIPSR2 || CONFIG_CPU_MIPSR6 */ loongson_llsc_mb(); do { @@ -143,8 +142,7 @@ static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) return; } -#if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) - if (__builtin_constant_p(bit)) { + if ((MIPS_ISA_REV >= 2) && __builtin_constant_p(bit)) { loongson_llsc_mb(); do { __asm__ __volatile__( @@ -157,7 +155,6 @@ static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) } while (unlikely(!temp)); return; } -#endif /* CONFIG_CPU_MIPSR2 || CONFIG_CPU_MIPSR6 */ loongson_llsc_mb(); do { @@ -377,8 +374,7 @@ static inline int test_and_clear_bit(unsigned long nr, : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) : "r" (1UL << bit) : __LLSC_CLOBBER); -#if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) - } else if (__builtin_constant_p(nr)) { + } else if ((MIPS_ISA_REV >= 2) && __builtin_constant_p(nr)) { loongson_llsc_mb(); do { __asm__ __volatile__( @@ -390,7 +386,6 @@ static inline int test_and_clear_bit(unsigned long nr, : "ir" (bit) : __LLSC_CLOBBER); } while (unlikely(!temp)); -#endif } else { loongson_llsc_mb(); do { From patchwork Mon Sep 30 23:08:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167783 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF153912 for ; Mon, 30 Sep 2019 23:10:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C35452086A for ; Mon, 30 Sep 2019 23:10:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="ghseb7DC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732530AbfI3XKN (ORCPT ); Mon, 30 Sep 2019 19:10:13 -0400 Received: from mail-eopbgr690119.outbound.protection.outlook.com ([40.107.69.119]:48448 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732442AbfI3XIo (ORCPT ); Mon, 30 Sep 2019 19:08:44 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jKJESwtrBItD+o9SsVNjiGVRYeYzIYvtoYshrcJ96js7tzvIxTOLj2j3PPA9TdIeuIvdI8fgBBze4co/Tz8e0i+jjkAVN0aYAqKsGM63PM9wYtPY0neWdlst2OR2b/Z5HxfgwHkHAj/G52fKoXX+1o01zNZUKPtCMd6a+9jy7quES9QMMl2Lu3wEtzVIXm7BE05nLikMiIkJLfbdXM6uP13LWM0bIj21GDDPVENi2lc9UeWM/nqQF86+gbPQGRk9Bpbu9aqurueBMk+OUljb5UbUiWmHMiD7sAV/VjTXMKhqfo/PqrYnhSGfgZJTgmOCT0+jouK1G6pU9giQnDlh+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0s52wFl4qopTrNonQGmwvzdL3cvCZuaf5g3wPIwJ0j0=; b=QOkBQbPpeyc79BPmlWAuT4vRZVQRh8OOS3BqHLuPo+LLnsDkUMFNVhh4gu51KoWRMOX4b5YyontWeTFNJolWeucG54vCp2UXL0d/F+Qk+I1n0CMcxKd4j0caOsjzTr+aj5EmBliac9OI0WJuidqAOHtpQToCYiLtADyDa1jG+PICqZbxaTXlFqi5KNnF2SrS0MJATzHuALLtX1lRaiotUMNaL4CngzJ6gk5u9DePmhFr4d24NsQ/TNayGWFqh7X4+oiAu4w2F2NUH1C2HgTsiiugL4QYqiGSVK/jeH4yU2rUmlIiiBxlAjbbZibxMdJVnyWJyOZf79rbuUMcBQlEZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0s52wFl4qopTrNonQGmwvzdL3cvCZuaf5g3wPIwJ0j0=; b=ghseb7DClReMwrQkyGrOOVwRbGzoDRNcGOmJkgQ7m84a0HcIAu51N8QsRPumpV+JSWCkn4y37zSNsLqduxezmkAdmLvdhEGzvpgB/QQPCiHashJQ82VSvzTio2O/78tt5xsMqru4dsjxklVHLc/F9Lcrm/3YngG/f0FsYXMuEJ4= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:31 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:31 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 20/37] MIPS: bitops: ins start position is always an immediate Thread-Topic: [PATCH 20/37] MIPS: bitops: ins start position is always an immediate Thread-Index: AQHVd+P6EZDR/gPpYUyjQdLtXj7q0A== Date: Mon, 30 Sep 2019 23:08:31 +0000 Message-ID: <20190930230806.2940505-21-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e925c1fd-dd62-41bc-0392-08d745fb1c7d x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2887; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(979002)(346002)(376002)(136003)(366004)(189003)(199004)(14454004)(508600001)(256004)(6512007)(81166006)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(186003)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002)(14773001)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: fOeJyq1AqjBmeRQYUnQM0Hjp7gwZEsDLhOvVN/B1TnPRhhjKALHxJdh7U9VMOURYcqdHlntVdJJva15i9siAsfnPbIx2aiWKf+GcXbW4+FcU0yfyf0dbYgB2qJcGWhjw6ARRTUAZ2AHvgoqXTPs18Vnp0RLDl+oQ368pdhB+IxPYiYeCERPaOYW0pQqmftJPQGLEmaLFEJIcoWPvrzOyYNKsoV+22KTHzYzmJe62B479+vOMFrQUXGNLLOuWNBuhqFHMHZBWUFJNeFSQH97g1dT/qrC0oAyu5phax3ZSQJa2v2A7J2cl9BQjK9KnwJ1sUi34GYcJsKrr2RsgX5J6fN2HneIaUgvPMJImulg101rEDBWwGDFRWi3DV/3Gis8uCDJD/uWAx6txduGB2/2FkOHU3sZjuFU0WllihaQ4QeM= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: e925c1fd-dd62-41bc-0392-08d745fb1c7d X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:31.6295 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: q7gmbtDLRwgx6tHV8LYT9ndXM0TgZhfI1n/vkLYxW4POHzDAkUwa42rRP578duq5420AiDQRVyezDrYQlR1ZsQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org The start position for an ins instruction is always encoded as an immediate, so allowing registers to be used by the inline asm makes no sense. It should never happen anyway since a bit index should always be small enough to be treated as an immediate, but remove the nonsensical "r" for sanity. Signed-off-by: Paul Burton --- arch/mips/include/asm/bitops.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/mips/include/asm/bitops.h b/arch/mips/include/asm/bitops.h index b8785bdf3507..83fd1f1c3ab4 100644 --- a/arch/mips/include/asm/bitops.h +++ b/arch/mips/include/asm/bitops.h @@ -85,7 +85,7 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) " " __INS "%0, %3, %2, 1 \n" " " __SC "%0, %1 \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "ir" (bit), "r" (~0) + : "i" (bit), "r" (~0) : __LLSC_CLOBBER); } while (unlikely(!temp)); return; @@ -150,7 +150,7 @@ static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) " " __INS "%0, $0, %2, 1 \n" " " __SC "%0, %1 \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "ir" (bit) + : "i" (bit) : __LLSC_CLOBBER); } while (unlikely(!temp)); return; @@ -383,7 +383,7 @@ static inline int test_and_clear_bit(unsigned long nr, " " __INS "%0, $0, %3, 1 \n" " " __SC "%0, %1 \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "ir" (bit) + : "i" (bit) : __LLSC_CLOBBER); } while (unlikely(!temp)); } else { From patchwork Mon Sep 30 23:08:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167781 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 54A58912 for ; Mon, 30 Sep 2019 23:10:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1EDC02086A for ; Mon, 30 Sep 2019 23:10:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="h9kK2ywU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732644AbfI3XIu (ORCPT ); Mon, 30 Sep 2019 19:08:50 -0400 Received: from mail-eopbgr690119.outbound.protection.outlook.com ([40.107.69.119]:48448 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732626AbfI3XIs (ORCPT ); Mon, 30 Sep 2019 19:08:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LFy9eP0i7wgXBbC2Cz1vS1D7JH4CTXILLGc9j+t9lzOTB4hF3A19MNZsVfGmNEu/3Z58se+Rk6t56GvrbQ8P04Rg96nd9NcEY0NAiDKMKYLd0nk2Y+l+Fj2io2IlbZ3OI+hQ9y2Fx0SiXz6ybvJZgtSfpl2ckxzr6Jl479BQRO/YVLbh8OTTbwwM/lHARuyu3nFgPckgtbhFCgrEvUtEkIqe6N6Lmd5wsdkgGNW49p9f8d5DtJaVm927U/dSASv7ZeKlC96ENhjEHPDbjRvYc+XG2r8r5ZrRagojDGE08p1uLWc6Q/NkQfzU9Wx55lSg7fP8U9HDVjsjCnc1p5UO3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZfAVvGvI2aPckslAY0N2YIANjNjzPYFO+OauvzKZOUs=; b=OtzmAI4cdl3jMy08PQaExOZ4fZk1zeLR8Z+VV94VZNqGfqgJxVF0p0DSInO+/z0mbdBlM1ZbXHX9JvGfr1ksrFpG4BJ+sxuXQ6Fay3tyMgI5RU0gQCq2SyLn6JCWE/qfAstB91K2OBfOPmUbb70kgzhJ4uw4qTNqpqfDvt4pg1znwyLTZYX7HgWh2e4MzNhFMOow7ZmxMmSRRpldj6hvjVRD8U2EwPzypNOcEC5kpXF3Xvu6tltPauypJHRFVdi//4sF7TRNsKisBNOKlOWmFio9kOLHVhH3thHpaFRH1jRIASRRad79Ifbo7bpfKvftN1QtsUZz6OelPG8fxh1jFA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZfAVvGvI2aPckslAY0N2YIANjNjzPYFO+OauvzKZOUs=; b=h9kK2ywUUnUVXHfc5B8My/08ZQlB7EjUVbfdxvaDmkhguypbuVGLMsP4eErqVZVvi8BGjHq6pEt4prmNXAkeXo2baRKhKkwJrbjXO9bsf1HQQUt5CHCBs6HEaTUMNgNIYmm20kkXt6T87INMWs3N4pFONzrVgMeephlIpYCghjM= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:32 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:32 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 21/37] MIPS: bitops: Implement test_and_set_bit() in terms of _lock variant Thread-Topic: [PATCH 21/37] MIPS: bitops: Implement test_and_set_bit() in terms of _lock variant Thread-Index: AQHVd+P6iWZRVNZFTkSLRs37dgW89Q== Date: Mon, 30 Sep 2019 23:08:32 +0000 Message-ID: <20190930230806.2940505-22-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 63001d44-d434-440c-5d12-08d745fb1d0e x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4714; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(376002)(136003)(366004)(189003)(199004)(14454004)(508600001)(256004)(6512007)(81166006)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: AcHyZX3BwJe9LWnyA5nQjylcFTDS4oMYnEeFJWnGXliGqVYlZ5zyyVUglJpxLStGv+Y3FdPn8NPbSjWYHEquqn12l21YKN34tk7PjSH18Jrpno7EKT+jGuj+VUdpPs8SXEb79LriRsbtqhMe84F4xX79FwiI54dG6im4j3UsxIfeVbGNkaFgz15p3WZbYccXTSmqYnrsQTp1CrsaJsvZTphU7Elhi6/Ip0ik96Ji5ZwqOBHuSyKSPXgL0SmombDSmtEo5fvf34cxLeZ2nVqAXJBwQJBfp2sKqki5wtsHV2F3BNKeqZCGVsSK3UFMNzDSTrY499w2GCw5GYkqkEwyOzGj00XmpQnVWDJSea/lbvn77KeC3fMsgGcnWE9UaqkDKm42+uTUAqqMgUnvr8h+xRd8lN4kMyKcVPYu2s6nkM0= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 63001d44-d434-440c-5d12-08d745fb1d0e X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:32.4602 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: VRZb82qP8cNWXFM/sH3OL743g0Gmdo1aB1Yr6dCdTWWQQyLgvU6VNLgRg526m+KEQaPz66LHLFYTB6jz+gTSnQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org The only difference between test_and_set_bit() & test_and_set_bit_lock() is memory ordering barrier semantics - the former provides a full barrier whilst the latter only provides acquire semantics. We can therefore implement test_and_set_bit() in terms of test_and_set_bit_lock() with the addition of the extra memory barrier. Do this in order to avoid duplicating logic. Signed-off-by: Paul Burton --- arch/mips/include/asm/bitops.h | 66 +++++++--------------------------- arch/mips/lib/bitops.c | 26 -------------- 2 files changed, 13 insertions(+), 79 deletions(-) diff --git a/arch/mips/include/asm/bitops.h b/arch/mips/include/asm/bitops.h index 83fd1f1c3ab4..34d6fe3f18d0 100644 --- a/arch/mips/include/asm/bitops.h +++ b/arch/mips/include/asm/bitops.h @@ -31,8 +31,6 @@ void __mips_set_bit(unsigned long nr, volatile unsigned long *addr); void __mips_clear_bit(unsigned long nr, volatile unsigned long *addr); void __mips_change_bit(unsigned long nr, volatile unsigned long *addr); -int __mips_test_and_set_bit(unsigned long nr, - volatile unsigned long *addr); int __mips_test_and_set_bit_lock(unsigned long nr, volatile unsigned long *addr); int __mips_test_and_clear_bit(unsigned long nr, @@ -236,24 +234,22 @@ static inline void change_bit(unsigned long nr, volatile unsigned long *addr) } /* - * test_and_set_bit - Set a bit and return its old value + * test_and_set_bit_lock - Set a bit and return its old value * @nr: Bit to set * @addr: Address to count from * - * This operation is atomic and cannot be reordered. - * It also implies a memory barrier. + * This operation is atomic and implies acquire ordering semantics + * after the memory operation. */ -static inline int test_and_set_bit(unsigned long nr, +static inline int test_and_set_bit_lock(unsigned long nr, volatile unsigned long *addr) { unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); int bit = nr & SZLONG_MASK; unsigned long res, temp; - smp_mb__before_llsc(); - if (!kernel_uses_llsc) { - res = __mips_test_and_set_bit(nr, addr); + res = __mips_test_and_set_bit_lock(nr, addr); } else if (R10000_LLSC_WAR) { __asm__ __volatile__( " .set push \n" @@ -264,7 +260,7 @@ static inline int test_and_set_bit(unsigned long nr, " beqzl %2, 1b \n" " and %2, %0, %3 \n" " .set pop \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) + : "=&r" (temp), "+m" (*m), "=&r" (res) : "r" (1UL << bit) : __LLSC_CLOBBER); } else { @@ -291,56 +287,20 @@ static inline int test_and_set_bit(unsigned long nr, } /* - * test_and_set_bit_lock - Set a bit and return its old value + * test_and_set_bit - Set a bit and return its old value * @nr: Bit to set * @addr: Address to count from * - * This operation is atomic and implies acquire ordering semantics - * after the memory operation. + * This operation is atomic and cannot be reordered. + * It also implies a memory barrier. */ -static inline int test_and_set_bit_lock(unsigned long nr, +static inline int test_and_set_bit(unsigned long nr, volatile unsigned long *addr) { - unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); - int bit = nr & SZLONG_MASK; - unsigned long res, temp; - - if (!kernel_uses_llsc) { - res = __mips_test_and_set_bit_lock(nr, addr); - } else if (R10000_LLSC_WAR) { - __asm__ __volatile__( - " .set push \n" - " .set arch=r4000 \n" - "1: " __LL "%0, %1 # test_and_set_bit \n" - " or %2, %0, %3 \n" - " " __SC "%2, %1 \n" - " beqzl %2, 1b \n" - " and %2, %0, %3 \n" - " .set pop \n" - : "=&r" (temp), "+m" (*m), "=&r" (res) - : "r" (1UL << bit) - : __LLSC_CLOBBER); - } else { - do { - __asm__ __volatile__( - " .set push \n" - " .set "MIPS_ISA_ARCH_LEVEL" \n" - " " __LL "%0, %1 # test_and_set_bit \n" - " or %2, %0, %3 \n" - " " __SC "%2, %1 \n" - " .set pop \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "r" (1UL << bit) - : __LLSC_CLOBBER); - } while (unlikely(!res)); - - res = temp & (1UL << bit); - } - - smp_llsc_mb(); - - return res != 0; + smp_mb__before_llsc(); + return test_and_set_bit_lock(nr, addr); } + /* * test_and_clear_bit - Clear a bit and return its old value * @nr: Bit to clear diff --git a/arch/mips/lib/bitops.c b/arch/mips/lib/bitops.c index 3b2a1e78a543..fba402c0879d 100644 --- a/arch/mips/lib/bitops.c +++ b/arch/mips/lib/bitops.c @@ -77,32 +77,6 @@ void __mips_change_bit(unsigned long nr, volatile unsigned long *addr) EXPORT_SYMBOL(__mips_change_bit); -/** - * __mips_test_and_set_bit - Set a bit and return its old value. This is - * called by test_and_set_bit() if it cannot find a faster solution. - * @nr: Bit to set - * @addr: Address to count from - */ -int __mips_test_and_set_bit(unsigned long nr, - volatile unsigned long *addr) -{ - unsigned long *a = (unsigned long *)addr; - unsigned bit = nr & SZLONG_MASK; - unsigned long mask; - unsigned long flags; - int res; - - a += nr >> SZLONG_LOG; - mask = 1UL << bit; - raw_local_irq_save(flags); - res = (mask & *a) != 0; - *a |= mask; - raw_local_irq_restore(flags); - return res; -} -EXPORT_SYMBOL(__mips_test_and_set_bit); - - /** * __mips_test_and_set_bit_lock - Set a bit and return its old value. This is * called by test_and_set_bit_lock() if it cannot find a faster solution. From patchwork Mon Sep 30 23:08:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167745 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 881B614DB for ; Mon, 30 Sep 2019 23:08:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5BFEC2168B for ; Mon, 30 Sep 2019 23:08:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="MCuzWv06" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732653AbfI3XIv (ORCPT ); Mon, 30 Sep 2019 19:08:51 -0400 Received: from mail-eopbgr690119.outbound.protection.outlook.com ([40.107.69.119]:48448 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732643AbfI3XIu (ORCPT ); Mon, 30 Sep 2019 19:08:50 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jhtG8gy19bL4ff1ISG2Yteka6SuAo0m7vkw0jSycE0uDtUEVcGRH5SvckBqkJ2mS2zw56deDoVp+DA6pdWcqHmpQOzZpZzhHH8EVFo9ubiacZ2BmNdl5SsQBJo+kvp6YOUjRmOZcvtznxwRA0TuPUPuyfXdxCwMCLY4+p4kwxkDPddM1lW/xNjBXmk9uX8VzTApCqkOu3gYbPuNBQt5MLeVI78AFNqABx0UmOqUi/+tYLvhj65MFx6LiB+UMaqugX2NZqCG5e0qzgfHNzpKs8T4D7USX5Bh7kI8zgrF0OLgbtEBeKAV887dP3P2qD70qysEm789RBkVuOFNZhT2rNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qgsxAQtwHf3lBMshWcs6/1kAPwHEPvTRJQk3M0eQ9aQ=; b=I1hUrx7SIOjp4qLWfcG2LXfl2QqjHv0x/CxOIIZOu8xAf35AkLfIr48WCoM0ngvRV/Y9MV3/tN9tAm+aNeaJwCj+OVibUwFhgYkqQUtuFGcmhsWi94ibf0joShAfobgpX+2tBz1LVPigPF9AIMdMWCnmuZwo61NLMDRfzJNKiCETF5X6SJXWlMkKV1VzESTxHBoQE3MwICkGWi/RK7vJ8T6dFv5ogDk2by4uuW0PuJP22WKA9EZnXuFuu8L0z9DZbwzVaoQh5BqV2pYxNz8zC99mPLB0V7S07khnlK1GdN+Zk3hVYOiPu+Oh/y5lUnBZVtr8ESV+/NRPDiIVLGKH8g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qgsxAQtwHf3lBMshWcs6/1kAPwHEPvTRJQk3M0eQ9aQ=; b=MCuzWv06nVLwkZQbZA7iRc4XvxyCumdcV++KgTwikhD6d/yBNrH/22RvaP3HT90wh+hWEtPxXXtpZ7mc47y4+2D2nz1Np04xbFQhx18QHLlWFzLP+3aIj1MJH3u4Kls2fs7PkPY5F0i1SPQYgnt9pEdlwOmOFkfdydrxSfJ/z3M= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:33 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:33 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 22/37] MIPS: bitops: Allow immediates in test_and_{set,clear,change}_bit Thread-Topic: [PATCH 22/37] MIPS: bitops: Allow immediates in test_and_{set,clear,change}_bit Thread-Index: AQHVd+P7r/zRTB56Uk+oKVHxefve8w== Date: Mon, 30 Sep 2019 23:08:33 +0000 Message-ID: <20190930230806.2940505-23-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 42737e41-2df7-4b1a-c034-08d745fb1d89 x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3173; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39850400004)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(14454004)(256004)(6512007)(81166006)(316002)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(478600001)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002)(14773001)(142933001);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: yQa2z/5JeLAvGCl27NAu+IFCwhMVz8rQe8v36+UVeN8vOv07PWtQVW/FS8gZfSrB2fYqEoP/XoxcxvTNPo8uoSzrC215h3v6WxeoJU2ewx+xtaB04EnrT0BAVQ3/H6na/9TxDi+luOVkqjFUMo+gDiuxfev2QPSMDH5e0lo+JJjNb+OKN4e8UoSwCVK/R/YlNubkDoSGAkb00NdSFwckKDp/S6Oltl1KiyX6A2YzZmywM84yYV2kwAG0THTWuxugyZ3zFgOEUS8lmtmDOF6siOHZQcN6t6QJ1s5ENULZGqvf/yoC0HwhJ1WxhZ1mEIEZAmcQPVg/wlSfSrlvJmAX7QtTC5Rg4v9OYYs9ACm1oEFUOy8NieFUWrZ46VE+LQOGj4K8ETbQB2WDYn6SIqJFzcomB2wd9+RY979Ows5Mcm0= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 42737e41-2df7-4b1a-c034-08d745fb1d89 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:33.2538 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: kipr0YbbFfFrxVM3YuijGt4gcfSX4Mfajw5nm5hvCY0A5AgpdxcCW4FZWi1TXgl0oedsRb6iZDf57U4WfJVQjg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org The logical operations or & xor used in the test_and_set_bit_lock(), test_and_clear_bit() & test_and_change_bit() functions currently force the value 1< --- arch/mips/include/asm/bitops.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/mips/include/asm/bitops.h b/arch/mips/include/asm/bitops.h index 34d6fe3f18d0..0b0ce0adce8f 100644 --- a/arch/mips/include/asm/bitops.h +++ b/arch/mips/include/asm/bitops.h @@ -261,7 +261,7 @@ static inline int test_and_set_bit_lock(unsigned long nr, " and %2, %0, %3 \n" " .set pop \n" : "=&r" (temp), "+m" (*m), "=&r" (res) - : "r" (1UL << bit) + : "ir" (1UL << bit) : __LLSC_CLOBBER); } else { loongson_llsc_mb(); @@ -274,7 +274,7 @@ static inline int test_and_set_bit_lock(unsigned long nr, " " __SC "%2, %1 \n" " .set pop \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "r" (1UL << bit) + : "ir" (1UL << bit) : __LLSC_CLOBBER); } while (unlikely(!res)); @@ -332,7 +332,7 @@ static inline int test_and_clear_bit(unsigned long nr, " and %2, %0, %3 \n" " .set pop \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "r" (1UL << bit) + : "ir" (1UL << bit) : __LLSC_CLOBBER); } else if ((MIPS_ISA_REV >= 2) && __builtin_constant_p(nr)) { loongson_llsc_mb(); @@ -358,7 +358,7 @@ static inline int test_and_clear_bit(unsigned long nr, " " __SC "%2, %1 \n" " .set pop \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "r" (1UL << bit) + : "ir" (1UL << bit) : __LLSC_CLOBBER); } while (unlikely(!res)); @@ -400,7 +400,7 @@ static inline int test_and_change_bit(unsigned long nr, " and %2, %0, %3 \n" " .set pop \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "r" (1UL << bit) + : "ir" (1UL << bit) : __LLSC_CLOBBER); } else { loongson_llsc_mb(); @@ -413,7 +413,7 @@ static inline int test_and_change_bit(unsigned long nr, " " __SC "\t%2, %1 \n" " .set pop \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "r" (1UL << bit) + : "ir" (1UL << bit) : __LLSC_CLOBBER); } while (unlikely(!res)); From patchwork Mon Sep 30 23:08:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167747 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1231C912 for ; Mon, 30 Sep 2019 23:08:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D0B9D2086A for ; Mon, 30 Sep 2019 23:08:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="DM+8yivJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732662AbfI3XIw (ORCPT ); Mon, 30 Sep 2019 19:08:52 -0400 Received: from mail-eopbgr690119.outbound.protection.outlook.com ([40.107.69.119]:48448 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732650AbfI3XIv (ORCPT ); Mon, 30 Sep 2019 19:08:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LTZc1MLwcDB3OPOLZxrRQbQztHA6k2zklOLQKzXBjvX9sfmtQHRZBiZ51MT9UEevBlqwFicbBVH5hxtBTsTks1bEHT+oLViiuI6TRPR3Nuc+Nkx+39r9qwM+XCA+3ljHVtEAtFxHuFOyAEh0RE/+VUd8BDOlwR2bWTPK8ALFb93F3ku09chhaX/db8riKt3xJfEHW+yqHRQTgLTQQwFZ/ei2INEfDrziV0GIePnMjIVoEhVk/43hryy7wM/T/enM2JkNAsQE5SKknGry1pbiqPxTjhQKWS/2D2QbXWN4PKVrOXKbX+jf/UAJAQW7Dk+/KPi0IdNYZdbxDXOYatAbJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NKr1DgS/ZnHEXFw4XWbybZYH/AiQC2vw2bR6v+Hzmks=; b=NbqAkDZSbdZ2lt5yIuKQxZdaejtDQL5xh7WrTsxSUegcl5T6VCl3MVd+ZHSj7nMTdkG28MgdBpQOKHvOcABjfAVNez65g2ry/ihiL2wpu1ejQfQe/ylfKvphabwKBCEvKE7U0nrarEmY8eP+VkjNjHC7qTnwVWuXu0oWjpprNAbVtqKONQRtvDzk0hP/Z8LRbPgOu9V7ysF4LsnOA/nctexEksbyPp6P+X0wdy3/k2Ml/EXS3BMTut6Omgq0daOoQ7LVg/PZweFQ9C0VvX6Wb+JNuCg5obKWfjqSUKWycYQTHSnOIExXz87TCc4X1pvutJHg01f9jczCoOUdE7ZLWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NKr1DgS/ZnHEXFw4XWbybZYH/AiQC2vw2bR6v+Hzmks=; b=DM+8yivJFx/SuNTMEt1P9Rz5h00BHAcsY1gdEI8OoaP03GMG8gefpO3fO1Inh8U3IVCY7Dg3W7jxd9C4yCEJWGlB+Ubu/P9DCFM8qmYP6WAPu6m7kbIZ6flUg7Wt9YbOcu18GrB4hRs0ILWsA5uH75K2yIx9554gHhkQyWjp/Bo= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:34 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:34 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 23/37] MIPS: bitops: Use the BIT() macro Thread-Topic: [PATCH 23/37] MIPS: bitops: Use the BIT() macro Thread-Index: AQHVd+P7X5zAOzc0lEaViWRl0/7agA== Date: Mon, 30 Sep 2019 23:08:34 +0000 Message-ID: <20190930230806.2940505-24-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d8ee0c01-fa9e-469b-93fe-08d745fb1e07 x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1002; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39850400004)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(14454004)(256004)(6512007)(81166006)(316002)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(478600001)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: yd232fM1G/XgdBcgtDYCBIKVVSxFRRSP+1yWq/lDPkAI/Z/SXjtf9g5BcP/Q5G/zCadGsnvJEczZCwXt4g2xnvzGXibmqFhHNgLvXw0K/sm6Fj8iyLarBamEDJQZvkvLia+gF5LPRTx83oY9OXbWI9jEhnZhIJILrrqzmrxZw7/Qip4xH5mXkwB9r7sO5eED8RaywMVxhpXtdgv9n23nxbmHPLlJ4n6AUGF/OxL2y3hRgRzM0nqFMBe4nAkz//7rTUMynUIv7aLPwWWh1M11AMMYsyBqiyGrDwhmvoiyQN3gzIbG9xjRQVCc7vDuoWuRZV+9SP+Y7YDhgOdeiHvk0I5ROcbLiEmEn3YGJ1LLMafa/Wy4zFoRfDCesqDOCA8tDVwwybWFdmYBU9SUnEhBqD7V4HT4mNxg0muf1/q+4+0= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: d8ee0c01-fa9e-469b-93fe-08d745fb1e07 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:34.1814 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: lF63xttofUb7+j2e35M1KJcOm0NoOfOrSmwTnbkqseniEH0dZk2Zwy+MD1DqYmzP8KscSEFgnj6a2rqZvePO2g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Use the BIT() macro in asm/bitops.h rather than open-coding its equivalent. Signed-off-by: Paul Burton --- arch/mips/include/asm/bitops.h | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/arch/mips/include/asm/bitops.h b/arch/mips/include/asm/bitops.h index 0b0ce0adce8f..35582afc057b 100644 --- a/arch/mips/include/asm/bitops.h +++ b/arch/mips/include/asm/bitops.h @@ -13,6 +13,7 @@ #error only can be included directly #endif +#include #include #include #include @@ -70,7 +71,7 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) " beqzl %0, 1b \n" " .set pop \n" : "=&r" (temp), "=" GCC_OFF_SMALL_ASM() (*m) - : "ir" (1UL << bit), GCC_OFF_SMALL_ASM() (*m) + : "ir" (BIT(bit)), GCC_OFF_SMALL_ASM() (*m) : __LLSC_CLOBBER); return; } @@ -99,7 +100,7 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) " " __SC "%0, %1 \n" " .set pop \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "ir" (1UL << bit) + : "ir" (BIT(bit)) : __LLSC_CLOBBER); } while (unlikely(!temp)); } @@ -135,7 +136,7 @@ static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) " beqzl %0, 1b \n" " .set pop \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "ir" (~(1UL << bit)) + : "ir" (~(BIT(bit))) : __LLSC_CLOBBER); return; } @@ -164,7 +165,7 @@ static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) " " __SC "%0, %1 \n" " .set pop \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "ir" (~(1UL << bit)) + : "ir" (~(BIT(bit))) : __LLSC_CLOBBER); } while (unlikely(!temp)); } @@ -213,7 +214,7 @@ static inline void change_bit(unsigned long nr, volatile unsigned long *addr) " beqzl %0, 1b \n" " .set pop \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "ir" (1UL << bit) + : "ir" (BIT(bit)) : __LLSC_CLOBBER); return; } @@ -228,7 +229,7 @@ static inline void change_bit(unsigned long nr, volatile unsigned long *addr) " " __SC "%0, %1 \n" " .set pop \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "ir" (1UL << bit) + : "ir" (BIT(bit)) : __LLSC_CLOBBER); } while (unlikely(!temp)); } @@ -261,7 +262,7 @@ static inline int test_and_set_bit_lock(unsigned long nr, " and %2, %0, %3 \n" " .set pop \n" : "=&r" (temp), "+m" (*m), "=&r" (res) - : "ir" (1UL << bit) + : "ir" (BIT(bit)) : __LLSC_CLOBBER); } else { loongson_llsc_mb(); @@ -274,11 +275,11 @@ static inline int test_and_set_bit_lock(unsigned long nr, " " __SC "%2, %1 \n" " .set pop \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "ir" (1UL << bit) + : "ir" (BIT(bit)) : __LLSC_CLOBBER); } while (unlikely(!res)); - res = temp & (1UL << bit); + res = temp & BIT(bit); } smp_llsc_mb(); @@ -332,7 +333,7 @@ static inline int test_and_clear_bit(unsigned long nr, " and %2, %0, %3 \n" " .set pop \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "ir" (1UL << bit) + : "ir" (BIT(bit)) : __LLSC_CLOBBER); } else if ((MIPS_ISA_REV >= 2) && __builtin_constant_p(nr)) { loongson_llsc_mb(); @@ -358,11 +359,11 @@ static inline int test_and_clear_bit(unsigned long nr, " " __SC "%2, %1 \n" " .set pop \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "ir" (1UL << bit) + : "ir" (BIT(bit)) : __LLSC_CLOBBER); } while (unlikely(!res)); - res = temp & (1UL << bit); + res = temp & BIT(bit); } smp_llsc_mb(); @@ -400,7 +401,7 @@ static inline int test_and_change_bit(unsigned long nr, " and %2, %0, %3 \n" " .set pop \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "ir" (1UL << bit) + : "ir" (BIT(bit)) : __LLSC_CLOBBER); } else { loongson_llsc_mb(); @@ -413,11 +414,11 @@ static inline int test_and_change_bit(unsigned long nr, " " __SC "\t%2, %1 \n" " .set pop \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "ir" (1UL << bit) + : "ir" (BIT(bit)) : __LLSC_CLOBBER); } while (unlikely(!res)); - res = temp & (1UL << bit); + res = temp & BIT(bit); } smp_llsc_mb(); From patchwork Mon Sep 30 23:08:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167749 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3D87817E1 for ; Mon, 30 Sep 2019 23:08:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1B9622086A for ; Mon, 30 Sep 2019 23:08:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="MZrdaIia" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732666AbfI3XIx (ORCPT ); Mon, 30 Sep 2019 19:08:53 -0400 Received: from mail-eopbgr690119.outbound.protection.outlook.com ([40.107.69.119]:48448 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732660AbfI3XIx (ORCPT ); Mon, 30 Sep 2019 19:08:53 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TLr8so0oI8rBkho2fAAW6o1i5qaHKxgu4MT2KwYwu3D/rv59kLS/QdTUobncKJeLbi2Lkd+CzuWmLtv5NGa85R19ugViF7yuU4xaSZxJe3gc+Fxc2vGXeCHvG2E5maBKelcZLy+RcezOnv80mOw+qZaoIIZYS3wDixlCuAqGIMaSqa9R9hbMTcb1quKvdZ1L2nU7EK+4h3yX9kbaJEzdVwKFROSSfpXVK1yUXOVairn1+XWoagY1qQoNyIxneh0d1mHd8LkLO4ILWp7isMxb4WMPuulVRz6dt6XiPDqqtmxRzJMUMaKuy7hj0YXIFKcRz+2ubAnM26KetCUhTuNJVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y6hL1v6jV4BHoMLK6wrVGnQWkPUvOe+a6kzlMbdv42s=; b=WQScYYcrhmDTa4um38C+Y7bscVEMh2BVnEF73XS8Fjn74iYbHGxeeFeiJq9XtKBTLscjfZ7ezh8RozViBGJl30RaKNYFmCecpkZmS62CSlt7uEVWXWxATcSXgwY4/SJ+D60IDBkBWg3ieI3cVC8Nx1qJMydnuVoLHfyRyxq6aoJ2JcHp50Lh8fqHzjQOs8lu5eLyCdekRuH8oTVNDAg4TqBwNZzSFaEGgQE2OQIY+vcbOeJ+3fVKczI8VpM6eWXEpcuyCb8ygoAr49QDRia8psKnOaPuWNu3OgdfmcctdsxFKEclYW4a33mbYkJhdRj7XXcypXp6936sTD0ek2Y1Mg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y6hL1v6jV4BHoMLK6wrVGnQWkPUvOe+a6kzlMbdv42s=; b=MZrdaIiagRQ8hLKTf8kC2n/GpW7GWCzjvX0byNR7GQDqpBLEWkS4mCuIrf9mRBb2mLfze+m61iaJbDcMy6R7XEFfFx7V6IBUXTUtRviqCOKgiPQrMQF4XtpUP9EmMdXcUkkfGj8YCiy8a8MLNrEf3fBEMPohYbXNL2umeyexrUU= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:35 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:35 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 24/37] MIPS: bitops: Avoid redundant zero-comparison for non-LLSC Thread-Topic: [PATCH 24/37] MIPS: bitops: Avoid redundant zero-comparison for non-LLSC Thread-Index: AQHVd+P8A0ilHb6j/UC44m7h7ENk2w== Date: Mon, 30 Sep 2019 23:08:35 +0000 Message-ID: <20190930230806.2940505-25-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 9e77b366-0363-47ad-5390-08d745fb1ecc x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:883; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39850400004)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(14454004)(256004)(6512007)(81166006)(316002)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(478600001)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: xHQy0NF4YL96/8yitOFmgspi7YEhptGFiU31hBTp3A/c8ncOKW0X3hdp2YKQvVu29uWZ6hgFzdl7CaUPGMVHeLSFWTg6kMWchq1WlN7h4LtgXPhAlTOALbRmgBmqg2x5k582r+8KHW1FPFrlv+a0NtjZmIRQLjNPw0izcIPneQJiNz5UG+DY0vJdnc6E0c0GHPRGxYIRl7dWM9spivLS6Hjtao9J9ETtTwO5ZdgWMfYjpI1AM1/5bdPQPzEfmiLVZfDk4U7jjwJZ1nwmElq1NN66q+YHp1muPMUj0nJEFS7noOFww4Nc0YEHuK68Vq/wmDAlRHMk7DY/beXBViLHY/i9JVPZ6WQQLwacXcdVmV63cesM44/rhsAgKuBF8oEdqaUK28nUE/tvyzAwR3fslvIOIzRs4OcEqw3FL48kNuM= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9e77b366-0363-47ad-5390-08d745fb1ecc X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:35.3418 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: eSMvfZnXdp8Zc+ztQTN1UMPEd2Jxv9BO+lnFSqysiE8j+rrEC4TUWss78A5NcHLnr2fl6RIaF9QlXaDKCwYOqw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org The IRQ-disabling non-LLSC fallbacks for bitops on UP systems already return a zero or one, so there's no need to perform another comparison against zero. Move these comparisons into the LLSC paths to avoid the redundant work. Signed-off-by: Paul Burton --- arch/mips/include/asm/bitops.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/mips/include/asm/bitops.h b/arch/mips/include/asm/bitops.h index 35582afc057b..3e5589320e83 100644 --- a/arch/mips/include/asm/bitops.h +++ b/arch/mips/include/asm/bitops.h @@ -264,6 +264,8 @@ static inline int test_and_set_bit_lock(unsigned long nr, : "=&r" (temp), "+m" (*m), "=&r" (res) : "ir" (BIT(bit)) : __LLSC_CLOBBER); + + res = res != 0; } else { loongson_llsc_mb(); do { @@ -279,12 +281,12 @@ static inline int test_and_set_bit_lock(unsigned long nr, : __LLSC_CLOBBER); } while (unlikely(!res)); - res = temp & BIT(bit); + res = (temp & BIT(bit)) != 0; } smp_llsc_mb(); - return res != 0; + return res; } /* @@ -335,6 +337,8 @@ static inline int test_and_clear_bit(unsigned long nr, : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) : "ir" (BIT(bit)) : __LLSC_CLOBBER); + + res = res != 0; } else if ((MIPS_ISA_REV >= 2) && __builtin_constant_p(nr)) { loongson_llsc_mb(); do { @@ -363,12 +367,12 @@ static inline int test_and_clear_bit(unsigned long nr, : __LLSC_CLOBBER); } while (unlikely(!res)); - res = temp & BIT(bit); + res = (temp & BIT(bit)) != 0; } smp_llsc_mb(); - return res != 0; + return res; } /* @@ -403,6 +407,8 @@ static inline int test_and_change_bit(unsigned long nr, : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) : "ir" (BIT(bit)) : __LLSC_CLOBBER); + + res = res != 0; } else { loongson_llsc_mb(); do { @@ -418,12 +424,12 @@ static inline int test_and_change_bit(unsigned long nr, : __LLSC_CLOBBER); } while (unlikely(!res)); - res = temp & BIT(bit); + res = (temp & BIT(bit)) != 0; } smp_llsc_mb(); - return res != 0; + return res; } #include From patchwork Mon Sep 30 23:08:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167777 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AE320912 for ; Mon, 30 Sep 2019 23:10:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 783DA218DE for ; Mon, 30 Sep 2019 23:10:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="JJbbvJrQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732676AbfI3XIy (ORCPT ); Mon, 30 Sep 2019 19:08:54 -0400 Received: from mail-eopbgr690119.outbound.protection.outlook.com ([40.107.69.119]:48448 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732664AbfI3XIy (ORCPT ); Mon, 30 Sep 2019 19:08:54 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZMOXENCh6Qnf1QhHczZLMnGgD+ygIGu4v3dq3qT6NnkGo3zM1NNGOKGk/gQLaG05ZKhqhwiJFqmtj1hk6Svpk2EaimvQ+jHGF4ktI7rSYrO+JFGA8TLq2BmlRAmbcIg4OpCC56IAf7pgspnzO4arrBpUPIj6mkeD8BMa5ri1Vn/UVsCY/Yy2xE32Tf69sIvH0wIv3Ne7gqHuVGDlGRdIaEwCFeI515XBpgMTCFGAD5vVLfb626WvbjpXv2y4nqHWWPyPvetV1+we3dTShnwnAQphTeigXsRdfQ2PgMa/y08osi+s8wAMmeKl312ev+0w9rTDchoov+IgHzbfc3a3yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ak6sjpxGyC8CbsbIm1/cUuebkaYx7A1pT8ibGpVE7uU=; b=SyPhHUpm7iJbVydeFLHwl45J0BvAXGVk3Z+nA52i5D5rZ8Z5o7YOAdaerlXWM4gZtHHrq1rA/lnSIs+MgXh0OZPwWJf1A16COg9z673IqiK4Smqq8pyagxzOfIXoL7Cpk2L7R2USyLJRvv2GBTD4IBYBhFpvjG2HjIlNWqQzd7VxY8BJqpoJgS6vXYYQ2GXacGHqF7KZZ9AEvMzd2jVuRc0bus4jn6WxuCRjKqFRFPw+Xaea2+6+uizLfKSAgZHfwxksP7/64qQtdd/2n1cIa9T+l5FYEzn3dXaC4lpicJERw6Zu7Q6L4w3VhFhvbAgnc588vSYJJ7cFM0jbp/4TvQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ak6sjpxGyC8CbsbIm1/cUuebkaYx7A1pT8ibGpVE7uU=; b=JJbbvJrQkpdHmFc2SOQw6T6PJvCsl/kuZSFKOiZ8J2E9zMZMqhDy/CchxthhEInYGich04V7/X6h4JEDNtLpN9HI9jIY33Ucd09TncdeVRuE+CJkryIiL8VBmgwKGK88MJ/pAC9uNSoivrBFR8pJzKw/9vtCLJjRVpXN90ytbGs= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:36 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:36 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 25/37] MIPS: bitops: Abstract LL/SC loops Thread-Topic: [PATCH 25/37] MIPS: bitops: Abstract LL/SC loops Thread-Index: AQHVd+P8NJwoT+um5EOQRUe4f/jQIw== Date: Mon, 30 Sep 2019 23:08:36 +0000 Message-ID: <20190930230806.2940505-26-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d0f649e1-e92b-4f71-1a77-08d745fb1f47 x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:751; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39850400004)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(14454004)(256004)(6512007)(81166006)(316002)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(478600001)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: wym9qoA4ReEjcWGoJFCiZC4P/VpLFP/t6bTJiqX262km2FQWhYjoCF1R0yNbnsc9M05ydw4OxjHI33LTB7vkVKKlD2ZI9b7eUd/Ngv6b90UxXhbMKjcKRKXqvHMC6IPabBSp+EJcAEi8D7LkZ/Kx/TWqVyj9/hDUuxkdYXL9sXOTl8UBc2nznqgYs7ByH6DU4qW1xspiutNn+Zv/c80Iow+WQlkFQGUMFeavb4umrCxsWegnnokdi8uB94T8975Spwh04zI7iX8DDzvbsB8lNQFvcGTrzK3mV5MsFVhIPlEjQDmQoTPMAPLqrB+wbgG+2s5uEUz2MmdAArdIWXpfFkLRI4URewECqMp1goIo1Zl+7/UcLDLb3jrfXW3UYfOdpiclC3w5bR0MYRROXy6UqKHHCWJBOcgJq/vQ7qOe8VA= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: d0f649e1-e92b-4f71-1a77-08d745fb1f47 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:36.1785 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: fx31rtvENW4/R2oL2X11xjj3fU2YgprUY6mG6vvsRpG0pPJCqeDrbqYkK3Vhw35T4x9H6JG2XXwDZauJzrBuzQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Introduce __bit_op() & __test_bit_op() macros which abstract away the implementation of LL/SC loops. This cuts down on a lot of duplicate boilerplate code, and also allows R10000_LLSC_WAR to be handled outside of the individual bitop functions. Signed-off-by: Paul Burton --- arch/mips/include/asm/bitops.h | 267 ++++++++------------------------- 1 file changed, 63 insertions(+), 204 deletions(-) diff --git a/arch/mips/include/asm/bitops.h b/arch/mips/include/asm/bitops.h index 3e5589320e83..5701f8b41e87 100644 --- a/arch/mips/include/asm/bitops.h +++ b/arch/mips/include/asm/bitops.h @@ -25,6 +25,41 @@ #include #include +#define __bit_op(mem, insn, inputs...) do { \ + unsigned long temp; \ + \ + asm volatile( \ + " .set push \n" \ + " .set " MIPS_ISA_LEVEL " \n" \ + "1: " __LL "%0, %1 \n" \ + " " insn " \n" \ + " " __SC "%0, %1 \n" \ + " " __SC_BEQZ "%0, 1b \n" \ + " .set pop \n" \ + : "=&r"(temp), "+" GCC_OFF_SMALL_ASM()(mem) \ + : inputs \ + : __LLSC_CLOBBER); \ +} while (0) + +#define __test_bit_op(mem, ll_dst, insn, inputs...) ({ \ + unsigned long orig, temp; \ + \ + asm volatile( \ + " .set push \n" \ + " .set " MIPS_ISA_LEVEL " \n" \ + "1: " __LL ll_dst ", %2 \n" \ + " " insn " \n" \ + " " __SC "%1, %2 \n" \ + " " __SC_BEQZ "%1, 1b \n" \ + " .set pop \n" \ + : "=&r"(orig), "=&r"(temp), \ + "+" GCC_OFF_SMALL_ASM()(mem) \ + : inputs \ + : __LLSC_CLOBBER); \ + \ + orig; \ +}) + /* * These are the "slower" versions of the functions and are in bitops.c. * These functions call raw_local_irq_{save,restore}(). @@ -54,55 +89,20 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) { unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); int bit = nr & SZLONG_MASK; - unsigned long temp; if (!kernel_uses_llsc) { __mips_set_bit(nr, addr); return; } - if (R10000_LLSC_WAR) { - __asm__ __volatile__( - " .set push \n" - " .set arch=r4000 \n" - "1: " __LL "%0, %1 # set_bit \n" - " or %0, %2 \n" - " " __SC "%0, %1 \n" - " beqzl %0, 1b \n" - " .set pop \n" - : "=&r" (temp), "=" GCC_OFF_SMALL_ASM() (*m) - : "ir" (BIT(bit)), GCC_OFF_SMALL_ASM() (*m) - : __LLSC_CLOBBER); - return; - } - if ((MIPS_ISA_REV >= 2) && __builtin_constant_p(bit) && (bit >= 16)) { loongson_llsc_mb(); - do { - __asm__ __volatile__( - " " __LL "%0, %1 # set_bit \n" - " " __INS "%0, %3, %2, 1 \n" - " " __SC "%0, %1 \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "i" (bit), "r" (~0) - : __LLSC_CLOBBER); - } while (unlikely(!temp)); + __bit_op(*m, __INS "%0, %3, %2, 1", "i"(bit), "r"(~0)); return; } loongson_llsc_mb(); - do { - __asm__ __volatile__( - " .set push \n" - " .set "MIPS_ISA_ARCH_LEVEL" \n" - " " __LL "%0, %1 # set_bit \n" - " or %0, %2 \n" - " " __SC "%0, %1 \n" - " .set pop \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "ir" (BIT(bit)) - : __LLSC_CLOBBER); - } while (unlikely(!temp)); + __bit_op(*m, "or\t%0, %2", "ir"(BIT(bit))); } /* @@ -119,55 +119,20 @@ static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) { unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); int bit = nr & SZLONG_MASK; - unsigned long temp; if (!kernel_uses_llsc) { __mips_clear_bit(nr, addr); return; } - if (R10000_LLSC_WAR) { - __asm__ __volatile__( - " .set push \n" - " .set arch=r4000 \n" - "1: " __LL "%0, %1 # clear_bit \n" - " and %0, %2 \n" - " " __SC "%0, %1 \n" - " beqzl %0, 1b \n" - " .set pop \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "ir" (~(BIT(bit))) - : __LLSC_CLOBBER); - return; - } - if ((MIPS_ISA_REV >= 2) && __builtin_constant_p(bit)) { loongson_llsc_mb(); - do { - __asm__ __volatile__( - " " __LL "%0, %1 # clear_bit \n" - " " __INS "%0, $0, %2, 1 \n" - " " __SC "%0, %1 \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "i" (bit) - : __LLSC_CLOBBER); - } while (unlikely(!temp)); + __bit_op(*m, __INS "%0, $0, %2, 1", "i"(bit)); return; } loongson_llsc_mb(); - do { - __asm__ __volatile__( - " .set push \n" - " .set "MIPS_ISA_ARCH_LEVEL" \n" - " " __LL "%0, %1 # clear_bit \n" - " and %0, %2 \n" - " " __SC "%0, %1 \n" - " .set pop \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "ir" (~(BIT(bit))) - : __LLSC_CLOBBER); - } while (unlikely(!temp)); + __bit_op(*m, "and\t%0, %2", "ir"(~BIT(bit))); } /* @@ -197,41 +162,14 @@ static inline void change_bit(unsigned long nr, volatile unsigned long *addr) { unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); int bit = nr & SZLONG_MASK; - unsigned long temp; if (!kernel_uses_llsc) { __mips_change_bit(nr, addr); return; } - if (R10000_LLSC_WAR) { - __asm__ __volatile__( - " .set push \n" - " .set arch=r4000 \n" - "1: " __LL "%0, %1 # change_bit \n" - " xor %0, %2 \n" - " " __SC "%0, %1 \n" - " beqzl %0, 1b \n" - " .set pop \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "ir" (BIT(bit)) - : __LLSC_CLOBBER); - return; - } - loongson_llsc_mb(); - do { - __asm__ __volatile__( - " .set push \n" - " .set "MIPS_ISA_ARCH_LEVEL" \n" - " " __LL "%0, %1 # change_bit \n" - " xor %0, %2 \n" - " " __SC "%0, %1 \n" - " .set pop \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) - : "ir" (BIT(bit)) - : __LLSC_CLOBBER); - } while (unlikely(!temp)); + __bit_op(*m, "xor\t%0, %2", "ir"(BIT(bit))); } /* @@ -247,41 +185,16 @@ static inline int test_and_set_bit_lock(unsigned long nr, { unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); int bit = nr & SZLONG_MASK; - unsigned long res, temp; + unsigned long res, orig; if (!kernel_uses_llsc) { res = __mips_test_and_set_bit_lock(nr, addr); - } else if (R10000_LLSC_WAR) { - __asm__ __volatile__( - " .set push \n" - " .set arch=r4000 \n" - "1: " __LL "%0, %1 # test_and_set_bit \n" - " or %2, %0, %3 \n" - " " __SC "%2, %1 \n" - " beqzl %2, 1b \n" - " and %2, %0, %3 \n" - " .set pop \n" - : "=&r" (temp), "+m" (*m), "=&r" (res) - : "ir" (BIT(bit)) - : __LLSC_CLOBBER); - - res = res != 0; } else { loongson_llsc_mb(); - do { - __asm__ __volatile__( - " .set push \n" - " .set "MIPS_ISA_ARCH_LEVEL" \n" - " " __LL "%0, %1 # test_and_set_bit \n" - " or %2, %0, %3 \n" - " " __SC "%2, %1 \n" - " .set pop \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "ir" (BIT(bit)) - : __LLSC_CLOBBER); - } while (unlikely(!res)); - - res = (temp & BIT(bit)) != 0; + orig = __test_bit_op(*m, "%0", + "or\t%1, %0, %3", + "ir"(BIT(bit))); + res = (orig & BIT(bit)) != 0; } smp_llsc_mb(); @@ -317,57 +230,25 @@ static inline int test_and_clear_bit(unsigned long nr, { unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); int bit = nr & SZLONG_MASK; - unsigned long res, temp; + unsigned long res, orig; smp_mb__before_llsc(); if (!kernel_uses_llsc) { res = __mips_test_and_clear_bit(nr, addr); - } else if (R10000_LLSC_WAR) { - __asm__ __volatile__( - " .set push \n" - " .set arch=r4000 \n" - "1: " __LL "%0, %1 # test_and_clear_bit \n" - " or %2, %0, %3 \n" - " xor %2, %3 \n" - " " __SC "%2, %1 \n" - " beqzl %2, 1b \n" - " and %2, %0, %3 \n" - " .set pop \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "ir" (BIT(bit)) - : __LLSC_CLOBBER); - - res = res != 0; } else if ((MIPS_ISA_REV >= 2) && __builtin_constant_p(nr)) { loongson_llsc_mb(); - do { - __asm__ __volatile__( - " " __LL "%0, %1 # test_and_clear_bit \n" - " " __EXT "%2, %0, %3, 1 \n" - " " __INS "%0, $0, %3, 1 \n" - " " __SC "%0, %1 \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "i" (bit) - : __LLSC_CLOBBER); - } while (unlikely(!temp)); + res = __test_bit_op(*m, "%1", + __EXT "%0, %1, %3, 1;" + __INS "%1, $0, %3, 1", + "i"(bit)); } else { loongson_llsc_mb(); - do { - __asm__ __volatile__( - " .set push \n" - " .set "MIPS_ISA_ARCH_LEVEL" \n" - " " __LL "%0, %1 # test_and_clear_bit \n" - " or %2, %0, %3 \n" - " xor %2, %3 \n" - " " __SC "%2, %1 \n" - " .set pop \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "ir" (BIT(bit)) - : __LLSC_CLOBBER); - } while (unlikely(!res)); - - res = (temp & BIT(bit)) != 0; + orig = __test_bit_op(*m, "%0", + "or\t%1, %0, %3;" + "xor\t%1, %1, %3", + "ir"(BIT(bit))); + res = (orig & BIT(bit)) != 0; } smp_llsc_mb(); @@ -388,43 +269,18 @@ static inline int test_and_change_bit(unsigned long nr, { unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); int bit = nr & SZLONG_MASK; - unsigned long res, temp; + unsigned long res, orig; smp_mb__before_llsc(); if (!kernel_uses_llsc) { res = __mips_test_and_change_bit(nr, addr); - } else if (R10000_LLSC_WAR) { - __asm__ __volatile__( - " .set push \n" - " .set arch=r4000 \n" - "1: " __LL "%0, %1 # test_and_change_bit \n" - " xor %2, %0, %3 \n" - " " __SC "%2, %1 \n" - " beqzl %2, 1b \n" - " and %2, %0, %3 \n" - " .set pop \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "ir" (BIT(bit)) - : __LLSC_CLOBBER); - - res = res != 0; } else { loongson_llsc_mb(); - do { - __asm__ __volatile__( - " .set push \n" - " .set "MIPS_ISA_ARCH_LEVEL" \n" - " " __LL "%0, %1 # test_and_change_bit \n" - " xor %2, %0, %3 \n" - " " __SC "\t%2, %1 \n" - " .set pop \n" - : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m), "=&r" (res) - : "ir" (BIT(bit)) - : __LLSC_CLOBBER); - } while (unlikely(!res)); - - res = (temp & BIT(bit)) != 0; + orig = __test_bit_op(*m, "%0", + "xor\t%1, %0, %3", + "ir"(BIT(bit))); + res = (orig & BIT(bit)) != 0; } smp_llsc_mb(); @@ -432,6 +288,9 @@ static inline int test_and_change_bit(unsigned long nr, return res; } +#undef __bit_op +#undef __test_bit_op + #include /* From patchwork Mon Sep 30 23:08:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167751 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D85514DB for ; Mon, 30 Sep 2019 23:09:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 483EC2086A for ; Mon, 30 Sep 2019 23:09:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="mMcneG3U" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732650AbfI3XJI (ORCPT ); Mon, 30 Sep 2019 19:09:08 -0400 Received: from mail-eopbgr820094.outbound.protection.outlook.com ([40.107.82.94]:14848 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732668AbfI3XJI (ORCPT ); Mon, 30 Sep 2019 19:09:08 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gqIzJO4VBSS3PnuvuA1TBJ/EkVobFkYvR8kCAjPDHgyHf1WzzJjJuJXvlUl7VlLg1p7IKlZaUTpx3yiOUARZz7vk2U5TKKd+X4HB4EfqhyrvxJSCXOxiv2xkNm4XHJcBA38heZiQ6gjMUgTISPls4DYTXIpnW0PSVZmGyJUWOj5dLJNRTStHyNzixHKcRP/aIGWclRb2Dv3KVMWRiAL+8UMy/t/7n/D5FAPDIy1mwjBiv8jqKJ9dcd0b+joHIKDS1522IK3IxtUfoegUSWS9Ba6m+L5BmJruR1uL0IX84QqIsAC1y/oVMtDlnqs7yXXHcODpn66MV/DrQKk8bOXVqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N9QO9GhbHq2ow+GTkgSArw21MBBAnQZ996yb/+T2VKM=; b=ZefsLg9hH43dKKYllfC1qtHcK1ZY0SmlSjlsi1DaYYrT6pRGfPyWuVn5BBq20V1qPWSZLazv2yb2oXqjKWzs5O9L8tH6ZVbW/5k3Fadocx8mdr0A7WSgI2dm1aCYpWTq0LsjgTkoNRo+FPNASNPg0ovBtCXhSkCjdcSnX9tftlbB3dwZN9Y6xMJXvG2xZbanhoSPcufqaK8ZutPKL7EYgy2HL3e9O4BPk0DTe7ukIWDmXB2pSX4e5v6EVDMg+loFDdN4I/rsKDGj1Ylaxvt+nR7gXBwv+oJsfQOZB8TWVNsuRZ649XpPe01mxrAuqFym0lrM2m9y2j0wRotUe6y/lg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N9QO9GhbHq2ow+GTkgSArw21MBBAnQZ996yb/+T2VKM=; b=mMcneG3UW6lUIaAw7TqmudTTJ+M1NMXlVn0UpiTr3ErzrJNgy2k9Htfbakyu4h1Jnitey+Gu7VJJSAtcNZfWlziUCwSyQVGVqUNvZ7PjNb/lpNl7+cuOU/U0byFlaL5luEKpUbDP/xxZ6jbuTtQC001udNWSoCQ0q9XwpcQyF4M= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:37 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:37 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 26/37] MIPS: bitops: Use BIT_WORD() & BITS_PER_LONG Thread-Topic: [PATCH 26/37] MIPS: bitops: Use BIT_WORD() & BITS_PER_LONG Thread-Index: AQHVd+P9u1jVk9oA90K0A0rSvCCFNA== Date: Mon, 30 Sep 2019 23:08:36 +0000 Message-ID: <20190930230806.2940505-27-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 769e27f4-9c67-4062-2f72-08d745fb1fc2 x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(1496009)(39850400004)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(14454004)(256004)(6512007)(81166006)(316002)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(478600001)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: dmReIcvoTwZPRmawdY9zlD35slGdLohnzwpJfPqNlEVblinKXEyHdcK6FxZnA3pZvJ1VJK7ButwPeIv0R7Tnbwgx6W+Dj5HV3yJdr/Re0MFbhCQgBkSuuZ/2tWRVxvoLJRsOmxIMxZD35mixWzT9IxmTA0Z7YZEr9P6rPCvVz/GqPcjuRaw0tiOEFHjjmnGBvwsUBzp0wB8LEi/pj4a2PhKYDIvY5GEC6FKENcjsnWD1EP637FPhi/UNX/bbWXxXoywB4f7ZuBYSe8macIEexltadu8iCzVSayQpGJB100PeZ5dEAIyMYgpVjsVcEIZQvHOCt6ZoYwcYwFzyvtupE/27yCoS05UfAKeqQ2llODFZeJrlxbw9kzOlZCfpA+4+rELKjHY7WOCh+TsE+NgQmj/SlWhxRSzu3wz3j/nF/aE= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 769e27f4-9c67-4062-2f72-08d745fb1fc2 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:36.9771 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 0gFy8ZxTc5kGkdMxdBreIUt9uZEPCu54BVnIjYN8CSH0WIUltDl+t4yP0rvCY8Oh6LrNPBhwm+x+Fyiy1L/MOw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Rather than using custom SZLONG_LOG & SZLONG_MASK macros to shift & mask a bit index to form word & bit offsets respectively, make use of the standard BIT_WORD() & BITS_PER_LONG macros for the same purpose. volatile is added to the definition of pointers to the long-sized word we'll operate on, in order to prevent the compiler complaining that we cast away the volatile qualifier of the addr argument. This should have no effect on generated code, which in the LL/SC case is inline asm anyway & in the non-LLSC case access is constrained by compiler barriers provided by raw_local_irq_{save,restore}(). Signed-off-by: Paul Burton --- arch/mips/include/asm/bitops.h | 24 ++++++++++++------------ arch/mips/include/asm/llsc.h | 4 ---- arch/mips/lib/bitops.c | 31 +++++++++++++------------------ 3 files changed, 25 insertions(+), 34 deletions(-) diff --git a/arch/mips/include/asm/bitops.h b/arch/mips/include/asm/bitops.h index 5701f8b41e87..59fe1d5d4fc9 100644 --- a/arch/mips/include/asm/bitops.h +++ b/arch/mips/include/asm/bitops.h @@ -87,8 +87,8 @@ int __mips_test_and_change_bit(unsigned long nr, */ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) { - unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); - int bit = nr & SZLONG_MASK; + volatile unsigned long *m = &addr[BIT_WORD(nr)]; + int bit = nr % BITS_PER_LONG; if (!kernel_uses_llsc) { __mips_set_bit(nr, addr); @@ -117,8 +117,8 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) */ static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) { - unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); - int bit = nr & SZLONG_MASK; + volatile unsigned long *m = &addr[BIT_WORD(nr)]; + int bit = nr % BITS_PER_LONG; if (!kernel_uses_llsc) { __mips_clear_bit(nr, addr); @@ -160,8 +160,8 @@ static inline void clear_bit_unlock(unsigned long nr, volatile unsigned long *ad */ static inline void change_bit(unsigned long nr, volatile unsigned long *addr) { - unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); - int bit = nr & SZLONG_MASK; + volatile unsigned long *m = &addr[BIT_WORD(nr)]; + int bit = nr % BITS_PER_LONG; if (!kernel_uses_llsc) { __mips_change_bit(nr, addr); @@ -183,8 +183,8 @@ static inline void change_bit(unsigned long nr, volatile unsigned long *addr) static inline int test_and_set_bit_lock(unsigned long nr, volatile unsigned long *addr) { - unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); - int bit = nr & SZLONG_MASK; + volatile unsigned long *m = &addr[BIT_WORD(nr)]; + int bit = nr % BITS_PER_LONG; unsigned long res, orig; if (!kernel_uses_llsc) { @@ -228,8 +228,8 @@ static inline int test_and_set_bit(unsigned long nr, static inline int test_and_clear_bit(unsigned long nr, volatile unsigned long *addr) { - unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); - int bit = nr & SZLONG_MASK; + volatile unsigned long *m = &addr[BIT_WORD(nr)]; + int bit = nr % BITS_PER_LONG; unsigned long res, orig; smp_mb__before_llsc(); @@ -267,8 +267,8 @@ static inline int test_and_clear_bit(unsigned long nr, static inline int test_and_change_bit(unsigned long nr, volatile unsigned long *addr) { - unsigned long *m = ((unsigned long *)addr) + (nr >> SZLONG_LOG); - int bit = nr & SZLONG_MASK; + volatile unsigned long *m = &addr[BIT_WORD(nr)]; + int bit = nr % BITS_PER_LONG; unsigned long res, orig; smp_mb__before_llsc(); diff --git a/arch/mips/include/asm/llsc.h b/arch/mips/include/asm/llsc.h index d240a4a2d1c4..c49738bc3bda 100644 --- a/arch/mips/include/asm/llsc.h +++ b/arch/mips/include/asm/llsc.h @@ -12,15 +12,11 @@ #include #if _MIPS_SZLONG == 32 -#define SZLONG_LOG 5 -#define SZLONG_MASK 31UL #define __LL "ll " #define __SC "sc " #define __INS "ins " #define __EXT "ext " #elif _MIPS_SZLONG == 64 -#define SZLONG_LOG 6 -#define SZLONG_MASK 63UL #define __LL "lld " #define __SC "scd " #define __INS "dins " diff --git a/arch/mips/lib/bitops.c b/arch/mips/lib/bitops.c index fba402c0879d..116d0bd8b2ae 100644 --- a/arch/mips/lib/bitops.c +++ b/arch/mips/lib/bitops.c @@ -7,6 +7,7 @@ * Copyright (c) 1999, 2000 Silicon Graphics, Inc. */ #include +#include #include #include @@ -19,12 +20,11 @@ */ void __mips_set_bit(unsigned long nr, volatile unsigned long *addr) { - unsigned long *a = (unsigned long *)addr; - unsigned bit = nr & SZLONG_MASK; + volatile unsigned long *a = &addr[BIT_WORD(nr)]; + unsigned int bit = nr % BITS_PER_LONG; unsigned long mask; unsigned long flags; - a += nr >> SZLONG_LOG; mask = 1UL << bit; raw_local_irq_save(flags); *a |= mask; @@ -41,12 +41,11 @@ EXPORT_SYMBOL(__mips_set_bit); */ void __mips_clear_bit(unsigned long nr, volatile unsigned long *addr) { - unsigned long *a = (unsigned long *)addr; - unsigned bit = nr & SZLONG_MASK; + volatile unsigned long *a = &addr[BIT_WORD(nr)]; + unsigned int bit = nr % BITS_PER_LONG; unsigned long mask; unsigned long flags; - a += nr >> SZLONG_LOG; mask = 1UL << bit; raw_local_irq_save(flags); *a &= ~mask; @@ -63,12 +62,11 @@ EXPORT_SYMBOL(__mips_clear_bit); */ void __mips_change_bit(unsigned long nr, volatile unsigned long *addr) { - unsigned long *a = (unsigned long *)addr; - unsigned bit = nr & SZLONG_MASK; + volatile unsigned long *a = &addr[BIT_WORD(nr)]; + unsigned int bit = nr % BITS_PER_LONG; unsigned long mask; unsigned long flags; - a += nr >> SZLONG_LOG; mask = 1UL << bit; raw_local_irq_save(flags); *a ^= mask; @@ -86,13 +84,12 @@ EXPORT_SYMBOL(__mips_change_bit); int __mips_test_and_set_bit_lock(unsigned long nr, volatile unsigned long *addr) { - unsigned long *a = (unsigned long *)addr; - unsigned bit = nr & SZLONG_MASK; + volatile unsigned long *a = &addr[BIT_WORD(nr)]; + unsigned int bit = nr % BITS_PER_LONG; unsigned long mask; unsigned long flags; int res; - a += nr >> SZLONG_LOG; mask = 1UL << bit; raw_local_irq_save(flags); res = (mask & *a) != 0; @@ -111,13 +108,12 @@ EXPORT_SYMBOL(__mips_test_and_set_bit_lock); */ int __mips_test_and_clear_bit(unsigned long nr, volatile unsigned long *addr) { - unsigned long *a = (unsigned long *)addr; - unsigned bit = nr & SZLONG_MASK; + volatile unsigned long *a = &addr[BIT_WORD(nr)]; + unsigned int bit = nr % BITS_PER_LONG; unsigned long mask; unsigned long flags; int res; - a += nr >> SZLONG_LOG; mask = 1UL << bit; raw_local_irq_save(flags); res = (mask & *a) != 0; @@ -136,13 +132,12 @@ EXPORT_SYMBOL(__mips_test_and_clear_bit); */ int __mips_test_and_change_bit(unsigned long nr, volatile unsigned long *addr) { - unsigned long *a = (unsigned long *)addr; - unsigned bit = nr & SZLONG_MASK; + volatile unsigned long *a = &addr[BIT_WORD(nr)]; + unsigned int bit = nr % BITS_PER_LONG; unsigned long mask; unsigned long flags; int res; - a += nr >> SZLONG_LOG; mask = 1UL << bit; raw_local_irq_save(flags); res = (mask & *a) != 0; From patchwork Mon Sep 30 23:08:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167775 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C0F814DB for ; Mon, 30 Sep 2019 23:10:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 203A52086A for ; Mon, 30 Sep 2019 23:10:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="IcudCc/H" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732732AbfI3XJP (ORCPT ); Mon, 30 Sep 2019 19:09:15 -0400 Received: from mail-eopbgr690119.outbound.protection.outlook.com ([40.107.69.119]:48448 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732672AbfI3XI4 (ORCPT ); Mon, 30 Sep 2019 19:08:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Aq+dMSlD/JjM+m3BtMLGd9kYc8oOHKGAFc8cRIxnnLFFRZeMKjPWuArq8QRnKWQUjT59X1Sx7r4zrv3IqrCVJv9BFcN7mwpMY54R5t4SaFb+qdeC/wWMKOSijC2gqOKh87iRLgcsRXBPf46J1eCWvsxhxA/yF/mdbSMu6kBwG6kUCZkPa+ji1fr+H2a1+oe9oWDb3PxYohWLxCqgk35NdPxLwti7DxGZorj1R7/X+uxWgJjmxkI9g19BokeyZBqhC7VFnJ41MTqtxAB78UpJoHk9qGX8EiaCSe3sGvTDQnGstlnaACXm1lGli6NXSRMzQh6JI/RVcUKZ+r0XPSicmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WhNYsmwbn6ZJzQOTghd2RFII1dQQ5hCvplB6kY72LnU=; b=fYnVfHcGr7u1S5NOiqpLEzLN5eiYHSV77+9XzWZRXQz75XQXEk11t9CKrSIYENFFv5bc6GTDDpjAIzuseMQZMpImn5GdAChrm9A4SVy9a4VB58PgRrgn2TZ+wosPSBG2z3QAY9SM7weFv8TAuMsNBYU+QuEC6gW6Or4ECY80cyhy2LmTvaruXV19lNcV8c9zYOqTzcAU38B52Djj/AwVf40cTIiAq0Azo8NdzXaxGKsJAJHjrJvXG9FImn3ROZ5P3nY5745p5JJEYmn6cG0dFabkWi7T3pcJQ2e1M1LOW6Kw2HCq9OKTQAAUSTK4jwUURsRr2XvEPRWM/TvhH3VEfg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WhNYsmwbn6ZJzQOTghd2RFII1dQQ5hCvplB6kY72LnU=; b=IcudCc/H75WFsOdhwARk1IwuiWachCPVBFF6oPWnfr7RC5m3iLurm4DIroU6SuygYiSI/TtIf9oWhVjYsGPS7EJts0lpR4H8Qytc/07+9c3y0NpMNQJaBsrkkqkeYp5Yosp/QEH/ggp+ApaxnzuQ5zj64ag5u4iY0rerHWkEHWk= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:37 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:37 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 27/37] MIPS: bitops: Emit Loongson3 sync workarounds within asm Thread-Topic: [PATCH 27/37] MIPS: bitops: Emit Loongson3 sync workarounds within asm Thread-Index: AQHVd+P9shQj/qNsjEaOCGSSfpq8Ug== Date: Mon, 30 Sep 2019 23:08:37 +0000 Message-ID: <20190930230806.2940505-28-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4d790d6c-0013-42ec-7c79-08d745fb2047 x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2657; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(1496009)(39850400004)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(14454004)(256004)(6512007)(81166006)(316002)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(478600001)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: cZJsMpqKDcoskgCEm7UjFFxY5yM6Ptm0L8wRvBXorC8NZzw157myQJ2TUP5L9NvdqWckxIEpV1pinBOP/lG12NGGIpThvr+VM2bEV9d6rru50YrbkAr1mckuy3AwwmIDjde3+iNY8GYlXU2Gk5p9KOiyMVgV/aBQY35EE2vKa/oC7kM38e3EbwkXC4ycmZStScW98Pvx4qrCCyQTjSBA/q4bai2TZqM0t8fFUdLPzYjr+Vdm71KGZAmAj4iq2tuZWbdiMvZsN+h7n4os7ZUkRE/RzRXORWx7GJZZoiXG3FwCRuhBL4YPahMPl3yas2Mk6utahn2kxg600/ASBV8tPpMibCilhOSkOlW4OD1YXJpDeLko4tZh2shk0DIFNyVYJ80YlmBX7OG24O5n+yp40ZYGAyecFK+4UZv0+dejzv4= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4d790d6c-0013-42ec-7c79-08d745fb2047 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:37.8047 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: D2h52Eny3Cin1RaHdj3yN4r148ulaWfmmuZkUHxqWVlqJQo1Y9gXAYnX7ceiSOm0rDfRrhPNXgPJwiNpOr/81w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Generate the sync instructions required to workaround Loongson3 LL/SC errata within inline asm blocks, which feels a little safer than doing it from C where strictly speaking the compiler would be well within its rights to insert a memory access between the separate asm statements we previously had, containing sync & ll instructions respectively. Signed-off-by: Paul Burton --- arch/mips/include/asm/bitops.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/arch/mips/include/asm/bitops.h b/arch/mips/include/asm/bitops.h index 59fe1d5d4fc9..9e967d6622c8 100644 --- a/arch/mips/include/asm/bitops.h +++ b/arch/mips/include/asm/bitops.h @@ -31,6 +31,7 @@ asm volatile( \ " .set push \n" \ " .set " MIPS_ISA_LEVEL " \n" \ + " " __SYNC(full, loongson3_war) " \n" \ "1: " __LL "%0, %1 \n" \ " " insn " \n" \ " " __SC "%0, %1 \n" \ @@ -47,6 +48,7 @@ asm volatile( \ " .set push \n" \ " .set " MIPS_ISA_LEVEL " \n" \ + " " __SYNC(full, loongson3_war) " \n" \ "1: " __LL ll_dst ", %2 \n" \ " " insn " \n" \ " " __SC "%1, %2 \n" \ @@ -96,12 +98,10 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) } if ((MIPS_ISA_REV >= 2) && __builtin_constant_p(bit) && (bit >= 16)) { - loongson_llsc_mb(); __bit_op(*m, __INS "%0, %3, %2, 1", "i"(bit), "r"(~0)); return; } - loongson_llsc_mb(); __bit_op(*m, "or\t%0, %2", "ir"(BIT(bit))); } @@ -126,12 +126,10 @@ static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) } if ((MIPS_ISA_REV >= 2) && __builtin_constant_p(bit)) { - loongson_llsc_mb(); __bit_op(*m, __INS "%0, $0, %2, 1", "i"(bit)); return; } - loongson_llsc_mb(); __bit_op(*m, "and\t%0, %2", "ir"(~BIT(bit))); } @@ -168,7 +166,6 @@ static inline void change_bit(unsigned long nr, volatile unsigned long *addr) return; } - loongson_llsc_mb(); __bit_op(*m, "xor\t%0, %2", "ir"(BIT(bit))); } @@ -190,7 +187,6 @@ static inline int test_and_set_bit_lock(unsigned long nr, if (!kernel_uses_llsc) { res = __mips_test_and_set_bit_lock(nr, addr); } else { - loongson_llsc_mb(); orig = __test_bit_op(*m, "%0", "or\t%1, %0, %3", "ir"(BIT(bit))); @@ -237,13 +233,11 @@ static inline int test_and_clear_bit(unsigned long nr, if (!kernel_uses_llsc) { res = __mips_test_and_clear_bit(nr, addr); } else if ((MIPS_ISA_REV >= 2) && __builtin_constant_p(nr)) { - loongson_llsc_mb(); res = __test_bit_op(*m, "%1", __EXT "%0, %1, %3, 1;" __INS "%1, $0, %3, 1", "i"(bit)); } else { - loongson_llsc_mb(); orig = __test_bit_op(*m, "%0", "or\t%1, %0, %3;" "xor\t%1, %1, %3", @@ -276,7 +270,6 @@ static inline int test_and_change_bit(unsigned long nr, if (!kernel_uses_llsc) { res = __mips_test_and_change_bit(nr, addr); } else { - loongson_llsc_mb(); orig = __test_bit_op(*m, "%0", "xor\t%1, %0, %3", "ir"(BIT(bit))); From patchwork Mon Sep 30 23:08:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167755 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A474912 for ; Mon, 30 Sep 2019 23:09:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC3432086A for ; Mon, 30 Sep 2019 23:09:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="Toc1DFB5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729740AbfI3XJO (ORCPT ); Mon, 30 Sep 2019 19:09:14 -0400 Received: from mail-eopbgr690119.outbound.protection.outlook.com ([40.107.69.119]:48448 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732683AbfI3XI6 (ORCPT ); Mon, 30 Sep 2019 19:08:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eCue5XQjosLvbgzo37y4DkrdLLa0pfNdXQatcw/Xoj1QfSScOiKlAkP93eyaUiR+uXCTszzAhYle6j4huzr9E1A7Fa7mUOBHpT9rhfaTVDkf1VRNDyxTSif3cIuCTLSV3XtUvxnMmwQYGfuywcx/mbAsY0eEBxzDtq+wRkJJW1Yfcum/6eL9OqmT2zKRPV1OP5jqXiR2qHPvoUbO8BzCXNusPOY/N/xPe7gRKfuvY/e8CAjlgyMQIoIGndHgUpVKnva5p0UR20jfNsxDgJJ1I7dCq5fJkewPWYQ6BwEVtqo1pJWISlNrfcgtuPigObThnhaaI6lVg3B/9GXBMfPPgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KaCYT94YeFl1o++ov4HQQnRx4R1OEcpIKK6cm9EuvZM=; b=ionU5BNsqlKpVNKum1femfunCf/vaKk+3Ofsc2HNtnF0pU3rnBBcogiYi+emYCnPeCOjOWu/uDJVr+pyfL0jmL0BPlBR/rICEpfpWKltYLbpaU1bzi+Yp9UsxSPbw9TJhj+yKpRwgkVTIvB0cXBmVUjDHKoDxcg1DhAGKNgVDIkS3SyG0C8TThkZkoqgJML/juIGm4Bu37XLzbs2a3PMSXY2I9Vvl7aVOJm3rb2uS75Fei5U3kJjylen0WcqRTY+mHuzbwGckiI5GLV3owet7tFm98BsovDU4JWiqjDYFBCjDwW4Pj9BbIGw+yjaZkgnbp2KViEGV9PZ8cgUHjw3Ew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KaCYT94YeFl1o++ov4HQQnRx4R1OEcpIKK6cm9EuvZM=; b=Toc1DFB5nHdJaPkTar4DKJpNWYb0BbBlTkyjDlFp/Fkv2o+iQyhO+qzt9zTbpaN1y0Z8USk/5xBAaqZxaMW0sO3VBnf1RpUOvRapH5qtERTy9xyamiAVmlj3B7V7zpPd/7udXP8w+iVEmQXhZSIm7s4q8dF03sCU+54dFD0yV2E= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:38 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:38 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 28/37] MIPS: bitops: Use smp_mb__before_atomic in test_* ops Thread-Topic: [PATCH 28/37] MIPS: bitops: Use smp_mb__before_atomic in test_* ops Thread-Index: AQHVd+P+drhGMZ3mjES1+6XBK14pCg== Date: Mon, 30 Sep 2019 23:08:38 +0000 Message-ID: <20190930230806.2940505-29-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 88d52176-3a5f-4077-06f8-08d745fb20ba x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2582; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(1496009)(39850400004)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(14454004)(256004)(6512007)(81166006)(316002)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(478600001)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002)(101420200001);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ClDyjq0oUFnGMxyaO0DsvvRwkyK/6FgC7VVzJFKsMOnBatjrCZ0erOVmj+pTaalH2b8d1RWftKWB8tsC0USin8FLS8IqAAznrz4v8r1hRvuL0carumOU199ZL7F0tVY7zcgM3DCeF8g/+jGD/S8OvPmq3anIhByJHBYqo98mNAma6lYy2R/zYN6FqFesmcpl6WngJmZ7as/66jNg1DzgQOreozsDSfO6njvaBiP3tNAlj0yDUQfQtvxb+OocW8gxXJWtvCuSnzdXiObZBwqO8yVVxLISPkro+IurmQZewA5v5F+FRVBO9MsC6zKTZFwrE92BCZfMTg5DCuGaT3gyUmVIPqrjVNwz8v6uX68weIDhv/LCVLu7jtna8qII22vqZdW0Iu/kwkGTP9vhhfcdtqH9BIT/4ZaKLqiNEtl3IDI= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 88d52176-3a5f-4077-06f8-08d745fb20ba X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:38.6263 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 2YT65Iy3T9Sa8pxHR0z6XU/tPTj2b5fYntwsRBoJukqkdcXPu5tnPymDQo399cclwWDbXzpVyhY823khiHNJcg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Use smp_mb__before_atomic() rather than smp_mb__before_llsc() in test_and_set_bit(), test_and_clear_bit() & test_and_change_bit(). The _atomic() versions make semantic sense in these cases, and will allow a later patch to omit redundant barriers for Loongson3 systems that already include a barrier within __test_bit_op(). Signed-off-by: Paul Burton --- arch/mips/include/asm/bitops.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/mips/include/asm/bitops.h b/arch/mips/include/asm/bitops.h index 9e967d6622c8..e6d97238a321 100644 --- a/arch/mips/include/asm/bitops.h +++ b/arch/mips/include/asm/bitops.h @@ -209,7 +209,7 @@ static inline int test_and_set_bit_lock(unsigned long nr, static inline int test_and_set_bit(unsigned long nr, volatile unsigned long *addr) { - smp_mb__before_llsc(); + smp_mb__before_atomic(); return test_and_set_bit_lock(nr, addr); } @@ -228,7 +228,7 @@ static inline int test_and_clear_bit(unsigned long nr, int bit = nr % BITS_PER_LONG; unsigned long res, orig; - smp_mb__before_llsc(); + smp_mb__before_atomic(); if (!kernel_uses_llsc) { res = __mips_test_and_clear_bit(nr, addr); @@ -265,7 +265,7 @@ static inline int test_and_change_bit(unsigned long nr, int bit = nr % BITS_PER_LONG; unsigned long res, orig; - smp_mb__before_llsc(); + smp_mb__before_atomic(); if (!kernel_uses_llsc) { res = __mips_test_and_change_bit(nr, addr); From patchwork Mon Sep 30 23:08:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167753 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1371117E1 for ; Mon, 30 Sep 2019 23:09:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DCE8B2086A for ; Mon, 30 Sep 2019 23:09:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="pUve4ULp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732709AbfI3XJF (ORCPT ); Mon, 30 Sep 2019 19:09:05 -0400 Received: from mail-eopbgr690119.outbound.protection.outlook.com ([40.107.69.119]:48448 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732650AbfI3XI7 (ORCPT ); Mon, 30 Sep 2019 19:08:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hsz5hlypEcliCG08pwWFFJfGYGe6Z5JOF+R5F6002pY45qF0mGP+CbJB1l7BTFMAZBjiXCa127lP3/ODZ1J9Wnolrw2M89sYvlhqTNXcQRzbcy08vDKBEjuvUiPEHlt1vaHAE97YA5mjhjKsMLfsm7NnfrgoU2wD6PFrWWyM/2DEtPQN1WrvyXmHYjtnInBqnG4fLCXiTUinQa5Y16C+QhLcR0Roo9ppyiROJdVmbsCEqwozXY8ktCUgLgJ7pmjFLbzkmj0LoHlf56vEcrCGWAvMKFEePyCgde0+bkYRUSZy9e03kLF4QWJcdWbMRIhqk0tQSw5ULom5+UsTZmiYow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=B6/Ez4vkXZURVDHG/O+B8Niebtwqn0sJ7vIuPvLgslk=; b=ho07t5t88Hw/QT3+FiBXDpgEoF3+5Kdw3J6WW4K+KxNu9RhI7KbBn18IvL3pGolfu9O4irxLy+kafkASOs5QbajAMdgdbXQh+NajBcWHnP/qkAe4kw3/SGaKez/ifgzbytqx+4jrrOpJjYO83EHiX6zDSYka44sUbKPmZuCfnZtbLdAw0Dby00/SniLnLnqfv7bH3JEEM86xlekvuD0r1be0zoaNiondXZ0YiokSf5Uwpp/CfD/JcpCxRgapIhJ0wJP5tTq99JHzxq0YB0XoVf9dJik8F+ZySZUGY0iUI0nTX7OQjJiNl1DanOhNhG9yRGEK2qMsDD2LBd6hZQDKiw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=B6/Ez4vkXZURVDHG/O+B8Niebtwqn0sJ7vIuPvLgslk=; b=pUve4ULpiuNEVUaMCXiMmzZSlWRAdJiB2n4NC4f6EcPMWxHuVPeRpubHb7x/ubpbmNdYwBqE8InT0vVLBF+BGyuWkQgrEs0A4cmNPaxJOOdeQ4248r9e9gJ0tcOWrLUQtiwKKYOibtJbn0XI5zbs7/xPgNq+x32Mz6E/pp01ot0= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:08:39 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:08:39 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 29/37] MIPS: cmpxchg: Emit Loongson3 sync workarounds within asm Thread-Topic: [PATCH 29/37] MIPS: cmpxchg: Emit Loongson3 sync workarounds within asm Thread-Index: AQHVd+P+ax0/6CFtlkmWfuxHQZzrbQ== Date: Mon, 30 Sep 2019 23:08:39 +0000 Message-ID: <20190930230806.2940505-30-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bb85eca4-3ecc-4d76-728d-08d745fb213a x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1107; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(1496009)(39850400004)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(14454004)(256004)(6512007)(81166006)(316002)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(478600001)(2501003)(6436002)(50226002)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002)(133343001);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: HNsP2bWBUOyUlvZjUirbVNntXhox8XIr247t+ZkRbLMGP16VHiosYBMNWzdjP4ZGroze98LSu2wd3xSZTxvX80PQIlUCzSSvvFRZmoux+s2FbiFWZhxm5cYElprfH3y9vkNWdbE8Ks8dMCClSs+7fIQXFgaEf3j0g33T7WazcJnnbfMVibGWzhJjrgRdOihML7oJ3vZEVvf5kNfj5q9ka2g7WRBh2+pcMqFrT41fbOx2kO6xdle73NcuyGzBuvAf5hUQCAz9OUSCarS2+x7qwjkJp5xt1Mcy5e1qVzGYgxGeaNTEfn3CHIVQp9HeOAokMtxy3QIyXZqEEZ85IKw3XF7BGCRi0WDmAPeUUhxlNKg07fCM8TyODoIZwTMdLJX+L9YK2N32sdks44IKO4oYZR8c4V2wJ13Yw9S71JbGVtQ= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: bb85eca4-3ecc-4d76-728d-08d745fb213a X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:39.4730 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: rQG1Y9ojiTOYrt1ajS3NjVcOwt2fczA4W0z7xyBB371lvjOX4uY9JxKCLQusOQSLe1B4taFCXT60SIqPafJGUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Generate the sync instructions required to workaround Loongson3 LL/SC errata within inline asm blocks, which feels a little safer than doing it from C where strictly speaking the compiler would be well within its rights to insert a memory access between the separate asm statements we previously had, containing sync & ll instructions respectively. Signed-off-by: Paul Burton --- arch/mips/include/asm/cmpxchg.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/mips/include/asm/cmpxchg.h b/arch/mips/include/asm/cmpxchg.h index 5d3f0e3513b4..fc121d20a980 100644 --- a/arch/mips/include/asm/cmpxchg.h +++ b/arch/mips/include/asm/cmpxchg.h @@ -12,6 +12,7 @@ #include #include #include +#include #include /* @@ -36,12 +37,12 @@ extern unsigned long __xchg_called_with_bad_pointer(void) __typeof(*(m)) __ret; \ \ if (kernel_uses_llsc) { \ - loongson_llsc_mb(); \ __asm__ __volatile__( \ " .set push \n" \ " .set noat \n" \ " .set push \n" \ " .set " MIPS_ISA_ARCH_LEVEL " \n" \ + " " __SYNC(full, loongson3_war) " \n" \ "1: " ld " %0, %2 # __xchg_asm \n" \ " .set pop \n" \ " move $1, %z3 \n" \ @@ -108,12 +109,12 @@ static inline unsigned long __xchg(volatile void *ptr, unsigned long x, __typeof(*(m)) __ret; \ \ if (kernel_uses_llsc) { \ - loongson_llsc_mb(); \ __asm__ __volatile__( \ " .set push \n" \ " .set noat \n" \ " .set push \n" \ " .set "MIPS_ISA_ARCH_LEVEL" \n" \ + " " __SYNC(full, loongson3_war) " \n" \ "1: " ld " %0, %2 # __cmpxchg_asm \n" \ " bne %0, %z3, 2f \n" \ " .set pop \n" \ @@ -122,11 +123,10 @@ static inline unsigned long __xchg(volatile void *ptr, unsigned long x, " " st " $1, %1 \n" \ "\t" __SC_BEQZ "$1, 1b \n" \ " .set pop \n" \ - "2: \n" \ + "2: " __SYNC(full, loongson3_war) " \n" \ : "=&r" (__ret), "=" GCC_OFF_SMALL_ASM() (*m) \ : GCC_OFF_SMALL_ASM() (*m), "Jr" (old), "Jr" (new) \ : __LLSC_CLOBBER); \ - loongson_llsc_mb(); \ } else { \ unsigned long __flags; \ \ @@ -222,11 +222,11 @@ static inline unsigned long __cmpxchg64(volatile void *ptr, */ local_irq_save(flags); - loongson_llsc_mb(); asm volatile( " .set push \n" " .set " MIPS_ISA_ARCH_LEVEL " \n" /* Load 64 bits from ptr */ + " " __SYNC(full, loongson3_war) " \n" "1: lld %L0, %3 # __cmpxchg64 \n" /* * Split the 64 bit value we loaded into the 2 registers that hold the @@ -260,7 +260,7 @@ static inline unsigned long __cmpxchg64(volatile void *ptr, /* If we failed, loop! */ "\t" __SC_BEQZ "%L1, 1b \n" " .set pop \n" - "2: \n" + "2: " __SYNC(full, loongson3_war) " \n" : "=&r"(ret), "=&r"(tmp), "=" GCC_OFF_SMALL_ASM() (*(unsigned long long *)ptr) @@ -268,7 +268,6 @@ static inline unsigned long __cmpxchg64(volatile void *ptr, "r" (old), "r" (new) : "memory"); - loongson_llsc_mb(); local_irq_restore(flags); return ret; From patchwork Mon Sep 30 23:08:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167773 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 44C8114DB for ; Mon, 30 Sep 2019 23:10:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 18BF82086A for ; Mon, 30 Sep 2019 23:10:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="Am5jpH+h" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732752AbfI3XJS (ORCPT ); Mon, 30 Sep 2019 19:09:18 -0400 Received: from mail-eopbgr820129.outbound.protection.outlook.com ([40.107.82.129]:60959 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732748AbfI3XJS (ORCPT ); Mon, 30 Sep 2019 19:09:18 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A7/vdmGj1qntGxcDP1emfRp3FS5N3s9C0lThKFF7Hjo1DPrWUnFgxVG1wPMj4D/hmJozm1mrOZTnuF0/sux8vc7Uz5o5pA/BqHTwIHcF2PP8XKqxQKsnp3VUC1qWIo/BmNBSkXZRvKLiuCjCshm4Q+He69uCp5wgIUM+fsIKk7p1Gsry4UWotyeFS5Wj9YY2kQZf5pE/u15SY5LEfgMnAtKWtsBIpgAeQH7YhmP9JMwTmzejEzmM3OaFQt+bR2f9YBASea8pmoOzVITCXwhrsN3ExKjNkmiaz87JemCwaVWEgEODEK6HD4gZnB9xiHO2EJ1Dv3FWnojdK5ipGuN3VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cU4Uc0mo+O5PVjJGC0ciFRRf3CAmp/HGzg922sq6WDI=; b=RB5i4/PIJbT1715HZFZbBPWp+I3ZlH8kORgTbZMrniPsYyuZdISMJt+4pVjNx358eX8FXma8MfGcSHz+IIQC5kJ5SCd50/g2k0AUdRbBD/vQv1x6eKnmSFIsk+eJtOHpyzrjuXNhxEAJeMGPnuig7M0eSWx+ZsagFzxx/L+4Kbk35JITslmMn0428Zuqdebr1NDyPorPP9HB4ml66u7u+nV91ze3EjRg9X4ahpx/kZtg26YfdYTv+1SDe/5FZTSIPvdycYolduiGhpKMOrBJjlNQv/PFpCWqU2Mk1JdomKBQgmeUCbeGiANM3VvYa8ufPLeNg6ZDRZQ+dUGQodi5pA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cU4Uc0mo+O5PVjJGC0ciFRRf3CAmp/HGzg922sq6WDI=; b=Am5jpH+hYsRd+avJVN27mMhwMSXoOX76p7kS+McjWSVFsEyceHZ26oLczG5FnxKKzbutqUIa//ko1ESpzqTMCaAeTjsgHC6/Rk/QMhQVWsU9jA0tAe1CMqv5CX+TqQtrMQBZ+8lphZCVuQ3udB6TP+8jxUd+O6QiZu+i6IvzJhc= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:09:10 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:09:10 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 30/37] MIPS: cmpxchg: Omit redundant barriers for Loongson3 Thread-Topic: [PATCH 30/37] MIPS: cmpxchg: Omit redundant barriers for Loongson3 Thread-Index: AQHVd+P/34JQxmanBEabiwRK/UX20A== Date: Mon, 30 Sep 2019 23:08:40 +0000 Message-ID: <20190930230806.2940505-31-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: be9a93b3-c89e-4236-71cc-08d745fb21b6 x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6790; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39850400004)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(14454004)(256004)(6512007)(81166006)(316002)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(186003)(478600001)(2501003)(6436002)(50226002)(6666004)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002)(133343001);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: tm543mOujwZOy5RZLSJZ7ZVFt8AL/BITyg43+5TszTsUWL76vCZepL4tuwuoAKo71DX+wEX3OVVpasPB1PLObioqd5TL9srlbi+ux6NuyviGjsPUoWe3IGYMIJ77Ecs7W2FoFB/3KvC7V509AIOZTeVuIORpW38lrq8bSpXclIOu17KpczWWHGrwXruvJBgmqpyxe1cHzYDoQ7ZaMaAox/hBlGjtyIa9qX8hpnZl7nZ8DKR5e1FkhgAF/+EcaNgxwNgS1fkHTMryU7sQbah6+QArp8CBRStfiEwLN74pkkqUH1tfYl5GZVQGcONoru+lzajRRTVdbNYeXX+Q/uuFTn326D6y35Otdsi9ujviV6LNHLTa8RYXsQs7ZnPYIxuKCfuNVG1y0SGuwn9YDdKp/jYpI1ugk6w6PZCqUOFmdMk= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: be9a93b3-c89e-4236-71cc-08d745fb21b6 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:40.2916 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: dInZDDzcOQB6jQRqIfF0QtO2RIHfa98dzJwJsDKRTx6+hyHodX+04+uZlTzM2F5s9fg9DoMMqlQ0igGGFaFKQQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org When building a kernel configured to support Loongson3 LL/SC workarounds (ie. CONFIG_CPU_LOONGSON3_WORKAROUNDS=y) the inline assembly in __xchg_asm() & __cmpxchg_asm() already emits completion barriers, and as such we don't need to emit extra barriers from the xchg() or cmpxchg() macros. Add compile-time constant checks causing us to omit the redundant memory barriers. Signed-off-by: Paul Burton --- arch/mips/include/asm/cmpxchg.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/arch/mips/include/asm/cmpxchg.h b/arch/mips/include/asm/cmpxchg.h index fc121d20a980..820df68e32e1 100644 --- a/arch/mips/include/asm/cmpxchg.h +++ b/arch/mips/include/asm/cmpxchg.h @@ -94,7 +94,13 @@ static inline unsigned long __xchg(volatile void *ptr, unsigned long x, ({ \ __typeof__(*(ptr)) __res; \ \ - smp_mb__before_llsc(); \ + /* \ + * In the Loongson3 workaround case __xchg_asm() already \ + * contains a completion barrier prior to the LL, so we don't \ + * need to emit an extra one here. \ + */ \ + if (!__SYNC_loongson3_war) \ + smp_mb__before_llsc(); \ \ __res = (__typeof__(*(ptr))) \ __xchg((ptr), (unsigned long)(x), sizeof(*(ptr))); \ @@ -179,9 +185,23 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, ({ \ __typeof__(*(ptr)) __res; \ \ - smp_mb__before_llsc(); \ + /* \ + * In the Loongson3 workaround case __cmpxchg_asm() already \ + * contains a completion barrier prior to the LL, so we don't \ + * need to emit an extra one here. \ + */ \ + if (!__SYNC_loongson3_war) \ + smp_mb__before_llsc(); \ + \ __res = cmpxchg_local((ptr), (old), (new)); \ - smp_llsc_mb(); \ + \ + /* \ + * In the Loongson3 workaround case __cmpxchg_asm() already \ + * contains a completion barrier after the SC, so we don't \ + * need to emit an extra one here. \ + */ \ + if (!__SYNC_loongson3_war) \ + smp_llsc_mb(); \ \ __res; \ }) From patchwork Mon Sep 30 23:08:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167771 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 20EE117E1 for ; Mon, 30 Sep 2019 23:09:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0044E2081B for ; Mon, 30 Sep 2019 23:09:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="jeFB7g9n" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732765AbfI3XJV (ORCPT ); Mon, 30 Sep 2019 19:09:21 -0400 Received: from mail-eopbgr820129.outbound.protection.outlook.com ([40.107.82.129]:60959 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732672AbfI3XJU (ORCPT ); Mon, 30 Sep 2019 19:09:20 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D1qcQNtRSgZshGrTX6zvHOPr9mhrlogJ6+NF1KgdW9RqT7CjpE4U71I1Xg6JnThf6RYoK2Xtgy+/gaw2iU9ggj8lzkNtc8+jZWBVCaPDPCtnkYXyJg+1i7Fhv3EWlTR8fXnjYzbl9ts5F+L3MpXU0s8lVYIySkVsVZ96qBYMla6a1vSWlTBAJyXPO/vFV4fbdoljfEtgqmLA53B+a2dIf+eoqH4zA+FJfH5UerKYRfIpdI5uth0H5LSfT1w9MkXMiUGrTT0FUu7AdMgQW7OySWLWhcPSv3SGvHhEQYOoZd8j8b3l4JhmL4GADHNytEbljbKesGp+M2v0p0pU380WoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=P0SLHaYaFGFzK6n/63oO+4z01N7bEclUItN7ToHZMX4=; b=EbmcaPOyfeJW4v7TWJ6JLtwAUqdSOnhk8hyNHQf6YtQvPGAu9B6fQ/65tTicZ1sAXbnLewrA0X5Dnz8/IrCzkBqXW5+MUm8bUoh2xEw+LbuQD1GvUfyrpl8vgKIdKC7f8Dv4K81Mz8CfejxigNPPicWaO/08xSyEnNMc2dzcabqfcduGprnpznZgVXdGaLa4J2jgM7yoRCFARvp2LH+rfjQ2sxxugpErnLLjrYINHQwBVmqIrYtPs8kmwnvfjbKLsO1JBcAWMvi7RNQ2Yz2t1IvY0yHfEjTSmIjuCjrAEnblv83ECr96F6jqAVDQlbY8ctZaGnMxr8UNsOe5vqz3mw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=P0SLHaYaFGFzK6n/63oO+4z01N7bEclUItN7ToHZMX4=; b=jeFB7g9n+4lyoFwvIMefS/35FikGhY4MAat1hTMF3p8QzUczfja2OFvcLnGlINshju0JBTJLnjYJEPUkmppn8vXB79YZcpfHssbT4oQV3Sdcy+fLaBbiXoMJ4JLsdkaeZRZOfKm7+pGqH2oo0E3cDXTjZBBvVDF9mvZRPYTCOqQ= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:09:10 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:09:10 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 31/37] MIPS: futex: Emit Loongson3 sync workarounds within asm Thread-Topic: [PATCH 31/37] MIPS: futex: Emit Loongson3 sync workarounds within asm Thread-Index: AQHVd+P/6LGFBO66C0WgJGpQYiO+9w== Date: Mon, 30 Sep 2019 23:08:41 +0000 Message-ID: <20190930230806.2940505-32-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4ff78ddf-ae98-4eca-5e4a-08d745fb2255 x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:628; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39850400004)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(14454004)(256004)(6512007)(81166006)(316002)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(478600001)(2501003)(6436002)(50226002)(6666004)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: FYC4ZXZLIfUFKlE/zWT3YFbQMYUYTz6OxA6V1bI2bJe5k0wFlOMbV+CT0mvbhOroeU74Enljg0edMim7u/T9KZG5zeM75zZepPrFfEh1OoI0pitZDyx583Oq425WlOtIOwmpNy23UsZyBPV08eEBEPMP72qumF9xe9Qb5BAL0VXENz6633X63YD1jAbHvegOp6CRbNhp8nJpyXNF2p/WRrj6Zn5e6KnWoAvDhlhzVLhIdGU0Yg+pxI9bE8+8dgyZrzSNYs/b+YtzjlFD9CpHOQJh6qcZT9GnpBTiTz47CtQIL3yJ37c5LXnmSAptLrieh3YLlmWNJ2dJafpRvBgGTJAh3CwY4UpeOiUgFoBLHHaANPlBumxnaBRAabYBAJzFDSpnG+E5HnTycapeyctWlUoOVemjlcr67vrua53WGNM= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4ff78ddf-ae98-4eca-5e4a-08d745fb2255 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:41.3771 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: KHu5Ny7z/f+IPEXnw6PdwwzvtlEHSgaftshCG3I7V7K/jHTgjl3CoKTnhRFFDQQSHaWGOuNBN9BwWE28GXzUzQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Generate the sync instructions required to workaround Loongson3 LL/SC errata within inline asm blocks, which feels a little safer than doing it from C where strictly speaking the compiler would be well within its rights to insert a memory access between the separate asm statements we previously had, containing sync & ll instructions respectively. Signed-off-by: Paul Burton --- arch/mips/include/asm/futex.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/arch/mips/include/asm/futex.h b/arch/mips/include/asm/futex.h index b83b0397462d..45c3e3652f48 100644 --- a/arch/mips/include/asm/futex.h +++ b/arch/mips/include/asm/futex.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \ @@ -50,12 +51,12 @@ "i" (-EFAULT) \ : "memory"); \ } else if (cpu_has_llsc) { \ - loongson_llsc_mb(); \ __asm__ __volatile__( \ " .set push \n" \ " .set noat \n" \ " .set push \n" \ " .set "MIPS_ISA_ARCH_LEVEL" \n" \ + " " __SYNC(full, loongson3_war) " \n" \ "1: "user_ll("%1", "%4")" # __futex_atomic_op\n" \ " .set pop \n" \ " " insn " \n" \ @@ -164,13 +165,13 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, "i" (-EFAULT) : "memory"); } else if (cpu_has_llsc) { - loongson_llsc_mb(); __asm__ __volatile__( "# futex_atomic_cmpxchg_inatomic \n" " .set push \n" " .set noat \n" " .set push \n" " .set "MIPS_ISA_ARCH_LEVEL" \n" + " " __SYNC(full, loongson3_war) " \n" "1: "user_ll("%1", "%3")" \n" " bne %1, %z4, 3f \n" " .set pop \n" @@ -178,8 +179,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, " .set "MIPS_ISA_ARCH_LEVEL" \n" "2: "user_sc("$1", "%2")" \n" " beqz $1, 1b \n" - __WEAK_LLSC_MB - "3: \n" + "3: " __SYNC_ELSE(full, loongson3_war, __WEAK_LLSC_MB) "\n" " .insn \n" " .set pop \n" " .section .fixup,\"ax\" \n" @@ -194,7 +194,6 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, : GCC_OFF_SMALL_ASM() (*uaddr), "Jr" (oldval), "Jr" (newval), "i" (-EFAULT) : "memory"); - loongson_llsc_mb(); } else return -ENOSYS; From patchwork Mon Sep 30 23:08:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167757 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16F6914DB for ; Mon, 30 Sep 2019 23:09:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE97F2081B for ; Mon, 30 Sep 2019 23:09:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="n4mHBYL1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732772AbfI3XJV (ORCPT ); Mon, 30 Sep 2019 19:09:21 -0400 Received: from mail-eopbgr820129.outbound.protection.outlook.com ([40.107.82.129]:60959 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732761AbfI3XJV (ORCPT ); Mon, 30 Sep 2019 19:09:21 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mOpPVlg8QpAXgekZqwzo2V3veVHeLy8Vz+sJHrDVn85ra7aDQvauZbZZjmTTpliCbb2dHRoSAzJMY8Kx+xBld8mc+VsSuL+pTsgYcmNbjU2KbdIyBhhUtqy8f0s7uZdsBrMgdGN/4vtlS2UpXkIjz+ChIQIbJ3T7V7TKAu3+xFdq1JOS6jwMOuWg3SjSSrKlR9//JFvdiNyYCJPGUieVhi13X1SlXv4euQuYnZBbpDchwFjYfuJDQnBasCcRKhhbTJYpF0qLiK1jvvREpI5qK2titScx58muS9fJtGLeIzA8gEU/E8i6UAXz1z+d7hjRGc3izJOX6d3QsboSURbjPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EmlD0QaPvWpPJoRxuK+3Qa+UxcFEj5kWoedu2Uz5ojE=; b=blFS1ZIx4YxEoa4f8U3/h014B/1Fwe9pZ9eqYqxWXn7ZY1p+N9+xlvBzUZUwseddImUbOgSUhu0/lfGygqYX2K4ITY9WvVIibh7NeGjcrUk2Mz+TjL7RG6W9COujGTJuFdDEcHJ8rixp8Z5PS+fxgz5hBIhOl6s7x9p9dcOWoYtaurc7NFdJtI8QkfPfqKXM0Y4c4ruQNPe7lNHBCSwsYvZGmW3FHBGC2AkJODr4uqZ6ZYc0ew+Azup8UYQ+F7jHrqxEPZKOsijChzQkYlC0WHIm7k/8DM0G/JJ37UtOh4cIxOXAt66YuAAh+wjaVrOro/W6/kDoX5y39LwMAEBbUg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EmlD0QaPvWpPJoRxuK+3Qa+UxcFEj5kWoedu2Uz5ojE=; b=n4mHBYL1KH8nMUwUgOPpX6GUGUmnoydSTiSZ3ozrnHPOluSm3F33DtOImKfesfKka/ktwij4Dg6pBVUV4uHE41qdbZ9QavRe9sV/4efVsI7rEsCksCnPMc80bwC6v05BH3nHibkZa6qiPjo8TieEgbdvzxOzLTbyqOB0R3emhCs= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:09:11 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:09:11 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 32/37] MIPS: syscall: Emit Loongson3 sync workarounds within asm Thread-Topic: [PATCH 32/37] MIPS: syscall: Emit Loongson3 sync workarounds within asm Thread-Index: AQHVd+QAF39mXHIVtk2gNcjfUb4ejw== Date: Mon, 30 Sep 2019 23:08:42 +0000 Message-ID: <20190930230806.2940505-33-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1510cc6c-703b-4df3-bc9c-08d745fb22db x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2657; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39850400004)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(14454004)(256004)(6512007)(81166006)(316002)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(478600001)(2501003)(6436002)(50226002)(6666004)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: dHRk9ulhCtAVY060Ap1PRTGSda90OAY1ED2beqRRDi6PDpXPp4LaMCZCN+JDlUsftiTj1mQPE3TAdwXczBhNdjRVBg6AJ2T/uGh/nQotNACFL80PiR6UEQzUlo2K9ar4UiM4cGcqQGLBMs90bcFFa62gldU8ItmHUXmXd29dpv/4/de8HiufjcIWsRQrXttuJvcpZS6d/bgpZOkBwkK0Cb36UwEnpcKaNHQnaDha2xZidqmBPo4/Mv0ekAwkW48XmVQg2ono3cARNiFzc7OXgIuDAV7vX+rizBb23l3JbNmmLjqWsIS9s5k49ighQ65NonDwFTx6BS2+8W4qTjxSpEGL/8FOQnEyUcF5l3U+0u/4y9KaeQ/jrblHCmpORxnroKxu0QN/PIyxRm/DbCIi2ltqpxI7Rm7K92Zoj51JrXI= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1510cc6c-703b-4df3-bc9c-08d745fb22db X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:42.4416 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: CT2GwZ48ThxDKaDCuGWTvN3qzMByq2HPQDyt95iYEBKOlezMb1XHpf4cgJYrpj8k6fxjFq+jF4s/ccOANLl10Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Generate the sync instructions required to workaround Loongson3 LL/SC errata within inline asm blocks, which feels a little safer than doing it from C where strictly speaking the compiler would be well within its rights to insert a memory access between the separate asm statements we previously had, containing sync & ll instructions respectively. Signed-off-by: Paul Burton --- arch/mips/kernel/syscall.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c index b0e25e913bdb..3ea288ca35f1 100644 --- a/arch/mips/kernel/syscall.c +++ b/arch/mips/kernel/syscall.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -132,12 +133,12 @@ static inline int mips_atomic_set(unsigned long addr, unsigned long new) [efault] "i" (-EFAULT) : "memory"); } else if (cpu_has_llsc) { - loongson_llsc_mb(); __asm__ __volatile__ ( " .set push \n" " .set "MIPS_ISA_ARCH_LEVEL" \n" " li %[err], 0 \n" "1: \n" + " " __SYNC(full, loongson3_war) " \n" user_ll("%[old]", "(%[addr])") " move %[tmp], %[new] \n" "2: \n" From patchwork Mon Sep 30 23:08:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167769 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EAF96912 for ; Mon, 30 Sep 2019 23:09:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C04942081B for ; Mon, 30 Sep 2019 23:09:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="CxFp7+KB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732495AbfI3XJr (ORCPT ); Mon, 30 Sep 2019 19:09:47 -0400 Received: from mail-eopbgr820129.outbound.protection.outlook.com ([40.107.82.129]:60959 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732769AbfI3XJW (ORCPT ); Mon, 30 Sep 2019 19:09:22 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cP6VM++DGr9zafJlBBHtO2VPXKFxhqDdcHwDwSoA/3DuDEQEKXUAU1el4zuyCTmnEZedpKe0EWV/vY4ZNARcwjM9BDgi0kNzBihi/Gx5wKF25ypXs7zY6h8jsqryZU2nSwcxEsvG9iUVKBv1mrVRPO12inOHFpOJvQf3Vo/5CDUuVfC4boDn2jsIMe0jEpRT10O/QTIZvIoaSo/Rtym0BRscbpsS/YZqCJklI3rPXPtpSl9TEIES1WzlLxC/g/eu6cxpSF6U6OBPUoEvSYzC3vjVKaC/NvufJco5LCezGJ+4uFX34yGqSmqMeqFKQohc9ri4Pzi3M2RKRnDIEXDp9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Vl7osInJbQCZYE9OyTPsqX3Ns4VCo+RgudalhIuW48U=; b=Ztcg6cxy2l8fih5WDspam+JXl2SZuJ1iRqgdBrSrDdhnOBaHg9JMqa3ISKFnUH7L2m6PfgeVF226mViCfLaWv9/03Ffj83uAr8xTXSAASQeOi3Csh74XsQoE1RcfMaF9IjX7UonXxeLpMx6wHK2ihgNtHw991/Jz/cBf6z2jDztcuzDoxLKVvo6p+TumQB4QiD2c4zT9ZgLeDHrbJTe6z8/4wrkIgfiwD46iZ8GTLLM40LCZ64uiViZlFZOAAhuZWcqEuLOqRJFP2CJM7nviZjwyyTTh/mFiLSReMX2ZEgpnoB3tXupXaBqRX3kT4mWAGYIu1uAUdvpuj6ygqCEeTQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Vl7osInJbQCZYE9OyTPsqX3Ns4VCo+RgudalhIuW48U=; b=CxFp7+KBwGjVo8hjcKdE5yi6yHmt45WPIFzU+Bq4U7BIDHN1jKmSbteaI5DzXpnuxPjyn5lXi9ti70SG0DmXCPRHOWJYytghQv6RUKcVs3a4d/CqjLtEKWwfF6lcN1gOqn/D11twkbPdONA1FSi6NWmTobz7OaypRxcOw0utf0c= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:09:11 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:09:11 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 33/37] MIPS: barrier: Remove loongson_llsc_mb() Thread-Topic: [PATCH 33/37] MIPS: barrier: Remove loongson_llsc_mb() Thread-Index: AQHVd+QBGBvr0LXUB0q3rp1IZ4o/ww== Date: Mon, 30 Sep 2019 23:08:43 +0000 Message-ID: <20190930230806.2940505-34-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 5f8a0fc0-0e62-47d2-9bd4-08d745fb2380 x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39850400004)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(14454004)(256004)(6512007)(81166006)(316002)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(478600001)(2501003)(6436002)(50226002)(6666004)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ApxVF9qBnojsfU2HMgpvSir3aDVCPXHb87d1EXmvpmGe3nzBEBWgVrlaklhb+WVGoRU8PJJ1YS97eFR71eAZiY2JLdxkuoWmi+5a0McWVkKvE3O6tyaUKq7Hrw6rlcX/dWOuGnvQYRo5Z6q/FG0ndhMU/QJEdOybo6PKkcGvHV1vZcgt3PzczjmLX2M1qFQjWWuNJKPvEgPrGM0+pH/uokRMvYBjPPwIofa4HeRkG4CTaEIuhIftwa5wmOr8i9pMqRNfVa9WScBJf2qddshjtKJJatQeLbvbI/COPQg6c47HrqTarq3x/AX9b+XbtP9zy4+Wvzas5E1sCsTlBkZTW7C5ISMc+pPeS4eZPteZIVNI7fmSquHG31MsgG9CfCC9uWCd4Xy+nqsO47ng2I/mREM1oc47PmGT8fIzYxQsYZU= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5f8a0fc0-0e62-47d2-9bd4-08d745fb2380 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:43.3252 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: g+hCP62m9CHW2lCRvyi9102ZU+kb860ujlY/FYDcYvTR03yK+Nr1kKbBpVGL5wZ1f6i2IJ7b+zj7jkyUaFwa6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org The loongson_llsc_mb() macro is no longer used - instead barriers are emitted as part of inline asm using the __SYNC() macro. Remove the now-defunct loongson_llsc_mb() macro. Signed-off-by: Paul Burton --- arch/mips/include/asm/barrier.h | 40 --------------------------------- arch/mips/loongson64/Platform | 2 +- 2 files changed, 1 insertion(+), 41 deletions(-) diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h index c7e05e832da9..1a99a6c5b5dd 100644 --- a/arch/mips/include/asm/barrier.h +++ b/arch/mips/include/asm/barrier.h @@ -121,46 +121,6 @@ static inline void wmb(void) #define __smp_mb__before_atomic() __smp_mb__before_llsc() #define __smp_mb__after_atomic() smp_llsc_mb() -/* - * Some Loongson 3 CPUs have a bug wherein execution of a memory access (load, - * store or prefetch) in between an LL & SC can cause the SC instruction to - * erroneously succeed, breaking atomicity. Whilst it's unusual to write code - * containing such sequences, this bug bites harder than we might otherwise - * expect due to reordering & speculation: - * - * 1) A memory access appearing prior to the LL in program order may actually - * be executed after the LL - this is the reordering case. - * - * In order to avoid this we need to place a memory barrier (ie. a SYNC - * instruction) prior to every LL instruction, in between it and any earlier - * memory access instructions. - * - * This reordering case is fixed by 3A R2 CPUs, ie. 3A2000 models and later. - * - * 2) If a conditional branch exists between an LL & SC with a target outside - * of the LL-SC loop, for example an exit upon value mismatch in cmpxchg() - * or similar, then misprediction of the branch may allow speculative - * execution of memory accesses from outside of the LL-SC loop. - * - * In order to avoid this we need a memory barrier (ie. a SYNC instruction) - * at each affected branch target, for which we also use loongson_llsc_mb() - * defined below. - * - * This case affects all current Loongson 3 CPUs. - * - * The above described cases cause an error in the cache coherence protocol; - * such that the Invalidate of a competing LL-SC goes 'missing' and SC - * erroneously observes its core still has Exclusive state and lets the SC - * proceed. - * - * Therefore the error only occurs on SMP systems. - */ -#ifdef CONFIG_CPU_LOONGSON3_WORKAROUNDS /* Loongson-3's LLSC workaround */ -#define loongson_llsc_mb() __asm__ __volatile__("sync" : : :"memory") -#else -#define loongson_llsc_mb() do { } while (0) -#endif - static inline void sync_ginv(void) { asm volatile(__SYNC(ginv, always)); diff --git a/arch/mips/loongson64/Platform b/arch/mips/loongson64/Platform index c1a4d4dc4665..28172500f95a 100644 --- a/arch/mips/loongson64/Platform +++ b/arch/mips/loongson64/Platform @@ -27,7 +27,7 @@ cflags-$(CONFIG_CPU_LOONGSON3) += -Wa,--trap # # Some versions of binutils, not currently mainline as of 2019/02/04, support # an -mfix-loongson3-llsc flag which emits a sync prior to each ll instruction -# to work around a CPU bug (see loongson_llsc_mb() in asm/barrier.h for a +# to work around a CPU bug (see __SYNC_loongson3_war in asm/sync.h for a # description). # # We disable this in order to prevent the assembler meddling with the From patchwork Mon Sep 30 23:08:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167759 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 90A4E14DB for ; Mon, 30 Sep 2019 23:09:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 664842081B for ; Mon, 30 Sep 2019 23:09:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="aBJvOhCO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732783AbfI3XJY (ORCPT ); Mon, 30 Sep 2019 19:09:24 -0400 Received: from mail-eopbgr820129.outbound.protection.outlook.com ([40.107.82.129]:60959 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732777AbfI3XJY (ORCPT ); Mon, 30 Sep 2019 19:09:24 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fXOHetU42QHEeg0MCv6+ThaYvd8+DYY8JhrDco1m+cX5BS3abGKQoM9ZzMHKKvCK4u9L1t2sy8Zjc/kuLzyYJb4p1OQ4sQDu0xi582xzbfyzRxen8GcZGwKV/rRlyGvvSs91ulkwfo9e7W/KV1GpaOrd1MTckVorCpWHGqT4tvxc1fRPDI8PSe+Y9Ta9pmIjr2Iy/hyoeIorafMuAXADgcgT9iAl8kZuIP3icjpcLskKInCt+pewTRB3VSPK5uv5mZ4u0iDQbBcEaA/Cz7y+c8dh5nS+cOMcWPfof2a3MApsQbxCmbXJG5C8RpEJ5iRf3Y+lUQuzVfS2kqtjPRywPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5Oh8iGFaHrrSrAu0l0lxEekP4OgTK0dgdXb07ooT53M=; b=GShPitimI8dWEk9ykM/Po0eod9XXGH6b4KxTwFDJ1XiW1HbWul7+trtIGn2rkP7asqfLpVAI01J3+Pl66pVjTJr/dr097JRFFm1zagPUJaar1StAFGgEZ0xE/sGTkrXUGEuDrL6llnmUBqMxPcO3ZOAtqZMizjm7HyvU5/oDENaaQskzwUlYc3V1Y62xQzc/hUZ1QQxDMMTR3A+MomgVKwcJVq/wjZt6DK9v2BqonGlBhXBj6wWQaLl1/CUh1mJ4qZUUNNX7sMWgvEXU3KJwyPDmDSNfxcFTxaDJiUHhSzbi4xykw0VUSIpShk88kOJkWo1J7vDOt5khNIBhDU5KcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5Oh8iGFaHrrSrAu0l0lxEekP4OgTK0dgdXb07ooT53M=; b=aBJvOhCOlYv6B3hug9f444Dacb3VhsWadaroTb81wFzo9Yvls1yS5NoILcvCZfFp0vVohdyNChbfPlu3KnaxikdAYNkid9nznlTGP6zNpncmRnmdD2rZVRwAVtQTUSvxdnijZJm8FP1O8sT5Ey7IIuSHAnCLNzVzgYmLutMtjMk= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:09:12 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:09:12 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 34/37] MIPS: barrier: Make __smp_mb__before_atomic() a no-op for Loongson3 Thread-Topic: [PATCH 34/37] MIPS: barrier: Make __smp_mb__before_atomic() a no-op for Loongson3 Thread-Index: AQHVd+QB2C5901uTZkGZ4j2e1Mzz7Q== Date: Mon, 30 Sep 2019 23:08:44 +0000 Message-ID: <20190930230806.2940505-35-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e95359e3-2061-46ee-9aba-08d745fb2405 x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5797; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39850400004)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(14454004)(256004)(6512007)(81166006)(316002)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(478600001)(2501003)(6436002)(50226002)(6666004)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002)(101420200001);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 0xVEJ0+Hike8vH6HiFQ5zdqkxmQPmIB3hvBnS81IWNb/KzPIIuSxdCgM7Yw4r7iLRsN7oj8HUo2MdhUdl/ght4KPOSdjLrTDLx380ojE0W6jsfuKtYSZDwLDbGnZ4J3e329UZ/+Nm8qwlU6IFcPGYXEjvcmF+i8NSWc1TvZ5AGu4N+iYJ9t5Sqp3on0fwE48unvqqpFtN26hdOawcvFqReBiniTm7ese/2G0M8lAlUD+VWFLro4Dwq2dZyHybL6xx0KNLOgfLIoKDsE6VLjFI5XJtwokZunUKWyNjYgDlw3mDvOWr4YXhXUVcS1i4inP53vy+n1c+G4RAtU6VfSaLk+8oDznvrLwMC4WT3tpUEzDRbq+8CpGtJqe4WjI3hRdI7rNKzvRmjb0fTwkzOlla6mCxoG4FhlyfL7lNPnYMPg= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: e95359e3-2061-46ee-9aba-08d745fb2405 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:44.1618 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 7vOFl4ys0Qyb1LOOiP/GWyOxyq871aQlvrHqw6ZQR1nCE8sydOh080dcZ61maUzNmOTCz9u092hL61d54iAtAQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Loongson3 systems with CONFIG_CPU_LOONGSON3_WORKAROUNDS enabled already emit a full completion barrier as part of the inline assembly containing LL/SC loops for atomic operations. As such the barrier emitted by __smp_mb__before_atomic() is redundant, and we can remove it. Signed-off-by: Paul Burton --- arch/mips/include/asm/barrier.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h index 1a99a6c5b5dd..f3b5aa0938c1 100644 --- a/arch/mips/include/asm/barrier.h +++ b/arch/mips/include/asm/barrier.h @@ -118,7 +118,17 @@ static inline void wmb(void) #define nudge_writes() mb() #endif -#define __smp_mb__before_atomic() __smp_mb__before_llsc() +/* + * In the Loongson3 LL/SC workaround case, all of our LL/SC loops already have + * a completion barrier immediately preceding the LL instruction. Therefore we + * can skip emitting a barrier from __smp_mb__before_atomic(). + */ +#ifdef CONFIG_CPU_LOONGSON3_WORKAROUNDS +# define __smp_mb__before_atomic() +#else +# define __smp_mb__before_atomic() __smp_mb__before_llsc() +#endif + #define __smp_mb__after_atomic() smp_llsc_mb() static inline void sync_ginv(void) From patchwork Mon Sep 30 23:08:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167767 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 98AEA912 for ; Mon, 30 Sep 2019 23:09:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6C8002081B for ; Mon, 30 Sep 2019 23:09:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="nSgy2I47" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732790AbfI3XJZ (ORCPT ); Mon, 30 Sep 2019 19:09:25 -0400 Received: from mail-eopbgr820129.outbound.protection.outlook.com ([40.107.82.129]:60959 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732782AbfI3XJZ (ORCPT ); Mon, 30 Sep 2019 19:09:25 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nLTkSPlp7aWJiNBGE0zegV+h93v5qsgKibWC2A7paMHa2YNgWYDq2GrTex0jjFSw0SsquR/rl80yQ5AwaxN/Vp2eCVcWXa5wJk/tTm2N6mMkiLqX438xFxhwYDOKKzP49O+hzpDiOzNzHpjYnggJAoRaHul3jyU7ot2kBv0M7/LBjwaEsVVPrjI1u2wm7+naH2EKk7pQwAWS1t0NCNmpt5S7M+yUiiRs0ycINQlYan4T7y0q77/B+wAJdqh+vDmqH72iYOD80PsHvk6YyYOlCaQGCNBfKN2U6vgVJM/GcUYESngbwnqSZbcenfsl3egsqRuJtze/ioo6nDTanKdZ1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kDvKslP4waykgwOT3pICa4cjuCwk8SfOxtgfBgmSfb4=; b=Q3UDbVA0rEdmAZrDkXGJrt0Z3KAOsBc4kfwRhvNsmbEto+KAlkyIGbesTIawlRfOSYkYCBp2P0N4txOlUqgb8JyfkGieOxUFjKsLiMRp5Dv0C/DEMXRVtffcgER6KNjtMwM0IVi7ToK+8VaB6xkcW8g3FtCTBs82wmDJs3jfdEa+xhVNzs4gIp2Xtb3o0noqdmQrrEVUDsmendrMhmS6QYwa0PkS7/gamq0rMoygs1ifS6Q5RTX/8AE6qfGILco9+j1nU6sDCRAzuk+SGU7RrAncPSbznS6KjwRp0VD1jSDClrVdWyy0sWTmP77jlBD70SDDecmtNCpF3WqiKcsoIw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kDvKslP4waykgwOT3pICa4cjuCwk8SfOxtgfBgmSfb4=; b=nSgy2I47NpVbqKLnZUKbt+fEnDHWiAqV7B2UfGdvDw5zFspvOm0nRqQXbZW5FPiIRm2ewU+KbzxhD7IaVjx31DoTj5sOlQXs2lG1s56luZrKuTMizsIDKcL0PvWFwNJP9AjtgZjnbZmDBrQLG9InjS//KMqFICQrX/9SLLydueQ= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:09:12 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:09:12 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 35/37] MIPS: genex: Add Loongson3 LL/SC workaround to ejtag_debug_handler Thread-Topic: [PATCH 35/37] MIPS: genex: Add Loongson3 LL/SC workaround to ejtag_debug_handler Thread-Index: AQHVd+QCU5ec8BbikU2GQVtPG2qJTQ== Date: Mon, 30 Sep 2019 23:08:44 +0000 Message-ID: <20190930230806.2940505-36-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: da36d510-1352-4f04-31c7-08d745fb2484 x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6108; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39850400004)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(14454004)(256004)(6512007)(81166006)(316002)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(478600001)(2501003)(6436002)(50226002)(6666004)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(4744005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: fg3lXp9ROyZFwTBZx5bigvhv6cZCaVI0aZj8FHtzOMGLbu/qasszOZ7EI6gbc7mzeXiXTjSaPxLvvGFvvFv2h31o0P0xFwOqzNH/iel9+N0cPld4t8AWqbuYIDvPxQp076Fvm/BHMKwXPtDx1/EDs8Qd7yDD7upv05Q/QA7xjwWopW51TWIKDo+DZuoVeGtesXK5xbdqlMacmBFmSnqxOw11Pg6d1KXeslSkYG5YQG3duLrKrRj9qFwkrDG+eEYeJc4NVPkiOKiK/Rfh0jlxQ3ws60zLTpNs2lMfvoK9zQ+hr/Nn14Om3qQDYQQE6wvHfr6oXCtUFedvPuiZ796UOi1PgQUFQXsw3H7IctAX7Py/JinL7IKu6YxAtaADtrBy9CI3brVmKYUUiP4/da4ITiD+jxE7U3DWupJQk/LsO1Q= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: da36d510-1352-4f04-31c7-08d745fb2484 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:45.0424 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: WuqNcb7PxeJ6duo0UuuFpaFjyRqqmAdPxi+MIlvn/IVa1lW0E2SNyzAav1d0s3kYSedisv12vvsRVBEOdUp82A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org In ejtag_debug_handler we use LL & SC instructions to acquire & release an open-coded spinlock. For Loongson3 systems affected by LL/SC errata this requires that we insert a sync instruction prior to the LL in order to ensure correct behavior of the LL/SC loop. Signed-off-by: Paul Burton --- arch/mips/kernel/genex.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/mips/kernel/genex.S b/arch/mips/kernel/genex.S index efde27c99414..ac4f2b835165 100644 --- a/arch/mips/kernel/genex.S +++ b/arch/mips/kernel/genex.S @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -353,6 +354,7 @@ NESTED(ejtag_debug_handler, PT_SIZE, sp) #ifdef CONFIG_SMP 1: PTR_LA k0, ejtag_debug_buffer_spinlock + __SYNC(full, loongson3_war) ll k0, 0(k0) bnez k0, 1b PTR_LA k0, ejtag_debug_buffer_spinlock From patchwork Mon Sep 30 23:08:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167763 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CDBB71902 for ; Mon, 30 Sep 2019 23:09:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AC0BF2081B for ; Mon, 30 Sep 2019 23:09:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="qzAkb6hr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732819AbfI3XJe (ORCPT ); Mon, 30 Sep 2019 19:09:34 -0400 Received: from mail-eopbgr820129.outbound.protection.outlook.com ([40.107.82.129]:60959 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732787AbfI3XJ0 (ORCPT ); Mon, 30 Sep 2019 19:09:26 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IOgds0mTk0ld5ZDXsVq4VTxByEigmvpOecNvBC46lrbVxgqBuaznnEXw8V72hOwzYYd9aKFeH9qfzP19vVG261h8jN1/7u+1VvAhkmc4QUezlH7hZwg3KHcxeJqSgQdZN6rOC5NfIK9zjFK61+3mW0LywlqAFNIHmyJckOie4nzbSLSfRuibgbMzAD7ZUEUr0W/zCxIiq7AMVzV+3LI5NGs4VwFul7ERVaVUrzx0EwKnhYmVCqQbPiqUCpPuJpnfsOhbYGbNAFkE74kGb/W7atDP+iP/c+nfKbx6MNqm2dteyPV659Tu3A1YmvCyteR+Uz+jxSB81EY1jreNYYnnNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4nYZ8yzbRJyMVxKdFTwZuVNLM2h93JOjnEbl3tT51wM=; b=AtzP0d3YnRcgDJGyxxmvFeoLute9bjAezqpsyOKAqf13KMODy0OC9zv/zt2FQ4kZu4KDTrZtQU4oeCuA8D8l8qtPqG1qHw3FrGdKHd2GH4o2oR7pmVECypzssH2UY6791FaAWQvJfGJ9+K6JhqonVIvCk1xsqH2sw5NwdNGOw4TvrUgz34ZhELGtLNU1DbT57iVqOq81Z6/locQ/WGzUB3Kj1lWTYcYgyMUXa6aJHGe7iOurnm3vSojngarRJTer+019o+hGDt1Dx7TXixGiC0K1DalAW9QSEvUAVY+EQe0lvbqryhBe8ZKsJN71ofXr1+RPytwHiJsh8yb+i5qXBA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4nYZ8yzbRJyMVxKdFTwZuVNLM2h93JOjnEbl3tT51wM=; b=qzAkb6hrIA5giqfZ7QODbvUHTaM7WmfklzqHbmlKvL4yEAgLqbF0TStccyTSjavCtB7sNpuL+zxz0USrjPZPOxlxgAGAPUxCGZttOY/tmocHe+oFKqR7J7+YPGPhFxuG5tfa6HVtkwqzX2LoidzIFil+2x+RQq4pCumFhELOxp4= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:09:13 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:09:13 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 36/37] MIPS: genex: Don't reload address unnecessarily Thread-Topic: [PATCH 36/37] MIPS: genex: Don't reload address unnecessarily Thread-Index: AQHVd+QCXFvgLjbm8k6qCb39EX8RsQ== Date: Mon, 30 Sep 2019 23:08:45 +0000 Message-ID: <20190930230806.2940505-37-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 236fdd30-a078-4d74-4edf-08d745fb250d x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39850400004)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(14454004)(256004)(6512007)(81166006)(316002)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(478600001)(2501003)(6436002)(50226002)(6666004)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: JP5F9AGGQPgETj+tkZ/8pc0+HIgxa5Xd85Q/dikTPUh52ciWKq/5AB7XfbLWAoy7U3yROssFxK6dF+FiygVby94ZKhuXIDMyIU/gVq0Qr6zdTXHuzhZIQHQ14nhhL8U+5U3zwjQwgxoyu6huEL75ZvrxHU7IO3TVN+5Q1eXG1U8iI7YN9TClc+dJ3wEbWfKYtuGAJL9DDar+W1HHd9bdPhyyjtyAA4NBYRsh/0EjCijA2ebvxTAlmuxolNPkwhLXFlg/RAnhks+vajrDt2iwmHxbvxa17Tctkay9dLPFHy8bF8/r7cKmKqrDoYG9K398QGTNU8w3VLwDG2LGYkvySWBdNJmuawNMg9h3Kb16FMzz537kgwl0ojfO9iQGvf9Qa1zqXkulH+t9qu+8EgyBy0sVojft+DJcVcKJMH8uBwk= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 236fdd30-a078-4d74-4edf-08d745fb250d X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:45.8750 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 3FAPa50iTdra2hqbteKbbnyQEcnn4WgA0bLtxnvr4138TKVo9pIErwIlIpE9KWKCwV0Y/QsS20V4QqqZUPD8ow== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org In ejtag_debug_handler() we must reload the address of ejtag_debug_buffer_spinlock if an sc fails, since the address in k0 will have been clobbered by the result of the sc instruction. In the case where we simply load a non-zero value (ie. there's contention for the lock) the address will not be clobbered & we can simply branch back to repeat the load from memory without reloading the address into k0. The primary motivation for this change is that it moves the target of the bnez instruction to an instruction within the LL/SC loop (the LL itself), which we know contains no other memory accesses & therefore isn't affected by Loongson3 LL/SC errata. Signed-off-by: Paul Burton --- arch/mips/kernel/genex.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/mips/kernel/genex.S b/arch/mips/kernel/genex.S index ac4f2b835165..60ede6b75a3b 100644 --- a/arch/mips/kernel/genex.S +++ b/arch/mips/kernel/genex.S @@ -355,8 +355,8 @@ NESTED(ejtag_debug_handler, PT_SIZE, sp) #ifdef CONFIG_SMP 1: PTR_LA k0, ejtag_debug_buffer_spinlock __SYNC(full, loongson3_war) - ll k0, 0(k0) - bnez k0, 1b +2: ll k0, 0(k0) + bnez k0, 2b PTR_LA k0, ejtag_debug_buffer_spinlock sc k0, 0(k0) beqz k0, 1b From patchwork Mon Sep 30 23:08:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 11167761 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 36AF2912 for ; Mon, 30 Sep 2019 23:09:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 027412086A for ; Mon, 30 Sep 2019 23:09:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=wavecomp.com header.i=@wavecomp.com header.b="ME7Plb3Y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732813AbfI3XJc (ORCPT ); Mon, 30 Sep 2019 19:09:32 -0400 Received: from mail-eopbgr820129.outbound.protection.outlook.com ([40.107.82.129]:60959 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732797AbfI3XJb (ORCPT ); Mon, 30 Sep 2019 19:09:31 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h2Ud/iNErmzAkmEgXOyz85JsbmrEEv+r0thPKA7GtIuet6ELatcwoox7N2V7FdI4TSQH5gMmtHTcWMFyR35wxEVgZPSAiTNEP4CxIQwPn6qsOs/Ax4efXU76OBppsqlzXKrqvR7rpzMKs8NkfYA1hVTkHWKq4JkKIJau3iME9J1l6pvozbaAvdM5tu46K8vLElPtiyrxIls4JWcJRkHn7loKraAroAkB8FZShFXZT8+qAwDGxP8dtYpKAwEhEb97GG0HKkU+1tgvGfixwYVgRG8asb7wo6HgMnrriK2do5+cxhhOBbtWLAykbm/3o/2dLoaaqWPHVb46b9m/RDwyQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3LMwFmxfY4shaNmDDmfj9qLygxnScLtXxUVpllXUruw=; b=Wb3F3zbPwrNPStEaii0/cn1pMEpwbt+nb92VFdRUpLu+MEzrYWQKu/ZeXCkyTzmyU70DNP21GlTqoduq3W5QD7u7O1TQe9ZsUzISPOl7RCUIqMI+WaF2G6EuTh9GDgiIXshMEqFQRBSz1lyLk5pX8DoFro9KFuTj8nM9vDzIuYuzRjwITZ2sOqMZtbc5ry/h1vVZbNM2XCn2N+f+t0XBee/pDByG++QEvzcw3XbG76u8pBvBwBcbxkLE/wTxzdpcXnK78xgH+ERg5ViDkVnPEgpb94Z9vNhLhTTtXUrzdYBTEvpLdjIEbbqpqzQnlGLZsG/zOiorURtEKSLY/mNazg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=mips.com; dkim=pass header.d=mips.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3LMwFmxfY4shaNmDDmfj9qLygxnScLtXxUVpllXUruw=; b=ME7Plb3YsyXE2HAyLL1SMp4MQxK5iDCTuav2oWQUbvwNm9+710dWyap9Jh1zD10UaieLLX7VnrzQ5Xui9HblxVUZtdklM1kiy20y6R2aUG2LJuk+VC9FZQ/GEir0dnCEnErMVfKXQ+It4fIxlRcaNKqZbPp97e7d4xCpAOsVjGo= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.172.60.12) by MWHPR2201MB1022.namprd22.prod.outlook.com (10.174.167.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Mon, 30 Sep 2019 23:09:13 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::498b:c2cd:e816:1481%2]) with mapi id 15.20.2305.017; Mon, 30 Sep 2019 23:09:13 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Huacai Chen , Jiaxun Yang , "linux-kernel@vger.kernel.org" , Paul Burton Subject: [PATCH 37/37] MIPS: Check Loongson3 LL/SC errata workaround correctness Thread-Topic: [PATCH 37/37] MIPS: Check Loongson3 LL/SC errata workaround correctness Thread-Index: AQHVd+QDb5WpqkNL602hvSM/CeT5mw== Date: Mon, 30 Sep 2019 23:08:46 +0000 Message-ID: <20190930230806.2940505-38-paul.burton@mips.com> References: <20190930230806.2940505-1-paul.burton@mips.com> In-Reply-To: <20190930230806.2940505-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:18::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 57983d1d-45ac-42c0-3870-08d745fb258a x-ms-traffictypediagnostic: MWHPR2201MB1022: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2150; x-forefront-prvs: 01762B0D64 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39850400004)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(14454004)(256004)(6512007)(81166006)(316002)(81156014)(44832011)(2351001)(486006)(476003)(6916009)(14444005)(186003)(478600001)(2501003)(6436002)(50226002)(6666004)(8676002)(11346002)(8936002)(2616005)(5640700003)(66946007)(6486002)(42882007)(64756008)(66446008)(66476007)(66556008)(446003)(6506007)(1076003)(305945005)(386003)(52116002)(7736002)(102836004)(2906002)(71190400001)(71200400001)(36756003)(5660300002)(26005)(4326008)(66066001)(54906003)(25786009)(76176011)(107886003)(99286004)(6116002)(3846002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1022;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: CMcme2cA2hoVFge1pO0MwdaCoF11oecTWDucOpLXGu5aPSa3z3UpAm2foyi3L/oHxzXLx72+DgUuxuk51uPiuwhagp++gmhsCJiIvbMGKbHysazAanv0GEwGziFTKjd6lY6ZFp9mnhkLyXHw22ZuE5dOd7f9ahnLNvns4IyqJrhYnPqWr3SCrs7aGd8lyN9Q3ZzkTcvwHBR5RGJKtXtvRz4o8HewPAbQOjEfy8hiWWo3dpSdXuBUL6CxRfWTJukQ/6kx6GtVXDf6mFpvBWnBtOc5IK9+EJRAnjyBVVSl8tjyzG8PQ8GowCkH9liuHETTRWUg14bHZ6OPKfmfEXfb4V5Qbfpi/DUrDYdtdF8pBahWg3uX0wzaT120pc4byegXKcYbiqkTnQug2RaopufHjREfzLJrY0uVZx8ebkIX9tk= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 57983d1d-45ac-42c0-3870-08d745fb258a X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2019 23:08:46.6856 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: EFAO2LdnT8avjr8s217MjaQBr3gsKpNCxg+TscO9WFJLCSUD1y/cmRag2Q6Hegy+U7xwqWLLw7oW2fHsnPMU7g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1022 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org When Loongson3 LL/SC errata workarounds are enabled (ie. CONFIG_CPU_LOONGSON3_WORKAROUNDS=y) run a tool to scan through the compiled kernel & ensure that the workaround is applied correctly. That is, ensure that: - Every LL or LLD instruction is preceded by a sync instruction. - Any branches from within an LL/SC loop to outside of that loop target a sync instruction. Reasoning for these conditions can be found by reading the comment above the definition of __SYNC_loongson3_war in arch/mips/include/asm/sync.h. This tool will help ensure that we don't inadvertently introduce code paths that miss the required workarounds. Signed-off-by: Paul Burton --- arch/mips/Makefile | 2 +- arch/mips/Makefile.postlink | 10 +- arch/mips/tools/.gitignore | 1 + arch/mips/tools/Makefile | 5 + arch/mips/tools/loongson3-llsc-check.c | 307 +++++++++++++++++++++++++ 5 files changed, 323 insertions(+), 2 deletions(-) create mode 100644 arch/mips/tools/loongson3-llsc-check.c diff --git a/arch/mips/Makefile b/arch/mips/Makefile index cdc09b71febe..4ac0974cf902 100644 --- a/arch/mips/Makefile +++ b/arch/mips/Makefile @@ -13,7 +13,7 @@ # archscripts: scripts_basic - $(Q)$(MAKE) $(build)=arch/mips/tools elf-entry + $(Q)$(MAKE) $(build)=arch/mips/tools elf-entry loongson3-llsc-check $(Q)$(MAKE) $(build)=arch/mips/boot/tools relocs KBUILD_DEFCONFIG := 32r2el_defconfig diff --git a/arch/mips/Makefile.postlink b/arch/mips/Makefile.postlink index 4eea4188cb20..f03fdc95143e 100644 --- a/arch/mips/Makefile.postlink +++ b/arch/mips/Makefile.postlink @@ -3,7 +3,8 @@ # Post-link MIPS pass # =========================================================================== # -# 1. Insert relocations into vmlinux +# 1. Check that Loongson3 LL/SC workarounds are applied correctly +# 2. Insert relocations into vmlinux PHONY := __archpost __archpost: @@ -11,6 +12,10 @@ __archpost: -include include/config/auto.conf include scripts/Kbuild.include +CMD_LS3_LLSC = arch/mips/tools/loongson3-llsc-check +quiet_cmd_ls3_llsc = LLSCCHK $@ + cmd_ls3_llsc = $(CMD_LS3_LLSC) $@ + CMD_RELOCS = arch/mips/boot/tools/relocs quiet_cmd_relocs = RELOCS $@ cmd_relocs = $(CMD_RELOCS) $@ @@ -19,6 +24,9 @@ quiet_cmd_relocs = RELOCS $@ vmlinux: FORCE @true +ifeq ($(CONFIG_CPU_LOONGSON3_WORKAROUNDS),y) + $(call if_changed,ls3_llsc) +endif ifeq ($(CONFIG_RELOCATABLE),y) $(call if_changed,relocs) endif diff --git a/arch/mips/tools/.gitignore b/arch/mips/tools/.gitignore index 56d34ccccce4..b0209450d9ff 100644 --- a/arch/mips/tools/.gitignore +++ b/arch/mips/tools/.gitignore @@ -1 +1,2 @@ elf-entry +loongson3-llsc-check diff --git a/arch/mips/tools/Makefile b/arch/mips/tools/Makefile index 3baee4bc6775..aaef688749f5 100644 --- a/arch/mips/tools/Makefile +++ b/arch/mips/tools/Makefile @@ -3,3 +3,8 @@ hostprogs-y := elf-entry PHONY += elf-entry elf-entry: $(obj)/elf-entry @: + +hostprogs-$(CONFIG_CPU_LOONGSON3_WORKAROUNDS) += loongson3-llsc-check +PHONY += loongson3-llsc-check +loongson3-llsc-check: $(obj)/loongson3-llsc-check + @: diff --git a/arch/mips/tools/loongson3-llsc-check.c b/arch/mips/tools/loongson3-llsc-check.c new file mode 100644 index 000000000000..0ebddd0ae46f --- /dev/null +++ b/arch/mips/tools/loongson3-llsc-check.c @@ -0,0 +1,307 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef be32toh +/* If libc provides le{16,32,64}toh() then we'll use them */ +#elif BYTE_ORDER == LITTLE_ENDIAN +# define le16toh(x) (x) +# define le32toh(x) (x) +# define le64toh(x) (x) +#elif BYTE_ORDER == BIG_ENDIAN +# define le16toh(x) bswap_16(x) +# define le32toh(x) bswap_32(x) +# define le64toh(x) bswap_64(x) +#endif + +/* MIPS opcodes, in bits 31:26 of an instruction */ +#define OP_SPECIAL 0x00 +#define OP_REGIMM 0x01 +#define OP_BEQ 0x04 +#define OP_BNE 0x05 +#define OP_BLEZ 0x06 +#define OP_BGTZ 0x07 +#define OP_BEQL 0x14 +#define OP_BNEL 0x15 +#define OP_BLEZL 0x16 +#define OP_BGTZL 0x17 +#define OP_LL 0x30 +#define OP_LLD 0x34 +#define OP_SC 0x38 +#define OP_SCD 0x3c + +/* Bits 20:16 of OP_REGIMM instructions */ +#define REGIMM_BLTZ 0x00 +#define REGIMM_BGEZ 0x01 +#define REGIMM_BLTZL 0x02 +#define REGIMM_BGEZL 0x03 +#define REGIMM_BLTZAL 0x10 +#define REGIMM_BGEZAL 0x11 +#define REGIMM_BLTZALL 0x12 +#define REGIMM_BGEZALL 0x13 + +/* Bits 5:0 of OP_SPECIAL instructions */ +#define SPECIAL_SYNC 0x0f + +static void usage(FILE *f) +{ + fprintf(f, "Usage: loongson3-llsc-check /path/to/vmlinux\n"); +} + +static int se16(uint16_t x) +{ + return (int16_t)x; +} + +static bool is_ll(uint32_t insn) +{ + switch (insn >> 26) { + case OP_LL: + case OP_LLD: + return true; + + default: + return false; + } +} + +static bool is_sc(uint32_t insn) +{ + switch (insn >> 26) { + case OP_SC: + case OP_SCD: + return true; + + default: + return false; + } +} + +static bool is_sync(uint32_t insn) +{ + /* Bits 31:11 should all be zeroes */ + if (insn >> 11) + return false; + + /* Bits 5:0 specify the SYNC special encoding */ + if ((insn & 0x3f) != SPECIAL_SYNC) + return false; + + return true; +} + +static bool is_branch(uint32_t insn, int *off) +{ + switch (insn >> 26) { + case OP_BEQ: + case OP_BEQL: + case OP_BNE: + case OP_BNEL: + case OP_BGTZ: + case OP_BGTZL: + case OP_BLEZ: + case OP_BLEZL: + *off = se16(insn) + 1; + return true; + + case OP_REGIMM: + switch ((insn >> 16) & 0x1f) { + case REGIMM_BGEZ: + case REGIMM_BGEZL: + case REGIMM_BGEZAL: + case REGIMM_BGEZALL: + case REGIMM_BLTZ: + case REGIMM_BLTZL: + case REGIMM_BLTZAL: + case REGIMM_BLTZALL: + *off = se16(insn) + 1; + return true; + + default: + return false; + } + + default: + return false; + } +} + +static int check_ll(uint64_t pc, uint32_t *code, size_t sz) +{ + ssize_t i, max, sc_pos; + int off; + + /* + * Every LL must be preceded by a sync instruction in order to ensure + * that instruction reordering doesn't allow a prior memory access to + * execute after the LL & cause erroneous results. + */ + if (!is_sync(le32toh(code[-1]))) { + fprintf(stderr, "%" PRIx64 ": LL not preceded by sync\n", pc); + return -EINVAL; + } + + /* Find the matching SC instruction */ + max = sz / 4; + for (sc_pos = 0; sc_pos < max; sc_pos++) { + if (is_sc(le32toh(code[sc_pos]))) + break; + } + if (sc_pos >= max) { + fprintf(stderr, "%" PRIx64 ": LL has no matching SC\n", pc); + return -EINVAL; + } + + /* + * Check branches within the LL/SC loop target sync instructions, + * ensuring that speculative execution can't generate memory accesses + * due to instructions outside of the loop. + */ + for (i = 0; i < sc_pos; i++) { + if (!is_branch(le32toh(code[i]), &off)) + continue; + + /* + * If the branch target is within the LL/SC loop then we don't + * need to worry about it. + */ + if ((off >= -i) && (off <= sc_pos)) + continue; + + /* If the branch targets a sync instruction we're all good... */ + if (is_sync(le32toh(code[i + off]))) + continue; + + /* ...but if not, we have a problem */ + fprintf(stderr, "%" PRIx64 ": Branch target not a sync\n", + pc + (i * 4)); + return -EINVAL; + } + + return 0; +} + +static int check_code(uint64_t pc, uint32_t *code, size_t sz) +{ + int err = 0; + + if (sz % 4) { + fprintf(stderr, "%" PRIx64 ": Section size not a multiple of 4\n", + pc); + err = -EINVAL; + sz -= (sz % 4); + } + + if (is_ll(le32toh(code[0]))) { + fprintf(stderr, "%" PRIx64 ": First instruction in section is an LL\n", + pc); + err = -EINVAL; + } + +#define advance() ( \ + code++, \ + pc += 4, \ + sz -= 4 \ +) + + /* + * Skip the first instructionm allowing check_ll to look backwards + * unconditionally. + */ + advance(); + + /* Now scan through the code looking for LL instructions */ + for (; sz; advance()) { + if (is_ll(le32toh(code[0]))) + err |= check_ll(pc, code, sz); + } + + return err; +} + +int main(int argc, char *argv[]) +{ + int vmlinux_fd, status, err, i; + const char *vmlinux_path; + struct stat st; + Elf64_Ehdr *eh; + Elf64_Shdr *sh; + void *vmlinux; + + status = EXIT_FAILURE; + + if (argc < 2) { + usage(stderr); + goto out_ret; + } + + vmlinux_path = argv[1]; + vmlinux_fd = open(vmlinux_path, O_RDONLY); + if (vmlinux_fd == -1) { + perror("Unable to open vmlinux"); + goto out_ret; + } + + err = fstat(vmlinux_fd, &st); + if (err) { + perror("Unable to stat vmlinux"); + goto out_close; + } + + vmlinux = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, vmlinux_fd, 0); + if (vmlinux == MAP_FAILED) { + perror("Unable to mmap vmlinux"); + goto out_close; + } + + eh = vmlinux; + if (memcmp(eh->e_ident, ELFMAG, SELFMAG)) { + fprintf(stderr, "vmlinux is not an ELF?\n"); + goto out_munmap; + } + + if (eh->e_ident[EI_CLASS] != ELFCLASS64) { + fprintf(stderr, "vmlinux is not 64b?\n"); + goto out_munmap; + } + + if (eh->e_ident[EI_DATA] != ELFDATA2LSB) { + fprintf(stderr, "vmlinux is not little endian?\n"); + goto out_munmap; + } + + for (i = 0; i < le16toh(eh->e_shnum); i++) { + sh = vmlinux + le64toh(eh->e_shoff) + (i * le16toh(eh->e_shentsize)); + + if (sh->sh_type != SHT_PROGBITS) + continue; + if (!(sh->sh_flags & SHF_EXECINSTR)) + continue; + + err = check_code(le64toh(sh->sh_addr), + vmlinux + le64toh(sh->sh_offset), + le64toh(sh->sh_size)); + if (err) + goto out_munmap; + } + + status = EXIT_SUCCESS; +out_munmap: + munmap(vmlinux, st.st_size); +out_close: + close(vmlinux_fd); +out_ret: + return status; +}