From nobody Sat Nov 23 12:43:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1724844681; cv=none; d=zohomail.com; s=zohoarc; b=nY82x8u4TCi7BOmh8lvzjBDOekDOef9t19qzJY+s3nfXDzxqNMoAlMvuaYYAxxpBM6qXIGu+hqTdpmJACPBeRAXyz4vlOZ3Stz0xjQ4aZHkiYJwSYucteqD/2h2ZA8CnbOLsbgAYWNIn2CNSWE/AxHtpVIa6xjMWAMbre34Kobo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724844681; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NP40Ho4Pmq7WnToYus2s15UIRJ92xUV+gpDp04qChq4=; b=ESUaRHyyyRbpiRA93eHVNp/W/HtVBmUld9Iu98PEfzOjmNNmsSZhUMM143lnW6FdVAhVt975zUsi4DBMuVQzOSRzfya7+NRZh3OUYBa0SKywrnMko+IkgdX8Cr12fXgCEpbV0edYbX9cOgaQuoYWllyseEClYogG7dCnb6aAXCI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1724844681390147.31182122721987; Wed, 28 Aug 2024 04:31:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.784740.1194118 (Exim 4.92) (envelope-from ) id 1sjGt9-00061n-9l; Wed, 28 Aug 2024 11:30:59 +0000 Received: by outflank-mailman (output) from mailman id 784740.1194118; Wed, 28 Aug 2024 11:30:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sjGt9-00061g-6z; Wed, 28 Aug 2024 11:30:59 +0000 Received: by outflank-mailman (input) for mailman id 784740; Wed, 28 Aug 2024 11:30:57 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sjGt7-00061a-H4 for xen-devel@lists.xenproject.org; Wed, 28 Aug 2024 11:30:57 +0000 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [2607:f8b0:4864:20::729]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fcdd01b9-6530-11ef-99a0-01e77a169b0f; Wed, 28 Aug 2024 13:30:55 +0200 (CEST) Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-7a4df9dc840so387979885a.2 for ; Wed, 28 Aug 2024 04:30:55 -0700 (PDT) Received: from localhost ([213.195.124.163]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a67f35ba3bsm626925885a.59.2024.08.28.04.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 04:30:52 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: fcdd01b9-6530-11ef-99a0-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1724844654; x=1725449454; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=NP40Ho4Pmq7WnToYus2s15UIRJ92xUV+gpDp04qChq4=; b=AOTNdHnuYGlhcnYzgNN/uvdBzwVoS5TZtMbjVwf3MQPNimdMDhOQeiDMHFUafUN4m2 WbjMIKlONArqqm12SF5Auk1Wh8V822ti3UpaaLZ+tVgJl0ReK/8xfmqOCwacYCfrWQls mcb/ueSCF7bfIqj/9GzDBlVP4HkGxUX6ft48o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724844654; x=1725449454; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NP40Ho4Pmq7WnToYus2s15UIRJ92xUV+gpDp04qChq4=; b=Wu5+FVSNjtQqmmWyj6htrY4j9NTO4wXaZlvrBPFnf1nr/319aUjlHQ5lTXXcHxGpTy EPnKVG95TnIN8W5eL/T1ecViJ71q/qZvli0Oj17AHrKMRfG4oA2CJnZJDWBqAoyh9y69 smE8z+P7+1ZIvrcUdHrAoaB21ZlI+RGWL8ZM34HiNR4LWWCj7pRSYzR+hvTXxNNRWhWt ln0sEGLYqQjcdiymHlwTYw5KilMMqwQivKpjqr759QmEiwJ9kldUqCflYDZOF1SVPoU5 gcbZ99GuMeIoFEzP4948SBt3jDjEbgmTQKRdCzJZpyNgmVzzVDWe+1oJ1o34Gm9nHb2l drUw== X-Gm-Message-State: AOJu0YxswveN6IKCyXyh5XbNHuL96nyDPpGdXnAvW7cEr4va6/aywQ5K 7JA/DQI+QInjrDFfZvzO+JUH1c/gOS+vXo/lkBnDfWVNZrqdFFEjrmqMhBmwFP6vRVzzM9q57+z + X-Google-Smtp-Source: AGHT+IFKxLbDap4Z7rOnqJ3joVSoQbGTU5gfXH+djtGXTusKrCJtihPvJA714ffvGw6RZz0BhQwtbQ== X-Received: by 2002:a05:620a:458c:b0:79f:197d:fe92 with SMTP id af79cd13be357-7a6896e4417mr1465527285a.2.1724844653525; Wed, 28 Aug 2024 04:30:53 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v6] x86/dom0: disable SMAP for PV domain building only Date: Wed, 28 Aug 2024 13:30:44 +0200 Message-ID: <20240828113044.35541-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1724844683127116600 Move the logic that disables SMAP so it's only performed when building a PV dom0, PVH dom0 builder doesn't require disabling SMAP. The fixes tag is to account for the wrong usage of cpu_has_smap in create_dom0(), it should instead have used boot_cpu_has(X86_FEATURE_XEN_SMAP). Fix while moving the logic to apply to= PV only. While there also make cr4_pv32_mask __ro_after_init. Fixes: 493ab190e5b1 ('xen/sm{e, a}p: allow disabling sm{e, a}p for Xen itse= lf') Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Andrew Cooper Reviewed-by: Jan Beulich --- Changes since v5: - Drop comment and asmlinkage attribute. - Introduce a wrapper for dom0_construct_pv() so the usage of cr4_pv32_mask can be limited to a PV-specific file. Changes since v4: - New approach, move the current logic so it's only applied when creating = a PV dom0. --- xen/arch/x86/include/asm/setup.h | 2 ++ xen/arch/x86/pv/dom0_build.c | 38 +++++++++++++++++++++++++++----- xen/arch/x86/setup.c | 20 +---------------- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/se= tup.h index d75589178b91..8f7dfefb4dcf 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -64,6 +64,8 @@ extern bool opt_dom0_verbose; extern bool opt_dom0_cpuid_faulting; extern bool opt_dom0_msr_relaxed; =20 +extern unsigned long cr4_pv32_mask; + #define max_init_domid (0) =20 #endif diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 57e58a02e707..22988f2660b0 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -354,11 +354,11 @@ static struct page_info * __init alloc_chunk(struct d= omain *d, return page; } =20 -int __init dom0_construct_pv(struct domain *d, - const module_t *image, - unsigned long image_headroom, - module_t *initrd, - const char *cmdline) +static int __init dom0_construct(struct domain *d, + const module_t *image, + unsigned long image_headroom, + module_t *initrd, + const char *cmdline) { int i, rc, order, machine; bool compatible, compat; @@ -1051,6 +1051,34 @@ out: return rc; } =20 +int __init dom0_construct_pv(struct domain *d, + const module_t *image, + unsigned long image_headroom, + module_t *initrd, + const char *cmdline) +{ + int rc; + + /* + * Temporarily clear SMAP in CR4 to allow user-accesses in + * construct_dom0(). This saves a large number of corner cases + * interactions with copy_from_user(). + */ + if ( boot_cpu_has(X86_FEATURE_XEN_SMAP) ) + { + cr4_pv32_mask &=3D ~X86_CR4_SMAP; + write_cr4(read_cr4() & ~X86_CR4_SMAP); + } + rc =3D dom0_construct(d, image, image_headroom, initrd, cmdline); + if ( boot_cpu_has(X86_FEATURE_XEN_SMAP) ) + { + write_cr4(read_cr4() | X86_CR4_SMAP); + cr4_pv32_mask |=3D X86_CR4_SMAP; + } + + return rc; +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index eee20bb1753c..f1076c72032d 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -79,8 +79,7 @@ bool __read_mostly use_invpcid; int8_t __initdata opt_probe_port_aliases =3D -1; boolean_param("probe-port-aliases", opt_probe_port_aliases); =20 -/* Only used in asm code and within this source file */ -unsigned long asmlinkage __read_mostly cr4_pv32_mask; +unsigned long __ro_after_init cr4_pv32_mask; =20 /* **** Linux config option: propagated to domain0. */ /* "acpi=3Doff": Sisables both ACPI table parsing and interpreter. */ @@ -955,26 +954,9 @@ static struct domain *__init create_dom0(const module_= t *image, } } =20 - /* - * Temporarily clear SMAP in CR4 to allow user-accesses in construct_d= om0(). - * This saves a large number of corner cases interactions with - * copy_from_user(). - */ - if ( cpu_has_smap ) - { - cr4_pv32_mask &=3D ~X86_CR4_SMAP; - write_cr4(read_cr4() & ~X86_CR4_SMAP); - } - if ( construct_dom0(d, image, headroom, initrd, cmdline) !=3D 0 ) panic("Could not construct domain 0\n"); =20 - if ( cpu_has_smap ) - { - write_cr4(read_cr4() | X86_CR4_SMAP); - cr4_pv32_mask |=3D X86_CR4_SMAP; - } - return d; } =20 --=20 2.46.0