From: Rob Herring <robh@kernel.org>
To: Lakshmi Ramasubramanian <nramas@linux.microsoft.com>
Cc: zohar@linux.ibm.com, bauerman@linux.ibm.com,
takahiro.akashi@linaro.org, gregkh@linuxfoundation.org,
will@kernel.org, catalin.marinas@arm.com, mpe@ellerman.id.au,
james.morse@arm.com, sashal@kernel.org, benh@kernel.crashing.org,
paulus@samba.org, frowand.list@gmail.com,
vincenzo.frascino@arm.com, mark.rutland@arm.com,
dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com,
pasha.tatashin@soleen.com, allison@lohutok.net,
masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com,
hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr,
prsriva@linux.microsoft.com, balajib@linux.microsoft.com,
linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v11 2/8] powerpc: Move ima buffer functions to drivers/of/kexec.c
Date: Tue, 15 Dec 2020 12:16:01 -0600 [thread overview]
Message-ID: <20201215181601.GA4105316@robh.at.kernel.org> (raw)
In-Reply-To: <20201214191854.9050-3-nramas@linux.microsoft.com>
On Mon, Dec 14, 2020 at 11:18:48AM -0800, Lakshmi Ramasubramanian wrote:
> The functions do_get_kexec_buffer() and get_addr_size_cells(),
> defined in arch/powerpc/kexec/ima.c, retrieve the address and size
> of the given property from the device tree blob. These functions do
> not have architecture specific code, but are currently limited to
> powerpc. do_get_kexec_buffer() correctly handles a device tree property
> that is a child node of the root node, but not anything other than
> the immediate root child nodes.
>
> Move architecture independent functions get_ima_kexec_buffer() and
> get_root_addr_size_cells() to "drivers/of/kexec.c". These functions
> retrieve the chosen node "linux,ima-kexec-buffer" from the device tree,
> and return the address and size of the buffer used for carrying forward
> the IMA measurement log across kexec system call.
>
> Co-developed-by: Prakhar Srivastava <prsriva@linux.microsoft.com>
> Signed-off-by: Prakhar Srivastava <prsriva@linux.microsoft.com>
> Signed-off-by: Lakshmi Ramasubramanian <nramas@linux.microsoft.com>
> ---
> drivers/of/kexec.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++
> include/linux/of.h | 3 ++
> 2 files changed, 71 insertions(+)
>
> diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c
> index 66787be081fe..9af5371340b1 100644
> --- a/drivers/of/kexec.c
> +++ b/drivers/of/kexec.c
> @@ -30,6 +30,10 @@
> /**
> * fdt_find_and_del_mem_rsv - delete memory reservation with given address and size
> *
> + * @fdt: Flattened Device Tree to update
> + * @start: Starting address of the reservation to delete
> + * @size: Size of the reservation to delete
> + *
This belongs in the patch adding fdt_find_and_del_mem_rsv.
> * Return: 0 on success, or negative errno on error.
> */
> static int fdt_find_and_del_mem_rsv(void *fdt, unsigned long start, unsigned long size)
> @@ -226,3 +230,67 @@ int of_kexec_setup_new_fdt(const struct kimage *image, void *fdt,
>
> return 0;
> }
> +
> +/**
> + * get_root_addr_size_cells - Get address and size of root node
> + *
> + * @addr_cells: Return address of the root node
> + * @size_cells: Return size of the root node
> + *
> + * Return: 0 on success, or negative errno on error.
> + */
> +int get_root_addr_size_cells(int *addr_cells, int *size_cells)
> +{
> + struct device_node *root;
> +
> + root = of_find_node_by_path("/");
> + if (!root)
> + return -EINVAL;
> +
> + *addr_cells = of_n_addr_cells(root);
> + *size_cells = of_n_size_cells(root);
> +
> + of_node_put(root);
> +
> + return 0;
> +}
> +
> +/**
> + * get_ima_kexec_buffer - Get address and size of IMA kexec buffer
> + *
> + * @fdt: Flattened Device Tree
> + * @chosen_node: Offset of chosen node in the FDT
> + * @addr: Return address of the node
> + * @size: Return size of the node
> + *
> + * Return: 0 on success, or negative errno on error.
> + */
> +int get_ima_kexec_buffer(void *fdt, int chosen_node,
> + unsigned long *addr, size_t *size)
> +{
> + const void *prop;
> + int addr_cells, size_cells, prop_len;
> + int rc;
> +
> + rc = get_root_addr_size_cells(&addr_cells, &size_cells);
> + if (rc)
> + return rc;
> +
> + if (fdt)
> + prop = fdt_getprop(fdt, chosen_node,
> + "linux,ima-kexec-buffer", &prop_len);
> + else
> + prop = of_get_property(of_chosen,
> + "linux,ima-kexec-buffer", &prop_len);
This is an odd structure. The DT APIs are generally of_foo() for
unflattened tree and of_flat_foo() for FDT.
> +
> + if (!prop)
> + return -ENOENT;
> +
> + if (prop_len < 4 * (addr_cells + size_cells))
> + return -EINVAL;
> +
> + *addr = of_read_number(prop, addr_cells);
> + *size = of_read_number(prop + 4 * addr_cells, size_cells);
> +
> + return 0;
> +}
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 3375f5295875..fb2ef274135d 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -562,6 +562,9 @@ struct kimage;
> int of_kexec_setup_new_fdt(const struct kimage *image, void *fdt,
> unsigned long initrd_load_addr, unsigned long initrd_len,
> const char *cmdline);
> +int get_root_addr_size_cells(int *addr_cells, int *size_cells);
> +int get_ima_kexec_buffer(void *fdt, int chosen_node,
> + unsigned long *addr, size_t *size);
The whole point of moving code out of arch code was to avoid all these
cross tree calls.
I was expecting the next step to be moving setup_ima_buffer() call into
of_kexec_setup_new_fdt with all the code in powerpc/kexec/ima.c moved
here. Then the end result to enable on arm64 is just selecting
HAVE_IMA_KEXEC and adding fields to kimage_arch.
Rob
WARNING: multiple messages have this Message-ID (diff)
From: Rob Herring <robh@kernel.org>
To: Lakshmi Ramasubramanian <nramas@linux.microsoft.com>
Cc: mark.rutland@arm.com, benh@kernel.crashing.org,
bhsharma@redhat.com, tao.li@vivo.com, zohar@linux.ibm.com,
paulus@samba.org, vincenzo.frascino@arm.com,
frowand.list@gmail.com, sashal@kernel.org, mpe@ellerman.id.au,
masahiroy@kernel.org, jmorris@namei.org,
takahiro.akashi@linaro.org, linux-arm-kernel@lists.infradead.org,
catalin.marinas@arm.com, serge@hallyn.com,
devicetree@vger.kernel.org, pasha.tatashin@soleen.com,
will@kernel.org, prsriva@linux.microsoft.com,
hsinyi@chromium.org, allison@lohutok.net,
christophe.leroy@c-s.fr, mbrugger@suse.com,
balajib@linux.microsoft.com, dmitry.kasatkin@gmail.com,
linux-kernel@vger.kernel.org, james.morse@arm.com,
gregkh@linuxfoundation.org, linux-integrity@vger.kernel.org,
bauerman@linux.ibm.com
Subject: Re: [PATCH v11 2/8] powerpc: Move ima buffer functions to drivers/of/kexec.c
Date: Tue, 15 Dec 2020 12:16:01 -0600 [thread overview]
Message-ID: <20201215181601.GA4105316@robh.at.kernel.org> (raw)
In-Reply-To: <20201214191854.9050-3-nramas@linux.microsoft.com>
On Mon, Dec 14, 2020 at 11:18:48AM -0800, Lakshmi Ramasubramanian wrote:
> The functions do_get_kexec_buffer() and get_addr_size_cells(),
> defined in arch/powerpc/kexec/ima.c, retrieve the address and size
> of the given property from the device tree blob. These functions do
> not have architecture specific code, but are currently limited to
> powerpc. do_get_kexec_buffer() correctly handles a device tree property
> that is a child node of the root node, but not anything other than
> the immediate root child nodes.
>
> Move architecture independent functions get_ima_kexec_buffer() and
> get_root_addr_size_cells() to "drivers/of/kexec.c". These functions
> retrieve the chosen node "linux,ima-kexec-buffer" from the device tree,
> and return the address and size of the buffer used for carrying forward
> the IMA measurement log across kexec system call.
>
> Co-developed-by: Prakhar Srivastava <prsriva@linux.microsoft.com>
> Signed-off-by: Prakhar Srivastava <prsriva@linux.microsoft.com>
> Signed-off-by: Lakshmi Ramasubramanian <nramas@linux.microsoft.com>
> ---
> drivers/of/kexec.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++
> include/linux/of.h | 3 ++
> 2 files changed, 71 insertions(+)
>
> diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c
> index 66787be081fe..9af5371340b1 100644
> --- a/drivers/of/kexec.c
> +++ b/drivers/of/kexec.c
> @@ -30,6 +30,10 @@
> /**
> * fdt_find_and_del_mem_rsv - delete memory reservation with given address and size
> *
> + * @fdt: Flattened Device Tree to update
> + * @start: Starting address of the reservation to delete
> + * @size: Size of the reservation to delete
> + *
This belongs in the patch adding fdt_find_and_del_mem_rsv.
> * Return: 0 on success, or negative errno on error.
> */
> static int fdt_find_and_del_mem_rsv(void *fdt, unsigned long start, unsigned long size)
> @@ -226,3 +230,67 @@ int of_kexec_setup_new_fdt(const struct kimage *image, void *fdt,
>
> return 0;
> }
> +
> +/**
> + * get_root_addr_size_cells - Get address and size of root node
> + *
> + * @addr_cells: Return address of the root node
> + * @size_cells: Return size of the root node
> + *
> + * Return: 0 on success, or negative errno on error.
> + */
> +int get_root_addr_size_cells(int *addr_cells, int *size_cells)
> +{
> + struct device_node *root;
> +
> + root = of_find_node_by_path("/");
> + if (!root)
> + return -EINVAL;
> +
> + *addr_cells = of_n_addr_cells(root);
> + *size_cells = of_n_size_cells(root);
> +
> + of_node_put(root);
> +
> + return 0;
> +}
> +
> +/**
> + * get_ima_kexec_buffer - Get address and size of IMA kexec buffer
> + *
> + * @fdt: Flattened Device Tree
> + * @chosen_node: Offset of chosen node in the FDT
> + * @addr: Return address of the node
> + * @size: Return size of the node
> + *
> + * Return: 0 on success, or negative errno on error.
> + */
> +int get_ima_kexec_buffer(void *fdt, int chosen_node,
> + unsigned long *addr, size_t *size)
> +{
> + const void *prop;
> + int addr_cells, size_cells, prop_len;
> + int rc;
> +
> + rc = get_root_addr_size_cells(&addr_cells, &size_cells);
> + if (rc)
> + return rc;
> +
> + if (fdt)
> + prop = fdt_getprop(fdt, chosen_node,
> + "linux,ima-kexec-buffer", &prop_len);
> + else
> + prop = of_get_property(of_chosen,
> + "linux,ima-kexec-buffer", &prop_len);
This is an odd structure. The DT APIs are generally of_foo() for
unflattened tree and of_flat_foo() for FDT.
> +
> + if (!prop)
> + return -ENOENT;
> +
> + if (prop_len < 4 * (addr_cells + size_cells))
> + return -EINVAL;
> +
> + *addr = of_read_number(prop, addr_cells);
> + *size = of_read_number(prop + 4 * addr_cells, size_cells);
> +
> + return 0;
> +}
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 3375f5295875..fb2ef274135d 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -562,6 +562,9 @@ struct kimage;
> int of_kexec_setup_new_fdt(const struct kimage *image, void *fdt,
> unsigned long initrd_load_addr, unsigned long initrd_len,
> const char *cmdline);
> +int get_root_addr_size_cells(int *addr_cells, int *size_cells);
> +int get_ima_kexec_buffer(void *fdt, int chosen_node,
> + unsigned long *addr, size_t *size);
The whole point of moving code out of arch code was to avoid all these
cross tree calls.
I was expecting the next step to be moving setup_ima_buffer() call into
of_kexec_setup_new_fdt with all the code in powerpc/kexec/ima.c moved
here. Then the end result to enable on arm64 is just selecting
HAVE_IMA_KEXEC and adding fields to kimage_arch.
Rob
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-12-15 18:18 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-14 19:18 [PATCH v11 0/8] Carry forward IMA measurement log on kexec on ARM64 Lakshmi Ramasubramanian
2020-12-14 19:18 ` Lakshmi Ramasubramanian
2020-12-14 19:18 ` [PATCH v11 1/8] powerpc: Fix compiler warnings and errors Lakshmi Ramasubramanian
2020-12-14 19:18 ` Lakshmi Ramasubramanian
2020-12-14 19:18 ` [PATCH v11 2/8] powerpc: Move ima buffer functions to drivers/of/kexec.c Lakshmi Ramasubramanian
2020-12-14 19:18 ` Lakshmi Ramasubramanian
2020-12-15 18:16 ` Rob Herring [this message]
2020-12-15 18:16 ` Rob Herring
2020-12-16 16:58 ` Lakshmi Ramasubramanian
2020-12-16 16:58 ` Lakshmi Ramasubramanian
2020-12-14 19:18 ` [PATCH v11 3/8] powerpc: Use ima kexec node functions Lakshmi Ramasubramanian
2020-12-14 19:18 ` Lakshmi Ramasubramanian
2020-12-14 19:18 ` [PATCH v11 4/8] powerpc: Move remove_ima_buffer() to drivers/of/kexec.c Lakshmi Ramasubramanian
2020-12-14 19:18 ` Lakshmi Ramasubramanian
2020-12-14 19:18 ` [PATCH v11 5/8] powerpc: Move ima_get_kexec_buffer() and ima_free_kexec_buffer() to ima Lakshmi Ramasubramanian
2020-12-14 19:18 ` Lakshmi Ramasubramanian
2020-12-14 19:18 ` [PATCH v11 6/8] powerpc: Move arch_ima_add_kexec_buffer " Lakshmi Ramasubramanian
2020-12-14 19:18 ` Lakshmi Ramasubramanian
2020-12-14 19:18 ` [PATCH v11 7/8] arm64: Free DTB buffer if fdt_open_into() fails Lakshmi Ramasubramanian
2020-12-14 19:18 ` Lakshmi Ramasubramanian
2020-12-14 19:18 ` [PATCH v11 8/8] arm64: Add IMA log information in kimage used for kexec Lakshmi Ramasubramanian
2020-12-14 19:18 ` Lakshmi Ramasubramanian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201215181601.GA4105316@robh.at.kernel.org \
--to=robh@kernel.org \
--cc=allison@lohutok.net \
--cc=balajib@linux.microsoft.com \
--cc=bauerman@linux.ibm.com \
--cc=benh@kernel.crashing.org \
--cc=bhsharma@redhat.com \
--cc=catalin.marinas@arm.com \
--cc=christophe.leroy@c-s.fr \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.kasatkin@gmail.com \
--cc=frowand.list@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=hsinyi@chromium.org \
--cc=james.morse@arm.com \
--cc=jmorris@namei.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=masahiroy@kernel.org \
--cc=mbrugger@suse.com \
--cc=mpe@ellerman.id.au \
--cc=nramas@linux.microsoft.com \
--cc=pasha.tatashin@soleen.com \
--cc=paulus@samba.org \
--cc=prsriva@linux.microsoft.com \
--cc=sashal@kernel.org \
--cc=serge@hallyn.com \
--cc=takahiro.akashi@linaro.org \
--cc=tao.li@vivo.com \
--cc=vincenzo.frascino@arm.com \
--cc=will@kernel.org \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.