From: "Michał Leszczyński" <michal.leszczynski@cert.pl>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>, Wei Liu <wl@xen.org>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
George Dunlap <george.dunlap@citrix.com>,
Jan Beulich <jbeulich@suse.com>,
Tamas K Lengyel <tamas.k.lengyel@gmail.com>,
"Kang, Luwei" <luwei.kang@intel.com>
Subject: [PATCH v2 1/7] xen/mm: lift 32 item limit from mfn/gfn arrays
Date: Fri, 19 Jun 2020 01:38:00 +0200 (CEST) [thread overview]
Message-ID: <1060400786.9820894.1592523480084.JavaMail.zimbra@cert.pl> (raw)
In-Reply-To: <122238637.9820857.1592523264685.JavaMail.zimbra@cert.pl>
Replace on-stack array allocation with heap allocation
in order to lift the limit of 32 items in mfn/gfn arrays
when calling acquire_resource.
Signed-off-by: Michal Leszczynski <michal.leszczynski@cert.pl>
---
xen/common/memory.c | 39 +++++++++++++++++----------------------
1 file changed, 17 insertions(+), 22 deletions(-)
diff --git a/xen/common/memory.c b/xen/common/memory.c
index 714077c1e5..e02606ebe5 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -1050,12 +1050,7 @@ static int acquire_resource(
{
struct domain *d, *currd = current->domain;
xen_mem_acquire_resource_t xmar;
- /*
- * The mfn_list and gfn_list (below) arrays are ok on stack for the
- * moment since they are small, but if they need to grow in future
- * use-cases then per-CPU arrays or heap allocations may be required.
- */
- xen_pfn_t mfn_list[32];
+ xen_pfn_t *mfn_list;
int rc;
if ( copy_from_guest(&xmar, arg, 1) )
@@ -1064,25 +1059,17 @@ static int acquire_resource(
if ( xmar.pad != 0 )
return -EINVAL;
- if ( guest_handle_is_null(xmar.frame_list) )
- {
- if ( xmar.nr_frames )
- return -EINVAL;
-
- xmar.nr_frames = ARRAY_SIZE(mfn_list);
-
- if ( __copy_field_to_guest(arg, &xmar, nr_frames) )
- return -EFAULT;
-
- return 0;
- }
+ mfn_list = xmalloc_array(xen_pfn_t, xmar.nr_frames);
- if ( xmar.nr_frames > ARRAY_SIZE(mfn_list) )
- return -E2BIG;
+ if ( ! mfn_list )
+ return -EFAULT;
rc = rcu_lock_remote_domain_by_id(xmar.domid, &d);
if ( rc )
+ {
+ xfree(mfn_list);
return rc;
+ }
rc = xsm_domain_resource_map(XSM_DM_PRIV, d);
if ( rc )
@@ -1111,7 +1098,7 @@ static int acquire_resource(
}
else
{
- xen_pfn_t gfn_list[ARRAY_SIZE(mfn_list)];
+ xen_pfn_t *gfn_list;
unsigned int i;
/*
@@ -1120,7 +1107,12 @@ static int acquire_resource(
* resource pages unless the caller is the hardware domain.
*/
if ( !is_hardware_domain(currd) )
- return -EACCES;
+ {
+ rc = -EACCES;
+ goto out;
+ }
+
+ gfn_list = xmalloc_array(xen_pfn_t, xmar.nr_frames);
if ( copy_from_guest(gfn_list, xmar.frame_list, xmar.nr_frames) )
rc = -EFAULT;
@@ -1133,9 +1125,12 @@ static int acquire_resource(
if ( rc && i )
rc = -EIO;
}
+
+ xfree(gfn_list);
}
out:
+ xfree(mfn_list);
rcu_unlock_domain(d);
return rc;
--
2.20.1
next prev parent reply other threads:[~2020-06-18 23:38 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-18 23:34 [PATCH v2 0/7] Implement support for external IPT monitoring Michał Leszczyński
2020-06-18 23:38 ` Michał Leszczyński [this message]
2020-06-19 11:34 ` [PATCH v2 1/7] xen/mm: lift 32 item limit from mfn/gfn arrays Roger Pau Monné
2020-06-19 11:36 ` Michał Leszczyński
2020-06-19 11:48 ` Jan Beulich
2020-06-19 11:51 ` Michał Leszczyński
2020-06-19 12:35 ` Michał Leszczyński
2020-06-19 12:39 ` Jan Beulich
2020-06-22 3:00 ` Michał Leszczyński
2020-06-18 23:39 ` [PATCH v2 2/7] x86/vmx: add Intel PT MSR definitions Michał Leszczyński
2020-06-22 12:35 ` Jan Beulich
2020-06-18 23:40 ` [PATCH v2 3/7] x86/vmx: add IPT cpu feature Michał Leszczyński
2020-06-19 13:44 ` Roger Pau Monné
2020-06-19 14:22 ` Michał Leszczyński
2020-06-19 15:31 ` Roger Pau Monné
2020-06-22 2:49 ` Michał Leszczyński
2020-06-22 8:31 ` Jan Beulich
2020-06-22 12:40 ` Jan Beulich
2020-06-18 23:41 ` [PATCH v2 4/7] x86/vmx: add do_vmtrace_op Michał Leszczyński
2020-06-19 0:46 ` Michał Leszczyński
2020-06-19 15:30 ` Roger Pau Monné
2020-06-19 15:50 ` Jan Beulich
2020-06-22 2:45 ` Michał Leszczyński
2020-06-22 2:56 ` Michał Leszczyński
2020-06-22 8:39 ` Jan Beulich
2020-06-22 13:25 ` Jan Beulich
2020-06-22 14:35 ` Michał Leszczyński
2020-06-22 15:22 ` Jan Beulich
2020-06-22 16:02 ` Michał Leszczyński
2020-06-22 16:16 ` Jan Beulich
2020-06-22 16:22 ` Michał Leszczyński
2020-06-22 16:25 ` Roger Pau Monné
2020-06-22 16:33 ` Michał Leszczyński
2020-06-23 1:04 ` Michał Leszczyński
2020-06-23 8:51 ` Jan Beulich
2020-06-23 17:24 ` Andrew Cooper
2020-06-24 10:03 ` Jan Beulich
2020-06-24 12:40 ` Andrew Cooper
2020-06-24 12:52 ` Tamas K Lengyel
2020-06-24 12:23 ` Michał Leszczyński
2020-06-22 17:05 ` Michał Leszczyński
2020-06-23 8:49 ` Jan Beulich
2020-06-18 23:41 ` [PATCH v2 5/7] tools/libxc: add xc_vmtrace_* functions Michał Leszczyński
2020-06-18 23:42 ` [PATCH v2 6/7] tools/libxl: add vmtrace_pt_size parameter Michał Leszczyński
2020-06-18 23:42 ` [PATCH v2 7/7] tools/proctrace: add proctrace tool Michał Leszczyński
2020-06-18 23:51 ` [PATCH v2 0/7] Implement support for external IPT monitoring Michał Leszczyński
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=1060400786.9820894.1592523480084.JavaMail.zimbra@cert.pl \
--to=michal.leszczynski@cert.pl \
--cc=andrew.cooper3@citrix.com \
--cc=george.dunlap@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=luwei.kang@intel.com \
--cc=sstabellini@kernel.org \
--cc=tamas.k.lengyel@gmail.com \
--cc=wl@xen.org \
--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 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.