From nobody Tue May 7 18:01:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1580821646987757.3781374229458; Tue, 4 Feb 2020 05:07:26 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iyxua-0003th-Gg; Tue, 04 Feb 2020 13:06:40 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iyxuZ-0003tY-A8 for xen-devel@lists.xenproject.org; Tue, 04 Feb 2020 13:06:39 +0000 Received: from mail-wm1-f67.google.com (unknown [209.85.128.67]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2a641d05-474f-11ea-8f39-12813bfff9fa; Tue, 04 Feb 2020 13:06:34 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id m10so2181408wmc.0 for ; Tue, 04 Feb 2020 05:06:34 -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 y8sm3624776wma.10.2020.02.04.05.06.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 05:06:32 -0800 (PST) X-Inumbo-ID: 2a641d05-474f-11ea-8f39-12813bfff9fa 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=3oIjWzkiKCd8SRh3Zl916SAIra1g+izJglbfmsonOfw=; b=aUGtS6R9TQJfcdkojk/ovSzEks86jbdJ2lSREeZDxPNf2LAIJ41JnuKORby6Pfx/+l 6PyHCZCR358bqZCem89uuwW9gTeiHHjB/LGLEzXa6pQd7CQ1860DDyU/GOq2A+HjGPE3 SAxB9nxJJT/zaczpOmUUxej91X6cgAoOsKG4WiAmZR3yyOrHAaOvnjQ38UsV0+ijMqAP 0w/sZLKDGandP70t37RE0IWHoXLYF0EDCUPbzDCupVB0YjdFyRmwjaXAD5jRrsk9U9BN hoRTxeoV3WOo6BomIyD7RNTjEbmjfM4jyRI4FdF4Bn+aSk8uPsmNPiN2C3taVhgMy5Qg iZ0g== X-Gm-Message-State: APjAAAXDayzs16w1sZr0Q8Cebzdu3jzSiFIYJE0mBMmiFgHR0LEYrnGY k8BY4U8+IX4VOxWMfGOEcdNP+EDN9VQ= X-Google-Smtp-Source: APXvYqykJXdaCTIcvwETQqMrrbaV/SaGBg53j+IJ33UooSyJaYMLz5vfJAEou3o1xjhWF8FTKtV4eg== X-Received: by 2002:a1c:451:: with SMTP id 78mr5528281wme.125.1580821593165; Tue, 04 Feb 2020 05:06:33 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 4 Feb 2020 13:06:13 +0000 Message-Id: <20200204130614.15166-2-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204130614.15166-1-julien@xen.org> References: <20200204130614.15166-1-julien@xen.org> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 1/2] xen/x86: hap: Fix coding style in hap_enable() 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: julien@xen.org, Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Signed-off-by: Julien Grall Reviewed-by: Roger Pau Monn=C3=A9 Acked-by: George Dunlap --- Changes in v2: - Add Roger's reviewed-by --- xen/arch/x86/mm/hap/hap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c index 3d93f3451c..31362a31b6 100644 --- a/xen/arch/x86/mm/hap/hap.c +++ b/xen/arch/x86/mm/hap/hap.c @@ -473,7 +473,8 @@ int hap_enable(struct domain *d, u32 mode) goto out; } =20 - for (i =3D 0; i < MAX_NESTEDP2M; i++) { + for ( i =3D 0; i < MAX_NESTEDP2M; i++ ) + { rv =3D p2m_alloc_table(d->arch.nested_p2m[i]); if ( rv !=3D 0 ) goto out; --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue May 7 18:01:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1580821637121390.008703945972; Tue, 4 Feb 2020 05:07:17 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iyxuX-0003t6-0d; Tue, 04 Feb 2020 13:06:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iyxuW-0003sz-0g for xen-devel@lists.xenproject.org; Tue, 04 Feb 2020 13:06:36 +0000 Received: from mail-wm1-f65.google.com (unknown [209.85.128.65]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 2b96e990-474f-11ea-b211-bc764e2007e4; Tue, 04 Feb 2020 13:06:35 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id g1so3216603wmh.4 for ; Tue, 04 Feb 2020 05:06:35 -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 y8sm3624776wma.10.2020.02.04.05.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 05:06:33 -0800 (PST) X-Inumbo-ID: 2b96e990-474f-11ea-b211-bc764e2007e4 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:in-reply-to :references; bh=I/RYh/2DoPGwgWAaRh2LgcALyP0y0hX0y1FawturjEk=; b=LmgU0M8y7aush3VkWh8rrLAnfj7py/v3rPXglq3sr5TXyxKzlasVgVrA+OUxGN1tT6 HrnceGlUTBeZqZFvBal2FLHXvi33L/AvEtpTaSPh/Cq/WFNy25jwmhwIOl4hXuk1Ztrg 9fiw0kUJyoa9nJLTOsfSSb617cII+hq3NvfsBgTMVkU/P8SD3UKVVvUl5hQde9AqoZ3p A/TR+VPElOZneic7GYZUyEEaNM20YsRjhMpn+Zuo9+4qiuhE9p+vOQEyft7/gJ2DKTc1 ERhYTXMGiOrsg4T4l9Iedd6BHIYJCmyiGuT3z6lrLyuYYNvbRgeXIrsmsZuXAhsSF/G0 6wCg== X-Gm-Message-State: APjAAAXx+oF/P3U7AgC6nUQhjWGdKEQIbO2B+jyCksqRpiBgVKSKqFTf lFgLEGCRfN6XKgi5IVFK9TzCNme3FWQ= X-Google-Smtp-Source: APXvYqwdoxq3HVlJF/Eb+M4IzovaztivEiw82upR0UAE0tPFvW/hp19NimxZk3m9tpdT/5j7sjgh1g== X-Received: by 2002:a7b:c152:: with SMTP id z18mr5674308wmi.70.1580821594192; Tue, 04 Feb 2020 05:06:34 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 4 Feb 2020 13:06:14 +0000 Message-Id: <20200204130614.15166-3-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204130614.15166-1-julien@xen.org> References: <20200204130614.15166-1-julien@xen.org> Subject: [Xen-devel] [PATCH v2 2/2] xen/x86: hap: Clean-up and harden hap_enable() 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: julien@xen.org, Wei Liu , George Dunlap , Andrew Cooper , Julien Grall , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Julien Grall Unlike shadow_enable(), hap_enable() can only be called once during domain creation and with the mode equal to mode equal to PG_external | PG_translate | PG_refcounts. If it were called twice, then we might have something interesting problem as the p2m tables would be re-allocated (and therefore all the mappings would be lost). Add code to sanity check the mode and that the function is only called once. Take the opportunity to an if checking that PG_translate is set. Signed-off-by: Julien Grall Acked-by: Jan Beulich --- It is not entirely clear when PG_translate was enforced. I keep the check !=3D 0 because this is consistent with the rest of the file. If we want to omit comparison against 0, then this should be in a separate patches converting the file. Changes in v2: - Fix typoes in the commit message - Use -EEXIST instead of -EINVAL --- xen/arch/x86/mm/hap/hap.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c index 31362a31b6..4974bd13d4 100644 --- a/xen/arch/x86/mm/hap/hap.c +++ b/xen/arch/x86/mm/hap/hap.c @@ -445,6 +445,13 @@ int hap_enable(struct domain *d, u32 mode) unsigned int i; int rv =3D 0; =20 + if ( mode !=3D (PG_external | PG_translate | PG_refcounts) ) + return -EINVAL; + + /* The function can only be called once */ + if ( d->arch.paging.mode !=3D 0 ) + return -EEXIST; + domain_pause(d); =20 old_pages =3D d->arch.paging.hap.total_pages; @@ -465,13 +472,10 @@ int hap_enable(struct domain *d, u32 mode) d->arch.paging.alloc_page =3D hap_alloc_p2m_page; d->arch.paging.free_page =3D hap_free_p2m_page; =20 - /* allocate P2m table */ - if ( mode & PG_translate ) - { - rv =3D p2m_alloc_table(p2m_get_hostp2m(d)); - if ( rv !=3D 0 ) - goto out; - } + /* allocate P2M table */ + rv =3D p2m_alloc_table(p2m_get_hostp2m(d)); + if ( rv !=3D 0 ) + goto out; =20 for ( i =3D 0; i < MAX_NESTEDP2M; i++ ) { --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel