Re: [RFC PATCH v4 25/28] x86: Access the setup data through sysfs decrypted

From: Dave Young
Date: Wed Mar 08 2017 - 02:11:10 EST


On 02/16/17 at 09:47am, Tom Lendacky wrote:
> Use memremap() to map the setup data. This will make the appropriate
> decision as to whether a RAM remapping can be done or if a fallback to
> ioremap_cache() is needed (similar to the setup data debugfs support).
>
> Signed-off-by: Tom Lendacky <thomas.lendacky@xxxxxxx>
> ---
> arch/x86/kernel/ksysfs.c | 27 ++++++++++++++-------------
> 1 file changed, 14 insertions(+), 13 deletions(-)
>
> diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
> index 4afc67f..d653b3e 100644
> --- a/arch/x86/kernel/ksysfs.c
> +++ b/arch/x86/kernel/ksysfs.c
> @@ -16,6 +16,7 @@
> #include <linux/stat.h>
> #include <linux/slab.h>
> #include <linux/mm.h>
> +#include <linux/io.h>
>
> #include <asm/io.h>
> #include <asm/setup.h>
> @@ -79,12 +80,12 @@ static int get_setup_data_paddr(int nr, u64 *paddr)
> *paddr = pa_data;
> return 0;
> }
> - data = ioremap_cache(pa_data, sizeof(*data));
> + data = memremap(pa_data, sizeof(*data), MEMREMAP_WB);
> if (!data)
> return -ENOMEM;
>
> pa_data = data->next;
> - iounmap(data);
> + memunmap(data);
> i++;
> }
> return -EINVAL;
> @@ -97,17 +98,17 @@ static int __init get_setup_data_size(int nr, size_t *size)
> u64 pa_data = boot_params.hdr.setup_data;
>
> while (pa_data) {
> - data = ioremap_cache(pa_data, sizeof(*data));
> + data = memremap(pa_data, sizeof(*data), MEMREMAP_WB);
> if (!data)
> return -ENOMEM;
> if (nr == i) {
> *size = data->len;
> - iounmap(data);
> + memunmap(data);
> return 0;
> }
>
> pa_data = data->next;
> - iounmap(data);
> + memunmap(data);
> i++;
> }
> return -EINVAL;
> @@ -127,12 +128,12 @@ static ssize_t type_show(struct kobject *kobj,
> ret = get_setup_data_paddr(nr, &paddr);
> if (ret)
> return ret;
> - data = ioremap_cache(paddr, sizeof(*data));
> + data = memremap(paddr, sizeof(*data), MEMREMAP_WB);
> if (!data)
> return -ENOMEM;
>
> ret = sprintf(buf, "0x%x\n", data->type);
> - iounmap(data);
> + memunmap(data);
> return ret;
> }
>
> @@ -154,7 +155,7 @@ static ssize_t setup_data_data_read(struct file *fp,
> ret = get_setup_data_paddr(nr, &paddr);
> if (ret)
> return ret;
> - data = ioremap_cache(paddr, sizeof(*data));
> + data = memremap(paddr, sizeof(*data), MEMREMAP_WB);
> if (!data)
> return -ENOMEM;
>
> @@ -170,15 +171,15 @@ static ssize_t setup_data_data_read(struct file *fp,
> goto out;
>
> ret = count;
> - p = ioremap_cache(paddr + sizeof(*data), data->len);
> + p = memremap(paddr + sizeof(*data), data->len, MEMREMAP_WB);
> if (!p) {
> ret = -ENOMEM;
> goto out;
> }
> memcpy(buf, p + off, count);
> - iounmap(p);
> + memunmap(p);
> out:
> - iounmap(data);
> + memunmap(data);
> return ret;
> }
>
> @@ -250,13 +251,13 @@ static int __init get_setup_data_total_num(u64 pa_data, int *nr)
> *nr = 0;
> while (pa_data) {
> *nr += 1;
> - data = ioremap_cache(pa_data, sizeof(*data));
> + data = memremap(pa_data, sizeof(*data), MEMREMAP_WB);
> if (!data) {
> ret = -ENOMEM;
> goto out;
> }
> pa_data = data->next;
> - iounmap(data);
> + memunmap(data);
> }
>
> out:
>

It would be better that these cleanup patches are sent separately.

Acked-by: Dave Young <dyoung@xxxxxxxxxx>

Thanks
Dave