Skip to content

Commit a13d720

Browse files
author
Julien Grall
committed
xen/privcmd: Further s/MFN/GFN/ clean-up
The privcmd code is mixing the usage of GFN and MFN within the same functions which make the code difficult to understand when you only work with auto-translated guests. The privcmd driver is only dealing with GFN so replace all the mention of MFN into GFN. The ioctl structure used to map foreign change has been left unchanged given that the userspace is using it. Nonetheless, add a comment to explain the expected value within the "mfn" field. Signed-off-by: Julien Grall <julien.grall@citrix.com> Reviewed-by: David Vrabel <david.vrabel@citrix.com> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
1 parent 859e326 commit a13d720

6 files changed

Lines changed: 65 additions & 61 deletions

File tree

‎arch/arm/xen/enlighten.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,35 @@ static __read_mostly unsigned int xen_events_irq;
4949

5050
static __initdata struct device_node *xen_node;
5151

52-
int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
52+
int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
5353
unsigned long addr,
54-
xen_pfn_t *mfn, int nr,
54+
xen_pfn_t *gfn, int nr,
5555
int *err_ptr, pgprot_t prot,
5656
unsigned domid,
5757
struct page **pages)
5858
{
59-
return xen_xlate_remap_gfn_array(vma, addr, mfn, nr, err_ptr,
59+
return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
6060
prot, domid, pages);
6161
}
62-
EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_array);
62+
EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);
6363

6464
/* Not used by XENFEAT_auto_translated guests. */
65-
int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
65+
int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
6666
unsigned long addr,
67-
xen_pfn_t mfn, int nr,
67+
xen_pfn_t gfn, int nr,
6868
pgprot_t prot, unsigned domid,
6969
struct page **pages)
7070
{
7171
return -ENOSYS;
7272
}
73-
EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range);
73+
EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
7474

75-
int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
75+
int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
7676
int nr, struct page **pages)
7777
{
7878
return xen_xlate_unmap_gfn_range(vma, nr, pages);
7979
}
80-
EXPORT_SYMBOL_GPL(xen_unmap_domain_mfn_range);
80+
EXPORT_SYMBOL_GPL(xen_unmap_domain_gfn_range);
8181

8282
static void xen_percpu_init(void)
8383
{

‎arch/x86/xen/mmu.c‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,9 +2812,9 @@ static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token,
28122812
return 0;
28132813
}
28142814

2815-
static int do_remap_mfn(struct vm_area_struct *vma,
2815+
static int do_remap_gfn(struct vm_area_struct *vma,
28162816
unsigned long addr,
2817-
xen_pfn_t *mfn, int nr,
2817+
xen_pfn_t *gfn, int nr,
28182818
int *err_ptr, pgprot_t prot,
28192819
unsigned domid,
28202820
struct page **pages)
@@ -2830,14 +2830,14 @@ static int do_remap_mfn(struct vm_area_struct *vma,
28302830
if (xen_feature(XENFEAT_auto_translated_physmap)) {
28312831
#ifdef CONFIG_XEN_PVH
28322832
/* We need to update the local page tables and the xen HAP */
2833-
return xen_xlate_remap_gfn_array(vma, addr, mfn, nr, err_ptr,
2833+
return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
28342834
prot, domid, pages);
28352835
#else
28362836
return -EINVAL;
28372837
#endif
28382838
}
28392839

2840-
rmd.mfn = mfn;
2840+
rmd.mfn = gfn;
28412841
rmd.prot = prot;
28422842
/* We use the err_ptr to indicate if there we are doing a contigious
28432843
* mapping or a discontigious mapping. */
@@ -2865,8 +2865,8 @@ static int do_remap_mfn(struct vm_area_struct *vma,
28652865
batch_left, &done, domid);
28662866

28672867
/*
2868-
* @err_ptr may be the same buffer as @mfn, so
2869-
* only clear it after each chunk of @mfn is
2868+
* @err_ptr may be the same buffer as @gfn, so
2869+
* only clear it after each chunk of @gfn is
28702870
* used.
28712871
*/
28722872
if (err_ptr) {
@@ -2896,19 +2896,19 @@ static int do_remap_mfn(struct vm_area_struct *vma,
28962896
return err < 0 ? err : mapped;
28972897
}
28982898

2899-
int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
2899+
int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
29002900
unsigned long addr,
2901-
xen_pfn_t mfn, int nr,
2901+
xen_pfn_t gfn, int nr,
29022902
pgprot_t prot, unsigned domid,
29032903
struct page **pages)
29042904
{
2905-
return do_remap_mfn(vma, addr, &mfn, nr, NULL, prot, domid, pages);
2905+
return do_remap_gfn(vma, addr, &gfn, nr, NULL, prot, domid, pages);
29062906
}
2907-
EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range);
2907+
EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
29082908

2909-
int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
2909+
int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
29102910
unsigned long addr,
2911-
xen_pfn_t *mfn, int nr,
2911+
xen_pfn_t *gfn, int nr,
29122912
int *err_ptr, pgprot_t prot,
29132913
unsigned domid, struct page **pages)
29142914
{
@@ -2917,13 +2917,13 @@ int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
29172917
* cause of "wrong memory was mapped in".
29182918
*/
29192919
BUG_ON(err_ptr == NULL);
2920-
return do_remap_mfn(vma, addr, mfn, nr, err_ptr, prot, domid, pages);
2920+
return do_remap_gfn(vma, addr, gfn, nr, err_ptr, prot, domid, pages);
29212921
}
2922-
EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_array);
2922+
EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);
29232923

29242924

29252925
/* Returns: 0 success */
2926-
int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
2926+
int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
29272927
int numpgs, struct page **pages)
29282928
{
29292929
if (!pages || !xen_feature(XENFEAT_auto_translated_physmap))
@@ -2935,4 +2935,4 @@ int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
29352935
return -EINVAL;
29362936
#endif
29372937
}
2938-
EXPORT_SYMBOL_GPL(xen_unmap_domain_mfn_range);
2938+
EXPORT_SYMBOL_GPL(xen_unmap_domain_gfn_range);

‎drivers/xen/privcmd.c‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,16 @@ static int traverse_pages_block(unsigned nelem, size_t size,
193193
return ret;
194194
}
195195

196-
struct mmap_mfn_state {
196+
struct mmap_gfn_state {
197197
unsigned long va;
198198
struct vm_area_struct *vma;
199199
domid_t domain;
200200
};
201201

202-
static int mmap_mfn_range(void *data, void *state)
202+
static int mmap_gfn_range(void *data, void *state)
203203
{
204204
struct privcmd_mmap_entry *msg = data;
205-
struct mmap_mfn_state *st = state;
205+
struct mmap_gfn_state *st = state;
206206
struct vm_area_struct *vma = st->vma;
207207
int rc;
208208

@@ -216,7 +216,7 @@ static int mmap_mfn_range(void *data, void *state)
216216
((msg->va+(msg->npages<<PAGE_SHIFT)) > vma->vm_end))
217217
return -EINVAL;
218218

219-
rc = xen_remap_domain_mfn_range(vma,
219+
rc = xen_remap_domain_gfn_range(vma,
220220
msg->va & PAGE_MASK,
221221
msg->mfn, msg->npages,
222222
vma->vm_page_prot,
@@ -236,7 +236,7 @@ static long privcmd_ioctl_mmap(void __user *udata)
236236
struct vm_area_struct *vma;
237237
int rc;
238238
LIST_HEAD(pagelist);
239-
struct mmap_mfn_state state;
239+
struct mmap_gfn_state state;
240240

241241
/* We only support privcmd_ioctl_mmap_batch for auto translated. */
242242
if (xen_feature(XENFEAT_auto_translated_physmap))
@@ -273,7 +273,7 @@ static long privcmd_ioctl_mmap(void __user *udata)
273273

274274
rc = traverse_pages(mmapcmd.num, sizeof(struct privcmd_mmap_entry),
275275
&pagelist,
276-
mmap_mfn_range, &state);
276+
mmap_gfn_range, &state);
277277

278278

279279
out_up:
@@ -299,18 +299,18 @@ struct mmap_batch_state {
299299
int global_error;
300300
int version;
301301

302-
/* User-space mfn array to store errors in the second pass for V1. */
303-
xen_pfn_t __user *user_mfn;
302+
/* User-space gfn array to store errors in the second pass for V1. */
303+
xen_pfn_t __user *user_gfn;
304304
/* User-space int array to store errors in the second pass for V2. */
305305
int __user *user_err;
306306
};
307307

308-
/* auto translated dom0 note: if domU being created is PV, then mfn is
309-
* mfn(addr on bus). If it's auto xlated, then mfn is pfn (input to HAP).
308+
/* auto translated dom0 note: if domU being created is PV, then gfn is
309+
* mfn(addr on bus). If it's auto xlated, then gfn is pfn (input to HAP).
310310
*/
311311
static int mmap_batch_fn(void *data, int nr, void *state)
312312
{
313-
xen_pfn_t *mfnp = data;
313+
xen_pfn_t *gfnp = data;
314314
struct mmap_batch_state *st = state;
315315
struct vm_area_struct *vma = st->vma;
316316
struct page **pages = vma->vm_private_data;
@@ -321,8 +321,8 @@ static int mmap_batch_fn(void *data, int nr, void *state)
321321
cur_pages = &pages[st->index];
322322

323323
BUG_ON(nr < 0);
324-
ret = xen_remap_domain_mfn_array(st->vma, st->va & PAGE_MASK, mfnp, nr,
325-
(int *)mfnp, st->vma->vm_page_prot,
324+
ret = xen_remap_domain_gfn_array(st->vma, st->va & PAGE_MASK, gfnp, nr,
325+
(int *)gfnp, st->vma->vm_page_prot,
326326
st->domain, cur_pages);
327327

328328
/* Adjust the global_error? */
@@ -347,22 +347,22 @@ static int mmap_return_error(int err, struct mmap_batch_state *st)
347347

348348
if (st->version == 1) {
349349
if (err) {
350-
xen_pfn_t mfn;
350+
xen_pfn_t gfn;
351351

352-
ret = get_user(mfn, st->user_mfn);
352+
ret = get_user(gfn, st->user_gfn);
353353
if (ret < 0)
354354
return ret;
355355
/*
356356
* V1 encodes the error codes in the 32bit top
357-
* nibble of the mfn (with its known
357+
* nibble of the gfn (with its known
358358
* limitations vis-a-vis 64 bit callers).
359359
*/
360-
mfn |= (err == -ENOENT) ?
360+
gfn |= (err == -ENOENT) ?
361361
PRIVCMD_MMAPBATCH_PAGED_ERROR :
362362
PRIVCMD_MMAPBATCH_MFN_ERROR;
363-
return __put_user(mfn, st->user_mfn++);
363+
return __put_user(gfn, st->user_gfn++);
364364
} else
365-
st->user_mfn++;
365+
st->user_gfn++;
366366
} else { /* st->version == 2 */
367367
if (err)
368368
return __put_user(err, st->user_err++);
@@ -388,7 +388,7 @@ static int mmap_return_errors(void *data, int nr, void *state)
388388
return 0;
389389
}
390390

391-
/* Allocate pfns that are then mapped with gmfns from foreign domid. Update
391+
/* Allocate pfns that are then mapped with gfns from foreign domid. Update
392392
* the vma with the page info to use later.
393393
* Returns: 0 if success, otherwise -errno
394394
*/
@@ -526,7 +526,7 @@ static long privcmd_ioctl_mmap_batch(void __user *udata, int version)
526526

527527
if (state.global_error) {
528528
/* Write back errors in second pass. */
529-
state.user_mfn = (xen_pfn_t *)m.arr;
529+
state.user_gfn = (xen_pfn_t *)m.arr;
530530
state.user_err = m.err;
531531
ret = traverse_pages_block(m.num, sizeof(xen_pfn_t),
532532
&pagelist, mmap_return_errors, &state);
@@ -587,7 +587,7 @@ static void privcmd_close(struct vm_area_struct *vma)
587587
if (!xen_feature(XENFEAT_auto_translated_physmap) || !numpgs || !pages)
588588
return;
589589

590-
rc = xen_unmap_domain_mfn_range(vma, numpgs, pages);
590+
rc = xen_unmap_domain_gfn_range(vma, numpgs, pages);
591591
if (rc == 0)
592592
free_xenballooned_pages(numpgs, pages);
593593
else

‎drivers/xen/xlate_mmu.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
#include <xen/interface/xen.h>
3939
#include <xen/interface/memory.h>
4040

41-
/* map fgmfn of domid to lpfn in the current domain */
42-
static int map_foreign_page(unsigned long lpfn, unsigned long fgmfn,
41+
/* map fgfn of domid to lpfn in the current domain */
42+
static int map_foreign_page(unsigned long lpfn, unsigned long fgfn,
4343
unsigned int domid)
4444
{
4545
int rc;
@@ -49,7 +49,7 @@ static int map_foreign_page(unsigned long lpfn, unsigned long fgmfn,
4949
.size = 1,
5050
.space = XENMAPSPACE_gmfn_foreign,
5151
};
52-
xen_ulong_t idx = fgmfn;
52+
xen_ulong_t idx = fgfn;
5353
xen_pfn_t gpfn = lpfn;
5454
int err = 0;
5555

@@ -62,13 +62,13 @@ static int map_foreign_page(unsigned long lpfn, unsigned long fgmfn,
6262
}
6363

6464
struct remap_data {
65-
xen_pfn_t *fgmfn; /* foreign domain's gmfn */
65+
xen_pfn_t *fgfn; /* foreign domain's gfn */
6666
pgprot_t prot;
6767
domid_t domid;
6868
struct vm_area_struct *vma;
6969
int index;
7070
struct page **pages;
71-
struct xen_remap_mfn_info *info;
71+
struct xen_remap_gfn_info *info;
7272
int *err_ptr;
7373
int mapped;
7474
};
@@ -82,20 +82,20 @@ static int remap_pte_fn(pte_t *ptep, pgtable_t token, unsigned long addr,
8282
pte_t pte = pte_mkspecial(pfn_pte(pfn, info->prot));
8383
int rc;
8484

85-
rc = map_foreign_page(pfn, *info->fgmfn, info->domid);
85+
rc = map_foreign_page(pfn, *info->fgfn, info->domid);
8686
*info->err_ptr++ = rc;
8787
if (!rc) {
8888
set_pte_at(info->vma->vm_mm, addr, ptep, pte);
8989
info->mapped++;
9090
}
91-
info->fgmfn++;
91+
info->fgfn++;
9292

9393
return 0;
9494
}
9595

9696
int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
9797
unsigned long addr,
98-
xen_pfn_t *mfn, int nr,
98+
xen_pfn_t *gfn, int nr,
9999
int *err_ptr, pgprot_t prot,
100100
unsigned domid,
101101
struct page **pages)
@@ -108,7 +108,7 @@ int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
108108
x86 PVOPS */
109109
BUG_ON(!((vma->vm_flags & (VM_PFNMAP | VM_IO)) == (VM_PFNMAP | VM_IO)));
110110

111-
data.fgmfn = mfn;
111+
data.fgfn = gfn;
112112
data.prot = prot;
113113
data.domid = domid;
114114
data.vma = vma;

‎include/uapi/xen/privcmd.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ struct privcmd_hypercall {
4444

4545
struct privcmd_mmap_entry {
4646
__u64 va;
47+
/*
48+
* This should be a GFN. It's not possible to change the name because
49+
* it's exposed to the user-space.
50+
*/
4751
__u64 mfn;
4852
__u64 npages;
4953
};

‎include/xen/xen-ops.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order);
3030
struct vm_area_struct;
3131

3232
/*
33-
* xen_remap_domain_mfn_array() - map an array of foreign frames
33+
* xen_remap_domain_gfn_array() - map an array of foreign frames
3434
* @vma: VMA to map the pages into
3535
* @addr: Address at which to map the pages
3636
* @gfn: Array of GFNs to map
@@ -46,14 +46,14 @@ struct vm_area_struct;
4646
* Returns the number of successfully mapped frames, or a -ve error
4747
* code.
4848
*/
49-
int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
49+
int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
5050
unsigned long addr,
5151
xen_pfn_t *gfn, int nr,
5252
int *err_ptr, pgprot_t prot,
5353
unsigned domid,
5454
struct page **pages);
5555

56-
/* xen_remap_domain_mfn_range() - map a range of foreign frames
56+
/* xen_remap_domain_gfn_range() - map a range of foreign frames
5757
* @vma: VMA to map the pages into
5858
* @addr: Address at which to map the pages
5959
* @gfn: First GFN to map.
@@ -65,12 +65,12 @@ int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
6565
* Returns the number of successfully mapped frames, or a -ve error
6666
* code.
6767
*/
68-
int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
68+
int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
6969
unsigned long addr,
7070
xen_pfn_t gfn, int nr,
7171
pgprot_t prot, unsigned domid,
7272
struct page **pages);
73-
int xen_unmap_domain_mfn_range(struct vm_area_struct *vma,
73+
int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
7474
int numpgs, struct page **pages);
7575
int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
7676
unsigned long addr,

0 commit comments

Comments
 (0)