From: Samuel Thibault <samuel.thibault@ens-lyon.org>
To: Juergen Gross <jgross@suse.com>
Cc: minios-devel@lists.xenproject.org,
xen-devel@lists.xenproject.org, wei.liu2@citrix.com
Subject: Re: [PATCH v2 11/18] mini-os: add checks for out of memory
Date: Wed, 10 Aug 2016 22:18:54 +0200 [thread overview]
Message-ID: <20160810201854.GX16772@var.home> (raw)
In-Reply-To: <1470418562-11234-12-git-send-email-jgross@suse.com>
Juergen Gross, on Fri 05 Aug 2016 19:35:55 +0200, wrote:
> There are several core functions in Mini-OS not checking for failed
> memory allocations. Add such checks.
>
> Add do_map_frames() dummy function to arm architecture as it will be
> needed in future for compilations to succeed.
>
> Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> ---
> arch/arm/mm.c | 8 ++++++++
> arch/x86/mm.c | 26 +++++++++++++++++++-------
> include/mm.h | 2 +-
> 3 files changed, 28 insertions(+), 8 deletions(-)
>
> diff --git a/arch/arm/mm.c b/arch/arm/mm.c
> index f75888d..fc8d4bc 100644
> --- a/arch/arm/mm.c
> +++ b/arch/arm/mm.c
> @@ -1,6 +1,7 @@
> #include <mini-os/console.h>
> #include <xen/memory.h>
> #include <arch_mm.h>
> +#include <mini-os/errno.h>
> #include <mini-os/hypervisor.h>
> #include <libfdt.h>
> #include <lib.h>
> @@ -79,6 +80,13 @@ void arch_init_demand_mapping_area(void)
> {
> }
>
> +int do_map_frames(unsigned long addr,
> + const unsigned long *f, unsigned long n, unsigned long stride,
> + unsigned long increment, domid_t id, int *err, unsigned long prot)
> +{
> + return -ENOSYS;
> +}
> +
> /* Get Xen's suggested physical page assignments for the grant table. */
> static paddr_t get_gnttab_base(void)
> {
> diff --git a/arch/x86/mm.c b/arch/x86/mm.c
> index e2f026b..12f7fe4 100644
> --- a/arch/x86/mm.c
> +++ b/arch/x86/mm.c
> @@ -34,6 +34,7 @@
> * DEALINGS IN THE SOFTWARE.
> */
>
> +#include <mini-os/errno.h>
> #include <mini-os/os.h>
> #include <mini-os/hypervisor.h>
> #include <mini-os/mm.h>
> @@ -354,6 +355,8 @@ pgentry_t *need_pgt(unsigned long va)
> if ( !(tab[offset] & _PAGE_PRESENT) )
> {
> pt_pfn = virt_to_pfn(alloc_page());
> + if ( !pt_pfn )
> + return NULL;
> new_pt_frame(&pt_pfn, pt_mfn, offset, L3_FRAME);
> }
> ASSERT(tab[offset] & _PAGE_PRESENT);
> @@ -364,6 +367,8 @@ pgentry_t *need_pgt(unsigned long va)
> if ( !(tab[offset] & _PAGE_PRESENT) )
> {
> pt_pfn = virt_to_pfn(alloc_page());
> + if ( !pt_pfn )
> + return NULL;
> new_pt_frame(&pt_pfn, pt_mfn, offset, L2_FRAME);
> }
> ASSERT(tab[offset] & _PAGE_PRESENT);
> @@ -373,6 +378,8 @@ pgentry_t *need_pgt(unsigned long va)
> if ( !(tab[offset] & _PAGE_PRESENT) )
> {
> pt_pfn = virt_to_pfn(alloc_page());
> + if ( !pt_pfn )
> + return NULL;
> new_pt_frame(&pt_pfn, pt_mfn, offset, L1_FRAME);
> }
> ASSERT(tab[offset] & _PAGE_PRESENT);
> @@ -445,10 +452,10 @@ unsigned long allocate_ondemand(unsigned long n, unsigned long alignment)
> * va. map f[i*stride]+i*increment for i in 0..n-1.
> */
> #define MAP_BATCH ((STACK_SIZE / 2) / sizeof(mmu_update_t))
> -void do_map_frames(unsigned long va,
> - const unsigned long *mfns, unsigned long n,
> - unsigned long stride, unsigned long incr,
> - domid_t id, int *err, unsigned long prot)
> +int do_map_frames(unsigned long va,
> + const unsigned long *mfns, unsigned long n,
> + unsigned long stride, unsigned long incr,
> + domid_t id, int *err, unsigned long prot)
> {
> pgentry_t *pgt = NULL;
> unsigned long done = 0;
> @@ -458,7 +465,7 @@ void do_map_frames(unsigned long va,
> if ( !mfns )
> {
> printk("do_map_frames: no mfns supplied\n");
> - return;
> + return -EINVAL;
> }
> DEBUG("va=%p n=0x%lx, mfns[0]=0x%lx stride=0x%lx incr=0x%lx prot=0x%lx\n",
> va, n, mfns[0], stride, incr, prot);
> @@ -484,7 +491,9 @@ void do_map_frames(unsigned long va,
> {
> if ( !pgt || !(va & L1_MASK) )
> pgt = need_pgt(va);
> -
> + if ( !pgt )
> + return -ENOMEM;
> +
> mmu_updates[i].ptr = virt_to_mach(pgt) | MMU_NORMAL_PT_UPDATE;
> mmu_updates[i].val = ((pgentry_t)(mfns[(done + i) * stride] +
> (done + i) * incr)
> @@ -505,6 +514,8 @@ void do_map_frames(unsigned long va,
> }
> done += todo;
> }
> +
> + return 0;
> }
>
> /*
> @@ -521,7 +532,8 @@ void *map_frames_ex(const unsigned long *mfns, unsigned long n,
> if ( !va )
> return NULL;
>
> - do_map_frames(va, mfns, n, stride, incr, id, err, prot);
> + if ( do_map_frames(va, mfns, n, stride, incr, id, err, prot) )
> + return NULL;
>
> return (void *)va;
> }
> diff --git a/include/mm.h b/include/mm.h
> index a22dcd1..9244e26 100644
> --- a/include/mm.h
> +++ b/include/mm.h
> @@ -68,7 +68,7 @@ unsigned long allocate_ondemand(unsigned long n, unsigned long alignment);
> void *map_frames_ex(const unsigned long *f, unsigned long n, unsigned long stride,
> unsigned long increment, unsigned long alignment, domid_t id,
> int *err, unsigned long prot);
> -void do_map_frames(unsigned long addr,
> +int do_map_frames(unsigned long addr,
> const unsigned long *f, unsigned long n, unsigned long stride,
> unsigned long increment, domid_t id, int *err, unsigned long prot);
> int unmap_frames(unsigned long va, unsigned long num_frames);
> --
> 2.6.6
>
--
Samuel
"How should I know if it works? That's what beta testers are for. I only
coded it."
(Attributed to Linus Torvalds, somewhere in a posting)
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-08-10 20:18 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-05 17:35 [PATCH v2 00/18] mini-os: support of auto-ballooning Juergen Gross
2016-08-05 17:35 ` [PATCH v2 01/18] mini-os: correct first free pfn Juergen Gross
2016-08-10 20:02 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 02/18] mini-os: remove unused alloc_contig_pages() function Juergen Gross
2016-08-10 20:02 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 03/18] mini-os: remove MM_DEBUG code Juergen Gross
2016-08-10 20:03 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 04/18] mini-os: add description of x86 memory usage Juergen Gross
2016-08-10 20:04 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 05/18] mini-os: add nr_free_pages counter Juergen Gross
2016-08-10 20:05 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 06/18] mini-os: let memory allocation fail if no free page available Juergen Gross
2016-08-10 20:06 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 07/18] mini-os: add ballooning config item Juergen Gross
2016-08-10 20:10 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 08/18] mini-os: get maximum memory size from hypervisor Juergen Gross
2016-08-10 20:11 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 09/18] mini-os: modify virtual memory layout for support of ballooning Juergen Gross
2016-08-10 20:16 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 10/18] mini-os: remove unused mem_test() function Juergen Gross
2016-08-10 20:17 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 11/18] mini-os: add checks for out of memory Juergen Gross
2016-08-10 20:18 ` Samuel Thibault [this message]
2016-08-05 17:35 ` [PATCH v2 12/18] mini-os: don't allocate new pages for level 1 p2m tree Juergen Gross
2016-08-10 20:24 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 13/18] mini-os: add function to map one frame Juergen Gross
2016-08-10 20:26 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 14/18] mini-os: move p2m related macros to header file Juergen Gross
2016-08-10 20:29 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 15/18] mini-os: remap p2m list in case of ballooning Juergen Gross
2016-08-10 20:35 ` Samuel Thibault
2016-08-10 20:41 ` Samuel Thibault
2016-08-11 4:04 ` Juergen Gross
2016-08-05 17:36 ` [PATCH v2 16/18] mini-os: map page allocator's bitmap to virtual kernel area for ballooning Juergen Gross
2016-08-10 20:45 ` Samuel Thibault
2016-08-11 4:05 ` Juergen Gross
2016-08-05 17:36 ` [PATCH v2 17/18] mini-os: add support for ballooning up Juergen Gross
2016-08-10 21:02 ` Samuel Thibault
2016-08-11 5:50 ` Juergen Gross
2016-08-05 17:36 ` [PATCH v2 18/18] mini-os: balloon up in case of oom Juergen Gross
2016-08-10 21:07 ` Samuel Thibault
2016-08-11 5:51 ` Juergen Gross
2016-08-10 21:07 ` [PATCH v2 00/18] mini-os: support of auto-ballooning Samuel Thibault
2016-08-11 5:52 ` Juergen Gross
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=20160810201854.GX16772@var.home \
--to=samuel.thibault@ens-lyon.org \
--cc=jgross@suse.com \
--cc=minios-devel@lists.xenproject.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).