From owner-svn-src-head@freebsd.org Mon Sep 18 13:37:16 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 29FE3E10C8B; Mon, 18 Sep 2017 13:37:16 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 05E1369177; Mon, 18 Sep 2017 13:37:15 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8IDbFEv060250; Mon, 18 Sep 2017 13:37:15 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8IDbEPD060245; Mon, 18 Sep 2017 13:37:14 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201709181337.v8IDbEPD060245@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 18 Sep 2017 13:37:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r323705 - in head/sys/compat/linuxkpi/common: include/asm include/linux src X-SVN-Group: head X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: in head/sys/compat/linuxkpi/common: include/asm include/linux src X-SVN-Commit-Revision: 323705 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Sep 2017 13:37:16 -0000 Author: hselasky Date: Mon Sep 18 13:37:14 2017 New Revision: 323705 URL: https://svnweb.freebsd.org/changeset/base/323705 Log: The LinuxKPI atomics do not have acquire nor release semantics unless specified. Fix code to use READ_ONCE() and WRITE_ONCE() where appropriate. Suggested by: kib @ MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/compat/linuxkpi/common/include/asm/atomic-long.h head/sys/compat/linuxkpi/common/include/asm/atomic.h head/sys/compat/linuxkpi/common/include/asm/atomic64.h head/sys/compat/linuxkpi/common/include/linux/bitops.h head/sys/compat/linuxkpi/common/src/linux_tasklet.c Modified: head/sys/compat/linuxkpi/common/include/asm/atomic-long.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/asm/atomic-long.h Mon Sep 18 13:23:59 2017 (r323704) +++ head/sys/compat/linuxkpi/common/include/asm/atomic-long.h Mon Sep 18 13:37:14 2017 (r323705) @@ -2,7 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. - * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. + * Copyright (c) 2013-2017 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,7 @@ #ifndef _ATOMIC_LONG_H_ #define _ATOMIC_LONG_H_ -#include +#include #include #include @@ -54,13 +54,13 @@ atomic_long_add_return(long i, atomic_long_t *v) static inline void atomic_long_set(atomic_long_t *v, long i) { - atomic_store_rel_long(&v->counter, i); + WRITE_ONCE(v->counter, i); } static inline long atomic_long_read(atomic_long_t *v) { - return atomic_load_acq_long(&v->counter); + return READ_ONCE(v->counter); } static inline long Modified: head/sys/compat/linuxkpi/common/include/asm/atomic.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/asm/atomic.h Mon Sep 18 13:23:59 2017 (r323704) +++ head/sys/compat/linuxkpi/common/include/asm/atomic.h Mon Sep 18 13:37:14 2017 (r323705) @@ -2,7 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. - * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. + * Copyright (c) 2013-2017 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,9 +32,8 @@ #ifndef _ASM_ATOMIC_H_ #define _ASM_ATOMIC_H_ -#include +#include #include - #include #define ATOMIC_INIT(x) { .counter = (x) } @@ -73,7 +72,7 @@ atomic_sub_return(int i, atomic_t *v) static inline void atomic_set(atomic_t *v, int i) { - atomic_store_rel_int(&v->counter, i); + WRITE_ONCE(v->counter, i); } static inline void @@ -91,7 +90,7 @@ atomic_set_mask(unsigned int mask, atomic_t *v) static inline int atomic_read(const atomic_t *v) { - return atomic_load_acq_int(&__DECONST(atomic_t *, v)->counter); + return READ_ONCE(v->counter); } static inline int @@ -137,7 +136,7 @@ atomic_xchg(atomic_t *v, int i) #else int ret; for (;;) { - ret = atomic_load_acq_int(&v->counter); + ret = READ_ONCE(v->counter); if (atomic_cmpset_int(&v->counter, ret, i)) break; } @@ -153,7 +152,7 @@ atomic_cmpxchg(atomic_t *v, int old, int new) for (;;) { if (atomic_cmpset_int(&v->counter, old, new)) break; - ret = atomic_load_acq_int(&v->counter); + ret = READ_ONCE(v->counter); if (ret != old) break; } Modified: head/sys/compat/linuxkpi/common/include/asm/atomic64.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/asm/atomic64.h Mon Sep 18 13:23:59 2017 (r323704) +++ head/sys/compat/linuxkpi/common/include/asm/atomic64.h Mon Sep 18 13:37:14 2017 (r323705) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2016 Mellanox Technologies, Ltd. + * Copyright (c) 2016-2017 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,7 +28,7 @@ #ifndef _ASM_ATOMIC64_H_ #define _ASM_ATOMIC64_H_ -#include +#include #include #include @@ -74,7 +74,7 @@ atomic64_set(atomic64_t *v, int64_t i) static inline int64_t atomic64_read(atomic64_t *v) { - return atomic_load_acq_64(&v->counter); + return READ_ONCE(v->counter); } static inline int64_t @@ -114,7 +114,7 @@ atomic64_xchg(atomic64_t *v, int64_t i) #else int64_t ret; for (;;) { - ret = atomic_load_acq_64(&v->counter); + ret = READ_ONCE(v->counter); if (atomic_cmpset_64(&v->counter, ret, i)) break; } @@ -130,7 +130,7 @@ atomic64_cmpxchg(atomic64_t *v, int64_t old, int64_t n for (;;) { if (atomic_cmpset_64(&v->counter, old, new)) break; - ret = atomic_load_acq_64(&v->counter); + ret = READ_ONCE(v->counter); if (ret != old) break; } Modified: head/sys/compat/linuxkpi/common/include/linux/bitops.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/bitops.h Mon Sep 18 13:23:59 2017 (r323704) +++ head/sys/compat/linuxkpi/common/include/linux/bitops.h Mon Sep 18 13:37:14 2017 (r323705) @@ -269,8 +269,7 @@ find_next_zero_bit(const unsigned long *addr, unsigned atomic_clear_long(&((volatile unsigned long *)(a))[BIT_WORD(i)], BIT_MASK(i)) #define test_bit(i, a) \ - !!(atomic_load_acq_long(&((volatile unsigned long *)(a))[BIT_WORD(i)]) & \ - BIT_MASK(i)) + !!(READ_ONCE(((volatile unsigned long *)(a))[BIT_WORD(i)]) & BIT_MASK(i)) static inline int test_and_clear_bit(long bit, volatile unsigned long *var) Modified: head/sys/compat/linuxkpi/common/src/linux_tasklet.c ============================================================================== --- head/sys/compat/linuxkpi/common/src/linux_tasklet.c Mon Sep 18 13:23:59 2017 (r323704) +++ head/sys/compat/linuxkpi/common/src/linux_tasklet.c Mon Sep 18 13:37:14 2017 (r323705) @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -45,10 +46,10 @@ __FBSDID("$FreeBSD$"); atomic_cmpset_ptr((volatile uintptr_t *)&(ts)->entry.tqe_prev, old, new) #define TASKLET_ST_SET(ts, new) \ - atomic_store_rel_ptr((volatile uintptr_t *)&(ts)->entry.tqe_prev, new) + WRITE_ONCE(*(volatile uintptr_t *)&(ts)->entry.tqe_prev, new) #define TASKLET_ST_GET(ts) \ - atomic_load_acq_ptr((volatile uintptr_t *)&(ts)->entry.tqe_prev) + READ_ONCE(*(volatile uintptr_t *)&(ts)->entry.tqe_prev) struct tasklet_worker { struct mtx mtx;