Re: [PATCH v5 02/10] mm, x86: Add support for eXclusive Page Frame Ownership (XPFO)
From: Laura Abbott
Date: Mon Aug 14 2017 - 14:51:10 EST
On 08/09/2017 01:07 PM, Tycho Andersen wrote:
> diff --git a/mm/xpfo.c b/mm/xpfo.c
> new file mode 100644
> index 000000000000..3cd45f68b5ad
> --- /dev/null
> +++ b/mm/xpfo.c
> @@ -0,0 +1,208 @@
> +/*
> + * Copyright (C) 2017 Hewlett Packard Enterprise Development, L.P.
> + * Copyright (C) 2016 Brown University. All rights reserved.
> + *
> + * Authors:
> + * Juerg Haefliger <juerg.haefliger@xxxxxxx>
> + * Vasileios P. Kemerlis <vpk@xxxxxxxxxxxx>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License version 2 as published by
> + * the Free Software Foundation.
> + */
> +
> +#include <linux/mm.h>
> +#include <linux/module.h>
> +#include <linux/page_ext.h>
> +#include <linux/xpfo.h>
> +
> +#include <asm/tlbflush.h>
> +
> +/* XPFO page state flags */
> +enum xpfo_flags {
> + XPFO_PAGE_USER, /* Page is allocated to user-space */
> + XPFO_PAGE_UNMAPPED, /* Page is unmapped from the linear map */
> +};
> +
> +/* Per-page XPFO house-keeping data */
> +struct xpfo {
> + unsigned long flags; /* Page state */
> + bool inited; /* Map counter and lock initialized */
> + atomic_t mapcount; /* Counter for balancing map/unmap requests */
> + spinlock_t maplock; /* Lock to serialize map/unmap requests */
> +};
> +
> +DEFINE_STATIC_KEY_FALSE(xpfo_inited);
> +
> +static bool xpfo_disabled __initdata;
> +
> +static int __init noxpfo_param(char *str)
> +{
> + xpfo_disabled = true;
> +
> + return 0;
> +}
> +
> +early_param("noxpfo", noxpfo_param);
> +
> +static bool __init need_xpfo(void)
> +{
> + if (xpfo_disabled) {
> + printk(KERN_INFO "XPFO disabled\n");
> + return false;
> + }
> +
> + return true;
> +}
> +
> +static void init_xpfo(void)
> +{
> + printk(KERN_INFO "XPFO enabled\n");
> + static_branch_enable(&xpfo_inited);
> +}
> +
> +struct page_ext_operations page_xpfo_ops = {
> + .size = sizeof(struct xpfo),
> + .need = need_xpfo,
> + .init = init_xpfo,
> +};
> +
> +static inline struct xpfo *lookup_xpfo(struct page *page)
> +{
> + return (void *)lookup_page_ext(page) + page_xpfo_ops.offset;
> +}
lookup_page_ext can return NULL so this function and its callers
need to account for that.
Thanks,
Laura