From patchwork Wed Jul 17 16:14:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13735606 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 1F8BEC3DA62 for ; Wed, 17 Jul 2024 16:14:35 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.760075.1169793 (Exim 4.92) (envelope-from ) id 1sU7IP-0007gW-L1; Wed, 17 Jul 2024 16:14:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 760075.1169793; Wed, 17 Jul 2024 16:14:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sU7IP-0007gP-IA; Wed, 17 Jul 2024 16:14:25 +0000 Received: by outflank-mailman (input) for mailman id 760075; Wed, 17 Jul 2024 16:14:24 +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 1sU7IO-0007cd-BF for xen-devel@lists.xenproject.org; Wed, 17 Jul 2024 16:14:24 +0000 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [2a00:1450:4864:20::532]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a0c20ec2-4457-11ef-8776-851b0ebba9a2; Wed, 17 Jul 2024 18:14:22 +0200 (CEST) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5a156557029so72866a12.2 for ; Wed, 17 Jul 2024 09:14:22 -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.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 09:14:19 -0700 (PDT) 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: a0c20ec2-4457-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1721232861; x=1721837661; 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=5Hs4wrdJtk3VapaPKuUdheZRErHwrsf5hCAxRfp1mf8=; b=Lq7Rm/vx7l3PADnhtuZ4Ii4edFz0JO5DoDLVNiY30x1Dcgg9hfIuoHV+NnOjTlkCFI Kc4fYYul2JjqVCloBh/W9jSJQ3XuPsT0FFHl6B1BOnaWJLR85fL8v30OLbT39Yc66jSH Q76pBOe/yOGwjoOFLAsHltJXN9otALGhFUohA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721232861; x=1721837661; 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=5Hs4wrdJtk3VapaPKuUdheZRErHwrsf5hCAxRfp1mf8=; b=UtNZayiL7Lv1J2SFBjxKtnldR1i9i4jYnb9IjvVRnWN6ZEwWPUVPkfJPbamtk0MK/O orrDcQdOlcz321M/gUhfVrJQdpO3vog9+roog6499OoAouRaMcMuSm/Z/r7RR9arjk5q UK3USfCbVJC7mwsUBBc6BiNZD8miIl5V64NMve59kio7o9R2dNFjT4YX3hFuXMYJo0pU LdaK58RS17PLqAWPhp8il11P+f40DsblnkiWcNo8PlGOMJ8B0OBnZSZd98uY/wNYNghj 4ZsrEej21Zzk4C94hGiEaVGrtFXx0FLvcSBKxg/TDjZb9ocjPN3l4TRHea5lUaKHtM5Q dJbQ== X-Gm-Message-State: AOJu0YxODtR/2qvjqHPcoovk2UECgfQfhlmMAlmcdY78WpBQ4/sjyFpv 43BDSHhMQ09mo5kH/5jiYsvZ2m9PyPq5Fku6jxLubD6V4l53TatXqx5Jq6AMzToRkWkU6Kkqu+P s X-Google-Smtp-Source: AGHT+IE2A+aNCiABEOLDj6cm/ACujRFbXC9ad5IBBn1C1Q8iC5+GOl71h4QF9IdCDJYgfyBjlsI8TQ== X-Received: by 2002:a05:6402:2547:b0:58e:3501:5c25 with SMTP id 4fb4d7f45d1cf-5a05b9db216mr1759950a12.13.1721232861013; Wed, 17 Jul 2024 09:14:21 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH 1/3] x86/mm: Drop duplicate l1_disallow_mask() calls Date: Wed, 17 Jul 2024 17:14:13 +0100 Message-Id: <20240717161415.3586195-2-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 Even in release builds, gdprintk() evalues its parameters for side effects, and l1_disallow_mask() is full of them. Calculate the disallow mask once and reuse the variable. This improves code generation in release builds: add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-207 (-207) Function old new delta mod_l1_entry 1947 1860 -87 get_page_from_l1e 1391 1271 -120 Also, render the bad flags message with a 0x prefix. No practical change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monné --- xen/arch/x86/mm.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 648d6dd475ba..0ecea0f707b2 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -842,7 +842,7 @@ get_page_from_l1e( { unsigned long mfn = l1e_get_pfn(l1e); struct page_info *page = mfn_to_page(_mfn(mfn)); - uint32_t l1f = l1e_get_flags(l1e); + uint32_t l1f = l1e_get_flags(l1e), disallow; struct vcpu *curr = current; struct domain *real_pg_owner; bool write, valid; @@ -853,10 +853,10 @@ get_page_from_l1e( return 0; } - if ( unlikely(l1f & l1_disallow_mask(l1e_owner)) ) + disallow = l1_disallow_mask(l1e_owner); + if ( unlikely(l1f & disallow) ) { - gdprintk(XENLOG_WARNING, "Bad L1 flags %x\n", - l1f & l1_disallow_mask(l1e_owner)); + gdprintk(XENLOG_WARNING, "Bad L1 flags %#x\n", l1f & disallow); return -EINVAL; } @@ -2155,11 +2155,12 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e, if ( l1e_get_flags(nl1e) & _PAGE_PRESENT ) { struct page_info *page = NULL; + uint32_t disallow = l1_disallow_mask(pt_dom); - if ( unlikely(l1e_get_flags(nl1e) & l1_disallow_mask(pt_dom)) ) + if ( unlikely(l1e_get_flags(nl1e) & disallow) ) { - gdprintk(XENLOG_WARNING, "Bad L1 flags %x\n", - l1e_get_flags(nl1e) & l1_disallow_mask(pt_dom)); + gdprintk(XENLOG_WARNING, "Bad L1 flags %#x\n", + l1e_get_flags(nl1e) & disallow); return -EINVAL; } From patchwork Wed Jul 17 16:14:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13735607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 0C279C3DA60 for ; Wed, 17 Jul 2024 16:14:35 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.760076.1169800 (Exim 4.92) (envelope-from ) id 1sU7IP-0007js-Uf; Wed, 17 Jul 2024 16:14:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 760076.1169800; Wed, 17 Jul 2024 16:14:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sU7IP-0007jb-Pb; Wed, 17 Jul 2024 16:14:25 +0000 Received: by outflank-mailman (input) for mailman id 760076; Wed, 17 Jul 2024 16:14:25 +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 1sU7IP-0007cd-0C for xen-devel@lists.xenproject.org; Wed, 17 Jul 2024 16:14:25 +0000 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [2a00:1450:4864:20::536]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a1116879-4457-11ef-8776-851b0ebba9a2; Wed, 17 Jul 2024 18:14:22 +0200 (CEST) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-59f9f59b88cso2467408a12.3 for ; Wed, 17 Jul 2024 09:14:22 -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-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: a1116879-4457-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1721232862; x=1721837662; 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=J4qyb2Q8pmTavMu8lP6BG6l66WhcSIyplW6y2Sr0GR4=; b=ic+RTZsqos+QiI6gFCh77lXOKO4U/BHanCnMGFShOpITYfZIx15E1MgN/pkHosgkbQ NOHt78rlCa+hVG0tNz9DPIFAIs7fok32wESN0XJhHiYFSvskIrHgnXcLln8WDzqNQxNN r+rGe2DwGnxL17f7eJCY1kESKgqn98mJDnYoU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721232862; x=1721837662; 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=J4qyb2Q8pmTavMu8lP6BG6l66WhcSIyplW6y2Sr0GR4=; b=SB6L02hIbddP1Yec2gxhQA0de6MBV5LCOvY9ih4kR5ekqx9zUtXRE3X8UDQWaUsdFS eTetuGPFU6eVY8VUNdwR/kuZSgArON1qkkut2kMNIV3zD+nWrSDTL1ZdZPYolfSrNxCX Skcw3WPFHPcOTfvj/hbinUO4x72l+1a6SqWs1Vb9OPu+IKZadUeB8CuDVMwo1qfpxMFV H+jpKScvEjy/sugMClUQ4dc1Bg327uv30Mey5O/q6Et2iRRGmuc3ZYilEjBrbF5iDvEY jxDTE97hRYM3IF7IW/RImTAlhVNbdA44Q4nnE7RlgUIE7gUP9NMJDgAgJTKeHeWMqZHN WoOQ== X-Gm-Message-State: AOJu0YxiHmsAJUrt6Eb+HmNOO+rxF3mjz4iLvFgFmzBdq7uH5w8M9+bk 6DC9Csv9p0qZZJY12T3N9BQLaNgmqUhyl4nbruXH91H+gcVkEEiakojti5mb75B7bZPRYV+WuuP S X-Google-Smtp-Source: AGHT+IGIvS2ShxY2WkKbLfsrMI5Fza3y7YZ3JTKjaqhBi9LN2oyOYTXmNB6tdsxWF3bwKIAe23gX0w== X-Received: by 2002:a50:d5de:0:b0:585:4048:129a with SMTP id 4fb4d7f45d1cf-5a05ce11c37mr1509174a12.31.1721232861656; Wed, 17 Jul 2024 09:14:21 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH 2/3] x86/mm: Move base_disallow_mask into __ro_after_init Date: Wed, 17 Jul 2024 17:14:14 +0100 Message-Id: <20240717161415.3586195-3-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 base_disallow_mask is calculated once in arch_init_memory() and never changes thereafter. Write-protect it at runtime. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monné --- xen/arch/x86/mm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 0ecea0f707b2..95795567f2a5 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -150,7 +150,8 @@ bool __read_mostly machine_to_phys_mapping_valid; struct rangeset *__read_mostly mmio_ro_ranges; -static uint32_t base_disallow_mask; +static uint32_t __ro_after_init base_disallow_mask; + /* Global bit is allowed to be set on L1 PTEs. Intended for user mappings. */ #define L1_DISALLOW_MASK ((base_disallow_mask | _PAGE_GNTTAB) & ~_PAGE_GLOBAL) From patchwork Wed Jul 17 16:14:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13735604 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D7C7DC3DA42 for ; Wed, 17 Jul 2024 16:14:33 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 l1_disallow_mask() yields L1_DISALLOW_MASK with PAGE_CACHE_ATTRS conditionally 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é 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 irrespective 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 &= ~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; #define L4_DISALLOW_MASK (base_disallow_mask) -#define l1_disallow_mask(d) \ - (((d) != 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 = L1_DISALLOW_MASK; + + if ( (d->options & XEN_DOMCTL_CDF_iommu) || + !rangeset_is_empty(d->iomem_caps) || + !rangeset_is_empty(d->arch.ioport_caps) ) + disallow &= ~PAGE_CACHE_ATTRS; + + return disallow; +} static s8 __read_mostly opt_mmio_relax;