linux/kernel/kcsan/encoding.h

/* SPDX-License-Identifier: GPL-2.0 */
/*
 * KCSAN watchpoint encoding.
 *
 * Copyright (C) 2019, Google LLC.
 */

#ifndef _KERNEL_KCSAN_ENCODING_H
#define _KERNEL_KCSAN_ENCODING_H

#include <linux/bits.h>
#include <linux/log2.h>
#include <linux/mm.h>

#include "kcsan.h"

#define SLOT_RANGE

#define INVALID_WATCHPOINT
#define CONSUMED_WATCHPOINT

/*
 * The maximum useful size of accesses for which we set up watchpoints is the
 * max range of slots we check on an access.
 */
#define MAX_ENCODABLE_SIZE

/*
 * Number of bits we use to store size info.
 */
#define WATCHPOINT_SIZE_BITS
/*
 * This encoding for addresses discards the upper (1 for is-write + SIZE_BITS);
 * however, most 64-bit architectures do not use the full 64-bit address space.
 * Also, in order for a false positive to be observable 2 things need to happen:
 *
 *	1. different addresses but with the same encoded address race;
 *	2. and both map onto the same watchpoint slots;
 *
 * Both these are assumed to be very unlikely. However, in case it still
 * happens, the report logic will filter out the false positive (see report.c).
 */
#define WATCHPOINT_ADDR_BITS

/* Bitmasks for the encoded watchpoint access information. */
#define WATCHPOINT_WRITE_MASK
#define WATCHPOINT_SIZE_MASK
#define WATCHPOINT_ADDR_MASK
static_assert();
static_assert();

static inline bool check_encodable(unsigned long addr, size_t size)
{}

static inline long
encode_watchpoint(unsigned long addr, size_t size, bool is_write)
{}

static __always_inline bool decode_watchpoint(long watchpoint,
					      unsigned long *addr_masked,
					      size_t *size,
					      bool *is_write)
{}

/*
 * Return watchpoint slot for an address.
 */
static __always_inline int watchpoint_slot(unsigned long addr)
{}

static __always_inline bool matching_access(unsigned long addr1, size_t size1,
					    unsigned long addr2, size_t size2)
{}

#endif /* _KERNEL_KCSAN_ENCODING_H */