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

xen-ops.h (6781B)


      1/* SPDX-License-Identifier: GPL-2.0 */
      2#ifndef INCLUDE_XEN_OPS_H
      3#define INCLUDE_XEN_OPS_H
      4
      5#include <linux/percpu.h>
      6#include <linux/notifier.h>
      7#include <linux/efi.h>
      8#include <xen/features.h>
      9#include <asm/xen/interface.h>
     10#include <xen/interface/vcpu.h>
     11
     12DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu);
     13
     14DECLARE_PER_CPU(uint32_t, xen_vcpu_id);
     15static inline uint32_t xen_vcpu_nr(int cpu)
     16{
     17	return per_cpu(xen_vcpu_id, cpu);
     18}
     19
     20#define XEN_VCPU_ID_INVALID U32_MAX
     21
     22void xen_arch_pre_suspend(void);
     23void xen_arch_post_suspend(int suspend_cancelled);
     24
     25void xen_timer_resume(void);
     26void xen_arch_resume(void);
     27void xen_arch_suspend(void);
     28
     29void xen_reboot(int reason);
     30
     31void xen_resume_notifier_register(struct notifier_block *nb);
     32void xen_resume_notifier_unregister(struct notifier_block *nb);
     33
     34bool xen_vcpu_stolen(int vcpu);
     35void xen_setup_runstate_info(int cpu);
     36void xen_time_setup_guest(void);
     37void xen_manage_runstate_time(int action);
     38void xen_get_runstate_snapshot(struct vcpu_runstate_info *res);
     39u64 xen_steal_clock(int cpu);
     40
     41int xen_setup_shutdown_event(void);
     42
     43extern unsigned long *xen_contiguous_bitmap;
     44
     45#if defined(CONFIG_XEN_PV)
     46int xen_remap_pfn(struct vm_area_struct *vma, unsigned long addr,
     47		  xen_pfn_t *pfn, int nr, int *err_ptr, pgprot_t prot,
     48		  unsigned int domid, bool no_translate);
     49#else
     50static inline int xen_remap_pfn(struct vm_area_struct *vma, unsigned long addr,
     51				xen_pfn_t *pfn, int nr, int *err_ptr,
     52				pgprot_t prot,  unsigned int domid,
     53				bool no_translate)
     54{
     55	BUG();
     56	return 0;
     57}
     58#endif
     59
     60struct vm_area_struct;
     61
     62#ifdef CONFIG_XEN_AUTO_XLATE
     63int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
     64			      unsigned long addr,
     65			      xen_pfn_t *gfn, int nr,
     66			      int *err_ptr, pgprot_t prot,
     67			      unsigned int domid,
     68			      struct page **pages);
     69int xen_xlate_unmap_gfn_range(struct vm_area_struct *vma,
     70			      int nr, struct page **pages);
     71#else
     72/*
     73 * These two functions are called from arch/x86/xen/mmu.c and so stubs
     74 * are needed for a configuration not specifying CONFIG_XEN_AUTO_XLATE.
     75 */
     76static inline int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
     77					    unsigned long addr,
     78					    xen_pfn_t *gfn, int nr,
     79					    int *err_ptr, pgprot_t prot,
     80					    unsigned int domid,
     81					    struct page **pages)
     82{
     83	return -EOPNOTSUPP;
     84}
     85
     86static inline int xen_xlate_unmap_gfn_range(struct vm_area_struct *vma,
     87					    int nr, struct page **pages)
     88{
     89	return -EOPNOTSUPP;
     90}
     91#endif
     92
     93int xen_remap_vma_range(struct vm_area_struct *vma, unsigned long addr,
     94			unsigned long len);
     95
     96/*
     97 * xen_remap_domain_gfn_array() - map an array of foreign frames by gfn
     98 * @vma:     VMA to map the pages into
     99 * @addr:    Address at which to map the pages
    100 * @gfn:     Array of GFNs to map
    101 * @nr:      Number entries in the GFN array
    102 * @err_ptr: Returns per-GFN error status.
    103 * @prot:    page protection mask
    104 * @domid:   Domain owning the pages
    105 * @pages:   Array of pages if this domain has an auto-translated physmap
    106 *
    107 * @gfn and @err_ptr may point to the same buffer, the GFNs will be
    108 * overwritten by the error codes after they are mapped.
    109 *
    110 * Returns the number of successfully mapped frames, or a -ve error
    111 * code.
    112 */
    113static inline int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
    114					     unsigned long addr,
    115					     xen_pfn_t *gfn, int nr,
    116					     int *err_ptr, pgprot_t prot,
    117					     unsigned int domid,
    118					     struct page **pages)
    119{
    120	if (xen_feature(XENFEAT_auto_translated_physmap))
    121		return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
    122						 prot, domid, pages);
    123
    124	/* We BUG_ON because it's a programmer error to pass a NULL err_ptr,
    125	 * and the consequences later is quite hard to detect what the actual
    126	 * cause of "wrong memory was mapped in".
    127	 */
    128	BUG_ON(err_ptr == NULL);
    129	return xen_remap_pfn(vma, addr, gfn, nr, err_ptr, prot, domid,
    130			     false);
    131}
    132
    133/*
    134 * xen_remap_domain_mfn_array() - map an array of foreign frames by mfn
    135 * @vma:     VMA to map the pages into
    136 * @addr:    Address at which to map the pages
    137 * @mfn:     Array of MFNs to map
    138 * @nr:      Number entries in the MFN array
    139 * @err_ptr: Returns per-MFN error status.
    140 * @prot:    page protection mask
    141 * @domid:   Domain owning the pages
    142 *
    143 * @mfn and @err_ptr may point to the same buffer, the MFNs will be
    144 * overwritten by the error codes after they are mapped.
    145 *
    146 * Returns the number of successfully mapped frames, or a -ve error
    147 * code.
    148 */
    149static inline int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
    150					     unsigned long addr, xen_pfn_t *mfn,
    151					     int nr, int *err_ptr,
    152					     pgprot_t prot, unsigned int domid)
    153{
    154	if (xen_feature(XENFEAT_auto_translated_physmap))
    155		return -EOPNOTSUPP;
    156
    157	return xen_remap_pfn(vma, addr, mfn, nr, err_ptr, prot, domid,
    158			     true);
    159}
    160
    161/* xen_remap_domain_gfn_range() - map a range of foreign frames
    162 * @vma:     VMA to map the pages into
    163 * @addr:    Address at which to map the pages
    164 * @gfn:     First GFN to map.
    165 * @nr:      Number frames to map
    166 * @prot:    page protection mask
    167 * @domid:   Domain owning the pages
    168 * @pages:   Array of pages if this domain has an auto-translated physmap
    169 *
    170 * Returns the number of successfully mapped frames, or a -ve error
    171 * code.
    172 */
    173static inline int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
    174					     unsigned long addr,
    175					     xen_pfn_t gfn, int nr,
    176					     pgprot_t prot, unsigned int domid,
    177					     struct page **pages)
    178{
    179	if (xen_feature(XENFEAT_auto_translated_physmap))
    180		return -EOPNOTSUPP;
    181
    182	return xen_remap_pfn(vma, addr, &gfn, nr, NULL, prot, domid, false);
    183}
    184
    185int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
    186			       int numpgs, struct page **pages);
    187
    188int xen_xlate_map_ballooned_pages(xen_pfn_t **pfns, void **vaddr,
    189				  unsigned long nr_grant_frames);
    190
    191bool xen_running_on_version_or_later(unsigned int major, unsigned int minor);
    192
    193void xen_efi_runtime_setup(void);
    194
    195
    196#if defined(CONFIG_XEN_PV) && !defined(CONFIG_PREEMPTION)
    197
    198DECLARE_PER_CPU(bool, xen_in_preemptible_hcall);
    199
    200static inline void xen_preemptible_hcall_begin(void)
    201{
    202	__this_cpu_write(xen_in_preemptible_hcall, true);
    203}
    204
    205static inline void xen_preemptible_hcall_end(void)
    206{
    207	__this_cpu_write(xen_in_preemptible_hcall, false);
    208}
    209
    210#else
    211
    212static inline void xen_preemptible_hcall_begin(void) { }
    213static inline void xen_preemptible_hcall_end(void) { }
    214
    215#endif /* CONFIG_XEN_PV && !CONFIG_PREEMPTION */
    216
    217#ifdef CONFIG_XEN_GRANT_DMA_OPS
    218void xen_grant_setup_dma_ops(struct device *dev);
    219bool xen_is_grant_dma_device(struct device *dev);
    220#else
    221static inline void xen_grant_setup_dma_ops(struct device *dev)
    222{
    223}
    224static inline bool xen_is_grant_dma_device(struct device *dev)
    225{
    226	return false;
    227}
    228#endif /* CONFIG_XEN_GRANT_DMA_OPS */
    229
    230#endif /* INCLUDE_XEN_OPS_H */