mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-27 12:57:53 +00:00
c8e7df374b
Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). As found with Coccinelle[1], add __counted_by for struct amdgpu_bo_list. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier. Cc: Alex Deucher <alexander.deucher@amd.com> Cc: "Christian König" <christian.koenig@amd.com> Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com> Cc: David Airlie <airlied@gmail.com> Cc: Daniel Vetter <daniel@ffwll.ch> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> Cc: Luben Tuikov <luben.tuikov@amd.com> Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Cc: Felix Kuehling <Felix.Kuehling@amd.com> Cc: amd-gfx@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org Cc: linux-hardening@vger.kernel.org Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1] Reviewed-by: Luben Tuikov <luben.tuikov@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
84 lines
2.6 KiB
C
84 lines
2.6 KiB
C
/*
|
|
* Copyright 2018 Advanced Micro Devices, Inc.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
*/
|
|
#ifndef __AMDGPU_BO_LIST_H__
|
|
#define __AMDGPU_BO_LIST_H__
|
|
|
|
#include <drm/amdgpu_drm.h>
|
|
|
|
struct hmm_range;
|
|
|
|
struct drm_file;
|
|
|
|
struct amdgpu_device;
|
|
struct amdgpu_bo;
|
|
struct amdgpu_bo_va;
|
|
struct amdgpu_fpriv;
|
|
|
|
struct amdgpu_bo_list_entry {
|
|
struct amdgpu_bo *bo;
|
|
struct amdgpu_bo_va *bo_va;
|
|
uint32_t priority;
|
|
struct page **user_pages;
|
|
struct hmm_range *range;
|
|
bool user_invalidated;
|
|
};
|
|
|
|
struct amdgpu_bo_list {
|
|
struct rcu_head rhead;
|
|
struct kref refcount;
|
|
struct amdgpu_bo *gds_obj;
|
|
struct amdgpu_bo *gws_obj;
|
|
struct amdgpu_bo *oa_obj;
|
|
unsigned first_userptr;
|
|
unsigned num_entries;
|
|
|
|
/* Protect access during command submission.
|
|
*/
|
|
struct mutex bo_list_mutex;
|
|
|
|
struct amdgpu_bo_list_entry entries[] __counted_by(num_entries);
|
|
};
|
|
|
|
int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
|
|
struct amdgpu_bo_list **result);
|
|
void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
|
|
int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
|
|
struct drm_amdgpu_bo_list_entry **info_param);
|
|
|
|
int amdgpu_bo_list_create(struct amdgpu_device *adev,
|
|
struct drm_file *filp,
|
|
struct drm_amdgpu_bo_list_entry *info,
|
|
size_t num_entries,
|
|
struct amdgpu_bo_list **list);
|
|
|
|
#define amdgpu_bo_list_for_each_entry(e, list) \
|
|
for (e = list->entries; \
|
|
e != &list->entries[list->num_entries]; \
|
|
++e)
|
|
|
|
#define amdgpu_bo_list_for_each_userptr_entry(e, list) \
|
|
for (e = &list->entries[list->first_userptr]; \
|
|
e != &list->entries[list->num_entries]; \
|
|
++e)
|
|
|
|
#endif
|