From patchwork Mon Jan 27 09:38:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 11352281 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F32914B4 for ; Mon, 27 Jan 2020 09:39:50 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DF60F214DB for ; Mon, 27 Jan 2020 09:39:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF60F214DB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iw0qh-00089f-Ns; Mon, 27 Jan 2020 09:38:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iw0qf-00089a-U6 for xen-devel@lists.xenproject.org; Mon, 27 Jan 2020 09:38:25 +0000 X-Inumbo-ID: becae878-40e8-11ea-9fd7-bc764e2007e4 Received: from mail-wm1-f65.google.com (unknown [209.85.128.65]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id becae878-40e8-11ea-9fd7-bc764e2007e4; Mon, 27 Jan 2020 09:38:17 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id a9so1303321wmj.3 for ; Mon, 27 Jan 2020 01:38:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7yDYDUuBnKkaTfZ4nQFYkDd4vx/FuI+FIuhi5mEE3iM=; b=NPF9Z5hRmm6gWMuAAb4yzb0Tm6/fwsl1fR7WhljM/toLg0GWpTzRwIhwUgRgAYm9D+ 0hiIOzD6/cnpIT1YuRn4X8CsfGvpqgq5LqrjL0DPGrVsSkaVbrB9nZqN3z0wIiCJUXWk DYgiS2VLDx/aRcGzYt4GMaNBlJ9NmVrIGz9qWSUCJOdVJsX9RbUQu3kR44zRkn459bO3 LzvDMPc6HMWQrOe+pEOmAfQo+DhkA9jb3Ssi9/G3vY94NexdXt/pOaPwG6cvHyJbAC6c g9kMsFCfk6YfgsZKjAX2KK2MchExqicbRk9hr3GmA3UC08dprAGa0IVoJrcQYCHX28vm c9aw== X-Gm-Message-State: APjAAAWJWg8CpXlcjQfqTwkhnBNg2F2RGA2ml9iLT0rMdwlMZ6SlaLJd OOJHIkLCE2/XMzwuiaKrioyt7OGrhFs= X-Google-Smtp-Source: APXvYqwDx+bf4y/0kiWFSH257Q8SRe0amczRu1cYZfqZ/PvhnO84CkFSfPfTVXqyBDcIylDZ8KuhTQ== X-Received: by 2002:a05:600c:d5:: with SMTP id u21mr12768315wmm.98.1580117896058; Mon, 27 Jan 2020 01:38:16 -0800 (PST) Received: from ufe34d9ed68d054.ant.amazon.com (54-240-197-235.amazon.com. [54.240.197.235]) by smtp.gmail.com with ESMTPSA id a1sm19787707wrr.80.2020.01.27.01.38.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 01:38:15 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 27 Jan 2020 09:38:08 +0000 Message-Id: <20200127093808.31373-1-julien@xen.org> X-Mailer: git-send-email 2.17.1 Subject: [Xen-devel] [PATCH] xen/x86: domain: Remove specific case when allocating struct domain X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Andrew Cooper , Julien Grall , David Woodhouse , =?utf-8?q?Roger_Pau_Monn=C3=A9?= MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Julien Grall Commit 8916fcf4577 "x86/domain: compile with lock_profile=y enabled" allowed the struct domain to use more than a PAGE_SIZE (i.e 4096). However, the function free_domheap_struct() will only free the first page. We could modify the free part to free the correct number of pages, but the structure has been fitting in a page (even with lock profile enabled) since commit 428607a410 "x86: shrink 'struct domain', was already PAGE_SIZE" (part of Xen 4.7). Therefore, the specific case for lock profile is now removed. This is not a security issue because struct domain can only be bigger than a page size for lock profiling. The feature can only be selected in DEBUG and EXPERT mode. Fixes: 8916fcf4577 ("x86/domain: compile with lock_profile=y enabled") Reported-by: David Woodhouse Signed-off-by: Julien Grall Reviewed-by: Andrew Cooper --- This replace the original approach: https://lists.xenproject.org/archives/html/xen-devel/2020-01/msg01546.html --- xen/arch/x86/domain.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 28fefa1f81..f53ae5ff86 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -313,7 +313,6 @@ static unsigned int __init noinline _domain_struct_bits(void) struct domain *alloc_domain_struct(void) { struct domain *d; - unsigned int order = get_order_from_bytes(sizeof(*d)); #ifdef CONFIG_BIGMEM const unsigned int bits = 0; #else @@ -327,18 +326,10 @@ struct domain *alloc_domain_struct(void) bits = _domain_struct_bits(); #endif - -#ifndef CONFIG_DEBUG_LOCK_PROFILE BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE); -#endif - d = alloc_xenheap_pages(order, MEMF_bits(bits)); + d = alloc_xenheap_pages(0, MEMF_bits(bits)); if ( d != NULL ) - { - unsigned int sz; - - for ( sz = 0; sz < (PAGE_SIZE << order); sz += PAGE_SIZE ) - clear_page((void *)d + sz); - } + clear_page(d); return d; }