From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michal Novotny Subject: Re: [PATCH] Disallow setting maxmem to higher value than total physical memory size Date: Wed, 01 Sep 2010 17:34:10 +0200 Message-ID: <4C7E7272.20509@redhat.com> References: <4C7E47B2.9010805@redhat.com> <1283345049.12544.9494.camel@zakaz.uk.xensource.com> <4C7E4EAD.3060106@redhat.com> <1283348230.12544.9506.camel@zakaz.uk.xensource.com> <4C7E60D0.8050706@redhat.com> <1283354425.12544.9514.camel@zakaz.uk.xensource.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010508060106030905070101" Return-path: In-Reply-To: <1283354425.12544.9514.camel@zakaz.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Ian Campbell Cc: "'xen-devel@lists.xensource.com'" List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --------------010508060106030905070101 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 09/01/2010 05:20 PM, Ian Campbell wrote: > On Wed, 2010-09-01 at 15:18 +0100, Michal Novotny wrote: > > >> Oh, ok. It's not limited to dom0 nevertheless I don't see anything to be >> causing anything bad in domU. Of course, I can limit this to dom0 but >> for domU you can be having e.g. this: >> 1) >> dom0: total memory = 8192 >> domU: memory = 4096, maxmem = 8192 (xm mem-max domU 16384 fails) >> > It is useful, legal and valid to set e.g. maxmem = 12288 here, leaving > memory = 4096. Your patch prevents that. > > That's right. I'm just saying that there's a possibility that there will be wrong data output from `xm list -l` command. >> 2) >> and when you migrate to host B: >> dom0: total memory = 16384 >> domU: memory = 4096, maxmem = 8192 >> > If maxmem = 12288 then it would be possible to balloon this guest up to > 12288 on this system. With your patch it is no longer possible. Note > that maxmem cannot change once the domU is booted so it needs to have > been = 12288 at the time the guest was created on Host A. > > That's correct. >> Or should I just ignore the possibility domU maxmem could be set to >> higher value than host machine could provide and should I limit my check >> to dom0 only? >> > Yes! > > I haven't considered the applicability of this patch to dom0 > particularly deeply but it is wrong to enforce this constraint on domUs. > > Ian. > > Ok, I'm attaching the patch now for review. Now it's working fine for dom0 to limit just dom0. What do you think about this? Michal -- Michal Novotny, RHCE Virtualization Team (xen userspace), Red Hat --------------010508060106030905070101 Content-Type: text/x-patch; name="xen-disallow-setting-max-mem-higher-than-total-phys-mem.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="xen-disallow-setting-max-mem-higher-than-total-phys-mem.patc"; filename*1="h" diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index 4360ce2..aabc30f 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -152,6 +152,12 @@ def recreate(info, priv): assert not info['dying'] + # Validate domain maxmem value not to be higher than dom0 physical memory + if priv: + total_mem = int(xc.physinfo()['total_memory']) + if info['maxmem_kb'] > total_mem: + info['maxmem_kb'] = total_mem + xeninfo = XendConfig.XendConfig(dominfo = info) xeninfo['is_control_domain'] = priv xeninfo['is_a_template'] = False @@ -1490,6 +1496,14 @@ class XendDomainInfo: """Set the maximum memory limit of this domain @param limit: In MiB. """ + # Get total memory and convert to MiB + if self.info['is_control_domain']: + total_mem = int(xc.physinfo()['total_memory'] / 1024) + + if limit <= 0 or limit > total_mem: + raise XendError('Invalid memory size, only positive values ' + 'up to %s MiB are valid' % total_mem) + log.debug("Setting memory maximum of domain %s (%s) to %d MiB.", self.info['name_label'], str(self.domid), limit) --------------010508060106030905070101 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------010508060106030905070101--