X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=lib%2Fringbuffer%2Fbackend.h;h=46dcf1ccd9053443c4d00a743f5e1d19b2aa9ddb;hb=6423140ffcb1c5b005199bb2fa34621361ad538d;hp=0b75de8a65137aa1e7cd16a25afe26a280a5792d;hpb=a8f2d0c75c9cc179fc9e7f7ca17ea3b3b3b5af41;p=lttng-modules.git diff --git a/lib/ringbuffer/backend.h b/lib/ringbuffer/backend.h index 0b75de8a..46dcf1cc 100644 --- a/lib/ringbuffer/backend.h +++ b/lib/ringbuffer/backend.h @@ -1,31 +1,18 @@ -#ifndef _LIB_RING_BUFFER_BACKEND_H -#define _LIB_RING_BUFFER_BACKEND_H - -/* +/* SPDX-License-Identifier: (GPL-2.0 OR LGPL-2.1) + * * lib/ringbuffer/backend.h * * Ring buffer backend (API). * * Copyright (C) 2010-2012 Mathieu Desnoyers * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; only - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * * Credits to Steven Rostedt for proposing to use an extra-subbuffer owned by * the reader in flight recorder mode. */ +#ifndef _LIB_RING_BUFFER_BACKEND_H +#define _LIB_RING_BUFFER_BACKEND_H + #include #include #include @@ -34,7 +21,8 @@ #include #include #include -#include +#include +#include /* Internal helpers */ #include @@ -169,7 +157,7 @@ size_t lib_ring_buffer_do_strcpy(const struct lib_ring_buffer_config *config, * Only read source character once, in case it is * modified concurrently. */ - c = READ_ONCE(src[count]); + c = LTTNG_READ_ONCE(src[count]); if (!c) break; lib_ring_buffer_do_copy(config, &dest[count], &c, 1); @@ -290,7 +278,6 @@ void lib_ring_buffer_copy_from_user_inatomic(const struct lib_ring_buffer_config size_t offset = ctx->buf_offset; struct lib_ring_buffer_backend_pages *backend_pages; unsigned long ret; - mm_segment_t old_fs = get_fs(); if (unlikely(!len)) return; @@ -300,9 +287,8 @@ void lib_ring_buffer_copy_from_user_inatomic(const struct lib_ring_buffer_config index = (offset & (chanb->subbuf_size - 1)) >> PAGE_SHIFT; pagecpy = min_t(size_t, len, (-offset) & ~PAGE_MASK); - set_fs(KERNEL_DS); pagefault_disable(); - if (unlikely(!access_ok(VERIFY_READ, src, len))) + if (unlikely(!lttng_access_ok(VERIFY_READ, src, len))) goto fill_buffer; if (likely(pagecpy == len)) { @@ -317,19 +303,18 @@ void lib_ring_buffer_copy_from_user_inatomic(const struct lib_ring_buffer_config _lib_ring_buffer_copy_from_user_inatomic(bufb, offset, src, len, 0); } pagefault_enable(); - set_fs(old_fs); ctx->buf_offset += len; return; fill_buffer: pagefault_enable(); - set_fs(old_fs); /* * In the error path we call the slow path version to avoid * the pollution of static inline code. */ _lib_ring_buffer_memset(bufb, offset, 0, len, 0); + ctx->buf_offset += len; } /** @@ -360,7 +345,6 @@ void lib_ring_buffer_strcpy_from_user_inatomic(const struct lib_ring_buffer_conf size_t index, pagecpy; size_t offset = ctx->buf_offset; struct lib_ring_buffer_backend_pages *backend_pages; - mm_segment_t old_fs = get_fs(); if (unlikely(!len)) return; @@ -370,9 +354,8 @@ void lib_ring_buffer_strcpy_from_user_inatomic(const struct lib_ring_buffer_conf index = (offset & (chanb->subbuf_size - 1)) >> PAGE_SHIFT; pagecpy = min_t(size_t, len, (-offset) & ~PAGE_MASK); - set_fs(KERNEL_DS); pagefault_disable(); - if (unlikely(!access_ok(VERIFY_READ, src, len))) + if (unlikely(!lttng_access_ok(VERIFY_READ, src, len))) goto fill_buffer; if (likely(pagecpy == len)) { @@ -401,14 +384,12 @@ void lib_ring_buffer_strcpy_from_user_inatomic(const struct lib_ring_buffer_conf len, 0, pad); } pagefault_enable(); - set_fs(old_fs); ctx->buf_offset += len; return; fill_buffer: pagefault_enable(); - set_fs(old_fs); /* * In the error path we call the slow path version to avoid * the pollution of static inline code. @@ -416,6 +397,7 @@ fill_buffer: _lib_ring_buffer_memset(bufb, offset, pad, len - 1, 0); offset += len - 1; _lib_ring_buffer_memset(bufb, offset, '\0', 1, 0); + ctx->buf_offset += len; } /* @@ -459,18 +441,7 @@ unsigned long lib_ring_buffer_copy_from_user_check_nofault(void *dest, const void __user *src, unsigned long len) { - unsigned long ret; - mm_segment_t old_fs; - - if (!access_ok(VERIFY_READ, src, len)) - return 1; - old_fs = get_fs(); - set_fs(KERNEL_DS); - pagefault_disable(); - ret = __copy_from_user_inatomic(dest, src, len); - pagefault_enable(); - set_fs(old_fs); - return ret; + return lttng_copy_from_user_check_nofault(dest, src, len); } #endif /* _LIB_RING_BUFFER_BACKEND_H */