cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

migrate.h (5927B)


      1/* SPDX-License-Identifier: GPL-2.0 */
      2#ifndef _LINUX_MIGRATE_H
      3#define _LINUX_MIGRATE_H
      4
      5#include <linux/mm.h>
      6#include <linux/mempolicy.h>
      7#include <linux/migrate_mode.h>
      8#include <linux/hugetlb.h>
      9
     10typedef struct page *new_page_t(struct page *page, unsigned long private);
     11typedef void free_page_t(struct page *page, unsigned long private);
     12
     13struct migration_target_control;
     14
     15/*
     16 * Return values from addresss_space_operations.migratepage():
     17 * - negative errno on page migration failure;
     18 * - zero on page migration success;
     19 */
     20#define MIGRATEPAGE_SUCCESS		0
     21
     22/* Defined in mm/debug.c: */
     23extern const char *migrate_reason_names[MR_TYPES];
     24
     25#ifdef CONFIG_MIGRATION
     26
     27extern void putback_movable_pages(struct list_head *l);
     28extern int migrate_page(struct address_space *mapping,
     29			struct page *newpage, struct page *page,
     30			enum migrate_mode mode);
     31extern int migrate_pages(struct list_head *l, new_page_t new, free_page_t free,
     32		unsigned long private, enum migrate_mode mode, int reason,
     33		unsigned int *ret_succeeded);
     34extern struct page *alloc_migration_target(struct page *page, unsigned long private);
     35extern int isolate_movable_page(struct page *page, isolate_mode_t mode);
     36
     37extern void migrate_page_states(struct page *newpage, struct page *page);
     38extern void migrate_page_copy(struct page *newpage, struct page *page);
     39extern int migrate_huge_page_move_mapping(struct address_space *mapping,
     40				  struct page *newpage, struct page *page);
     41extern int migrate_page_move_mapping(struct address_space *mapping,
     42		struct page *newpage, struct page *page, int extra_count);
     43void migration_entry_wait_on_locked(swp_entry_t entry, pte_t *ptep,
     44				spinlock_t *ptl);
     45void folio_migrate_flags(struct folio *newfolio, struct folio *folio);
     46void folio_migrate_copy(struct folio *newfolio, struct folio *folio);
     47int folio_migrate_mapping(struct address_space *mapping,
     48		struct folio *newfolio, struct folio *folio, int extra_count);
     49
     50#else
     51
     52static inline void putback_movable_pages(struct list_head *l) {}
     53static inline int migrate_pages(struct list_head *l, new_page_t new,
     54		free_page_t free, unsigned long private, enum migrate_mode mode,
     55		int reason, unsigned int *ret_succeeded)
     56	{ return -ENOSYS; }
     57static inline struct page *alloc_migration_target(struct page *page,
     58		unsigned long private)
     59	{ return NULL; }
     60static inline int isolate_movable_page(struct page *page, isolate_mode_t mode)
     61	{ return -EBUSY; }
     62
     63static inline void migrate_page_states(struct page *newpage, struct page *page)
     64{
     65}
     66
     67static inline void migrate_page_copy(struct page *newpage,
     68				     struct page *page) {}
     69
     70static inline int migrate_huge_page_move_mapping(struct address_space *mapping,
     71				  struct page *newpage, struct page *page)
     72{
     73	return -ENOSYS;
     74}
     75
     76#endif /* CONFIG_MIGRATION */
     77
     78#if defined(CONFIG_MIGRATION) && defined(CONFIG_NUMA)
     79extern void set_migration_target_nodes(void);
     80extern void migrate_on_reclaim_init(void);
     81extern bool numa_demotion_enabled;
     82extern int next_demotion_node(int node);
     83#else
     84static inline void set_migration_target_nodes(void) {}
     85static inline void migrate_on_reclaim_init(void) {}
     86static inline int next_demotion_node(int node)
     87{
     88        return NUMA_NO_NODE;
     89}
     90#define numa_demotion_enabled  false
     91#endif
     92
     93#ifdef CONFIG_COMPACTION
     94extern int PageMovable(struct page *page);
     95extern void __SetPageMovable(struct page *page, struct address_space *mapping);
     96extern void __ClearPageMovable(struct page *page);
     97#else
     98static inline int PageMovable(struct page *page) { return 0; }
     99static inline void __SetPageMovable(struct page *page,
    100				struct address_space *mapping)
    101{
    102}
    103static inline void __ClearPageMovable(struct page *page)
    104{
    105}
    106#endif
    107
    108static inline bool folio_test_movable(struct folio *folio)
    109{
    110	return PageMovable(&folio->page);
    111}
    112
    113#ifdef CONFIG_NUMA_BALANCING
    114extern int migrate_misplaced_page(struct page *page,
    115				  struct vm_area_struct *vma, int node);
    116#else
    117static inline int migrate_misplaced_page(struct page *page,
    118					 struct vm_area_struct *vma, int node)
    119{
    120	return -EAGAIN; /* can't migrate now */
    121}
    122#endif /* CONFIG_NUMA_BALANCING */
    123
    124#ifdef CONFIG_MIGRATION
    125
    126/*
    127 * Watch out for PAE architecture, which has an unsigned long, and might not
    128 * have enough bits to store all physical address and flags. So far we have
    129 * enough room for all our flags.
    130 */
    131#define MIGRATE_PFN_VALID	(1UL << 0)
    132#define MIGRATE_PFN_MIGRATE	(1UL << 1)
    133#define MIGRATE_PFN_WRITE	(1UL << 3)
    134#define MIGRATE_PFN_SHIFT	6
    135
    136static inline struct page *migrate_pfn_to_page(unsigned long mpfn)
    137{
    138	if (!(mpfn & MIGRATE_PFN_VALID))
    139		return NULL;
    140	return pfn_to_page(mpfn >> MIGRATE_PFN_SHIFT);
    141}
    142
    143static inline unsigned long migrate_pfn(unsigned long pfn)
    144{
    145	return (pfn << MIGRATE_PFN_SHIFT) | MIGRATE_PFN_VALID;
    146}
    147
    148enum migrate_vma_direction {
    149	MIGRATE_VMA_SELECT_SYSTEM = 1 << 0,
    150	MIGRATE_VMA_SELECT_DEVICE_PRIVATE = 1 << 1,
    151};
    152
    153struct migrate_vma {
    154	struct vm_area_struct	*vma;
    155	/*
    156	 * Both src and dst array must be big enough for
    157	 * (end - start) >> PAGE_SHIFT entries.
    158	 *
    159	 * The src array must not be modified by the caller after
    160	 * migrate_vma_setup(), and must not change the dst array after
    161	 * migrate_vma_pages() returns.
    162	 */
    163	unsigned long		*dst;
    164	unsigned long		*src;
    165	unsigned long		cpages;
    166	unsigned long		npages;
    167	unsigned long		start;
    168	unsigned long		end;
    169
    170	/*
    171	 * Set to the owner value also stored in page->pgmap->owner for
    172	 * migrating out of device private memory. The flags also need to
    173	 * be set to MIGRATE_VMA_SELECT_DEVICE_PRIVATE.
    174	 * The caller should always set this field when using mmu notifier
    175	 * callbacks to avoid device MMU invalidations for device private
    176	 * pages that are not being migrated.
    177	 */
    178	void			*pgmap_owner;
    179	unsigned long		flags;
    180};
    181
    182int migrate_vma_setup(struct migrate_vma *args);
    183void migrate_vma_pages(struct migrate_vma *migrate);
    184void migrate_vma_finalize(struct migrate_vma *migrate);
    185#endif /* CONFIG_MIGRATION */
    186
    187#endif /* _LINUX_MIGRATE_H */