From nobody Thu Sep 19 01:16:12 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=1721232880; cv=none; d=zohomail.com; s=zohoarc; b=kls+dvaOMpQiohf9lqCrR+RVhLpBFXLVIu925Jr+d5AgEctbt6hrDJ+si+hKH/HvDW8NR6MQ/YqseJWYRyDdNM7Qrh6SB7fRY9rexSKBqEhu3h5eUxj4YnIl0m5Fg4BP3sZ6CrvwGKxBfWl5/gNrDJXbAuEfWcZcvbwsRX6lJRk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721232880; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZvzhdU6x9AsIJRrQYGcjNo5sQW70nyGBUDqt4jxaSlQ=; b=eo3/PDe07zBb15wF/wkOVM/XE5Ct2ePIThxnRqh8B4v6Iey+I8Ss08f3JpSYaJbCg3kArsvXhFrS/vWMzISfO+YUkLwO1adIe/q3jj2S+7W+yr5sQdDbgUH+/+pIDgY1tEIfCm4Y3+TmNlfcENlq2oN6F1JiNVCWqoanz5waxqI= 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 1721232880499880.8207842401424; Wed, 17 Jul 2024 09:14:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.760077.1169814 (Exim 4.92) (envelope-from ) id 1sU7IR-00089v-3a; Wed, 17 Jul 2024 16:14:27 +0000 Received: by outflank-mailman (output) from mailman id 760077.1169814; Wed, 17 Jul 2024 16:14:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sU7IR-00089a-0G; Wed, 17 Jul 2024 16:14:27 +0000 Received: by outflank-mailman (input) for mailman id 760077; Wed, 17 Jul 2024 16:14:26 +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 1sU7IQ-0007cd-0E for xen-devel@lists.xenproject.org; Wed, 17 Jul 2024 16:14:26 +0000 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [2a00:1450:4864:20::232]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a1e8a456-4457-11ef-8776-851b0ebba9a2; Wed, 17 Jul 2024 18:14:24 +0200 (CEST) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2eeb1ba0468so84852331fa.0 for ; Wed, 17 Jul 2024 09:14:24 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-59ff76e9851sm2064067a12.46.2024.07.17.09.14.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 09:14:21 -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: a1e8a456-4457-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1721232863; x=1721837663; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZvzhdU6x9AsIJRrQYGcjNo5sQW70nyGBUDqt4jxaSlQ=; b=S5kF/WWsNgVRZ1C2hE24FkRVgJvieZCAXesAFhfQlVzzoxDq2YNYSVhNd2LC1N8dGu bxNgu4zDltBkA3xJUhFj+If8bT0AhHKI8qNxYL8zzb74NId1xxhHnVXcloEQ1ywdESkV qfcBSTom9qhP7vdxlX3rWHiRJsk60fQZigH6U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721232863; x=1721837663; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZvzhdU6x9AsIJRrQYGcjNo5sQW70nyGBUDqt4jxaSlQ=; b=eljI4YbjDh8oJ0te7drSCSX6IUeYeM5j4xN47RCENfn52l7W13jhHSg0XSX3V7DkTp 3pympO2WaVZO2TYLKnFrKgkupaT/3Z3dXzEOMlZqFMmzp1fTRJIIrTQcIl1zz31nOWWF cAuVEFNeW48B7zrnPf1J3p3jt/00rSKGcs7ArA37evjPUwTTj3nr6mgoG/j8b++yMGg7 4aoRucL75l/zubh7wogxyjJmTIPwyRKZlQjS1ahTe9YbQnIrQ4sj75d6XfEgRET2FryI M6MUvp7w3rrxF9DRrY17SxD3H8P8IjkPFdj77jJNgv51Fc71QyDkr4p2sZrKAPdEVbQV lXZg== X-Gm-Message-State: AOJu0Yyom7rqP1xnmaSNrPrdOEwG/dEdjG6tOoLO5kuUx0aZQE43GTCp ip/87bPZUEKkvcKDgAFP54ntaCfOa5jReBTe3bdNvl7DjMkH9klYTGbhdqZ/rIUnW3cAVddnt6o d X-Google-Smtp-Source: AGHT+IGXLIIUiAI+gC9eBhq5fKEVyrJPtP68hJKmzAAuUzWzrV7GD8Gn/EXQtq6KFUp88QiJlBPmEw== X-Received: by 2002:a2e:be90:0:b0:2ec:3dd4:75f4 with SMTP id 38308e7fff4ca-2eefd141eb7mr21114391fa.38.1721232863174; Wed, 17 Jul 2024 09:14:23 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH RFC 3/3] x86/mm: Simplify/correct l1_disallow_mask() Date: Wed, 17 Jul 2024 17:14:15 +0100 Message-Id: <20240717161415.3586195-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240717161415.3586195-1-andrew.cooper3@citrix.com> References: <20240717161415.3586195-1-andrew.cooper3@citrix.com> 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: 1721232882048116600 l1_disallow_mask() yields L1_DISALLOW_MASK with PAGE_CACHE_ATTRS conditiona= lly permitted. First, rewrite it as a plain function. Next, correct some dubious behaviours. The use of is_pv_domain() is tautological; l1_disallow_mask() is only used = in the PV pagetable code, and it return true for system domains as well. The use of has_arch_pdevs() is wonky; by making the use of cache attributes dependent on the instantanious property of whether any devices is assigned, means that a guest could have created a legal PTE which will fail validation at a later point when the device has been removed. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 RFC. I've not tested this, and I doubt it will work to start with owing to the removal of the dom_io special case which IIRC dom0 uses to map arbitrary MMIO. Furthermore, the rangeset_is_empty() calls have the same problem that has_arch_pdevs() has; they're not invariants on the domain. Also, VMs wanting/needing encrypted memory need fully working cacheability irrespecti= ve of device assignment. I expect the way we actually want to fix this is to have a CDF flag for allowing reduced cahcebility, and for this expression to simplify to just: if ( d->options & XEN_DOMCTL_CDF_any_cacheability ) disallow &=3D ~PAGE_CACHE_ATTRS; which is simpler still. For the current form, bloat-o-meter reports: add/remove: 1/0 grow/shrink: 1/2 up/down: 75/-280 (-205) Function old new delta l1_disallow_mask - 74 +74 mod_l1_entry.cold 55 56 +1 get_page_from_l1e 1271 1167 -104 mod_l1_entry 1860 1684 -176 which is an even bigger improvement than simply not duplicating the logic. --- xen/arch/x86/mm.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 95795567f2a5..31937319c057 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -162,13 +162,17 @@ static uint32_t __ro_after_init base_disallow_mask; =20 #define L4_DISALLOW_MASK (base_disallow_mask) =20 -#define l1_disallow_mask(d) \ - (((d) !=3D dom_io) && \ - (rangeset_is_empty((d)->iomem_caps) && \ - rangeset_is_empty((d)->arch.ioport_caps) && \ - !has_arch_pdevs(d) && \ - is_pv_domain(d)) ? \ - L1_DISALLOW_MASK : (L1_DISALLOW_MASK & ~PAGE_CACHE_ATTRS)) +static uint32_t l1_disallow_mask(const struct domain *d) +{ + uint32_t disallow =3D L1_DISALLOW_MASK; + + if ( (d->options & XEN_DOMCTL_CDF_iommu) || + !rangeset_is_empty(d->iomem_caps) || + !rangeset_is_empty(d->arch.ioport_caps) ) + disallow &=3D ~PAGE_CACHE_ATTRS; + + return disallow; +} =20 static s8 __read_mostly opt_mmio_relax; =20 --=20 2.39.2