From nobody Thu May 16 08:05:20 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=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1691499791; cv=none; d=zohomail.com; s=zohoarc; b=OeGZdVaRlca6u4xQCwHkKvfv2/4LcL5LXo1Oa1RR+fEXtoZpZ4PaYFuRJzFD3txAa15j1OJwvDIJ7VH4yhqE428DcnxNechXJot4/YIPnM1qkv29d0Pjex1qJxWc/l2rugTIhJcaEKktWXGwkZoOCzOqaGtzIApoEWNVwaYReOE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691499791; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=I6QBQAGjY2r360IlHRoBLqtdiryrX7RiFTTDs7pUf/s=; b=EMRm70tEr3ZMn1fs9jer7co8Kpvb3jbp0ZwcqNTAxNOR43xC6wvVG3KKbMwGVMpppPFOB/l1dWusvTwJa/v1KN23H46DybphopNAkvNigOIWI3HvFSmrYGip6y31I1AxowBR/KrNbkGCFPq1WvTsgF2yTVRKwW8zewGJxb01TRI= 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 1691499791571449.0365261605142; Tue, 8 Aug 2023 06:03:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.579782.907901 (Exim 4.92) (envelope-from ) id 1qTMMC-0003NJ-UN; Tue, 08 Aug 2023 13:02:40 +0000 Received: by outflank-mailman (output) from mailman id 579782.907901; Tue, 08 Aug 2023 13:02:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qTMMC-0003Mw-P0; Tue, 08 Aug 2023 13:02:40 +0000 Received: by outflank-mailman (input) for mailman id 579782; Tue, 08 Aug 2023 13:02:39 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qTMMB-0003KL-QL for xen-devel@lists.xenproject.org; Tue, 08 Aug 2023 13:02:39 +0000 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [2a00:1450:4864:20::334]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d9aac536-35eb-11ee-b280-6b7b168915f2; Tue, 08 Aug 2023 15:02:38 +0200 (CEST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fe2fb9b4d7so47794765e9.1 for ; Tue, 08 Aug 2023 06:02:38 -0700 (PDT) Received: from localhost.localdomain (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id y15-20020a5d4acf000000b003144b50034esm13567072wrs.110.2023.08.08.06.02.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 06:02:36 -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: d9aac536-35eb-11ee-b280-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1691499757; x=1692104557; 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=I6QBQAGjY2r360IlHRoBLqtdiryrX7RiFTTDs7pUf/s=; b=lc7bZs3dOMd6Nfz9ANn2pPGoZX0osgPGShUy6l6kN2Yq6Z/ZJoMOqVnmGyLsy4hCDL B6MG6+iJjZKS9NaWVbpqrgb28AwKQWOzmdYsoFhSiStk+8R0UMs9djSaBGjN14+qhMkn GX+CpclGLCSR4GndhJCA93ewSmAEiGEuTp4Bw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691499757; x=1692104557; 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=I6QBQAGjY2r360IlHRoBLqtdiryrX7RiFTTDs7pUf/s=; b=Yb1k6OWU82S00uPKZ4rgat0tUsRvZpsKHzVjIiKtxa7xZPVJmphXX/22nySLtP1+7f WZ28LVfgDeRAgardKIUWunMoMHHYkr9/SEjz+9OC8RjRl9TcAWFsW3+gNSf0PrKQYDWj I7o+RIon4WnsnMwQgcp9lhB5oy1EUyCWqqOteyUJOzK1FSLNrXj9oj+ru9Tvo0LXDPPx 5uknn9KWyhQcr7JTB1Jr7BHAxsbi/Ud1YzD3B7eyeF0BcOZK2j487yl9ERlRn85LpyAR c3YX6ZpH/JEOE6WSO900Pch5TIy/2igOM5lTXUS2PQgTftjPzANd9RYDYSFmP3sAhZMn 4LhQ== X-Gm-Message-State: AOJu0YxawKebhctvo702AlRnN+iGnv9EdEqKOqZN8qjlw2l/WxtTltWw CLm6faZrKozZQQ14gq0ki8PQ656/nZNB022A8DE= X-Google-Smtp-Source: AGHT+IGI4sjkvPq5FlJLChKC03G3IDBfL8r9LDQBa14X9x6e46zkyN+2uB0RKQUmhONKDEg0sakldw== X-Received: by 2002:adf:ce09:0:b0:317:5caa:c3a3 with SMTP id p9-20020adfce09000000b003175caac3a3mr7489337wrn.40.1691499757343; Tue, 08 Aug 2023 06:02:37 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Julien Grall Subject: [PATCH v3 1/4] mm: Factor out the pdx compression logic in ma/va converters Date: Tue, 8 Aug 2023 14:02:17 +0100 Message-Id: <20230808130220.27891-2-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808130220.27891-1-alejandro.vallejo@cloud.com> References: <20230808130220.27891-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1691499917090100002 Content-Type: text/plain; charset="utf-8" This patch factors out the pdx compression logic hardcoded in both ports for the maddr<->vaddr conversion functions. Touches both x86 and arm ports. Signed-off-by: Alejandro Vallejo Reviewed-by: Julien Grall --- v3: * size_t -> unsigned long (Jan) * uint64_t -> paddr_t (Jan) --- xen/arch/arm/include/asm/mm.h | 3 +-- xen/arch/x86/include/asm/x86_64/page.h | 28 +++++++++++--------------- xen/include/xen/pdx.h | 25 +++++++++++++++++++++++ 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 5b530f0f40..c0d7f0f181 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -319,8 +319,7 @@ static inline void *maddr_to_virt(paddr_t ma) (DIRECTMAP_SIZE >> PAGE_SHIFT)); return (void *)(XENHEAP_VIRT_START - (directmap_base_pdx << PAGE_SHIFT) + - ((ma & ma_va_bottom_mask) | - ((ma & ma_top_mask) >> pfn_pdx_hole_shift))); + maddr_to_directmapoff(ma)); } #endif =20 diff --git a/xen/arch/x86/include/asm/x86_64/page.h b/xen/arch/x86/include/= asm/x86_64/page.h index 53faa7875b..e40b451221 100644 --- a/xen/arch/x86/include/asm/x86_64/page.h +++ b/xen/arch/x86/include/asm/x86_64/page.h @@ -36,26 +36,22 @@ static inline unsigned long __virt_to_maddr(unsigned lo= ng va) { ASSERT(va < DIRECTMAP_VIRT_END); if ( va >=3D DIRECTMAP_VIRT_START ) - va -=3D DIRECTMAP_VIRT_START; - else - { - BUILD_BUG_ON(XEN_VIRT_END - XEN_VIRT_START !=3D GB(1)); - /* Signed, so ((long)XEN_VIRT_START >> 30) fits in an imm32. */ - ASSERT(((long)va >> (PAGE_ORDER_1G + PAGE_SHIFT)) =3D=3D - ((long)XEN_VIRT_START >> (PAGE_ORDER_1G + PAGE_SHIFT))); - - va +=3D xen_phys_start - XEN_VIRT_START; - } - return (va & ma_va_bottom_mask) | - ((va << pfn_pdx_hole_shift) & ma_top_mask); + return directmapoff_to_maddr(va - DIRECTMAP_VIRT_START); + + BUILD_BUG_ON(XEN_VIRT_END - XEN_VIRT_START !=3D GB(1)); + /* Signed, so ((long)XEN_VIRT_START >> 30) fits in an imm32. */ + ASSERT(((long)va >> (PAGE_ORDER_1G + PAGE_SHIFT)) =3D=3D + ((long)XEN_VIRT_START >> (PAGE_ORDER_1G + PAGE_SHIFT))); + + return xen_phys_start + va - XEN_VIRT_START; } =20 static inline void *__maddr_to_virt(unsigned long ma) { - ASSERT(pfn_to_pdx(ma >> PAGE_SHIFT) < (DIRECTMAP_SIZE >> PAGE_SHIFT)); - return (void *)(DIRECTMAP_VIRT_START + - ((ma & ma_va_bottom_mask) | - ((ma & ma_top_mask) >> pfn_pdx_hole_shift))); + /* Offset in the direct map, accounting for pdx compression */ + unsigned long va_offset =3D maddr_to_directmapoff(ma); + ASSERT(va_offset < DIRECTMAP_SIZE); + return (void *)(DIRECTMAP_VIRT_START + va_offset); } =20 /* read access (should only be used for debug printk's) */ diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h index de5439a5e5..8f29598230 100644 --- a/xen/include/xen/pdx.h +++ b/xen/include/xen/pdx.h @@ -160,6 +160,31 @@ static inline unsigned long pdx_to_pfn(unsigned long p= dx) #define mfn_to_pdx(mfn) pfn_to_pdx(mfn_x(mfn)) #define pdx_to_mfn(pdx) _mfn(pdx_to_pfn(pdx)) =20 +/** + * Computes the offset into the direct map of an maddr + * + * @param ma Machine address + * @return Offset on the direct map where that + * machine address can be accessed + */ +static inline unsigned long maddr_to_directmapoff(paddr_t ma) +{ + return ((ma & ma_top_mask) >> pfn_pdx_hole_shift) | + (ma & ma_va_bottom_mask); +} + +/** + * Computes a machine address given a direct map offset + * + * @param offset Offset into the direct map + * @return Corresponding machine address of that virtual location + */ +static inline paddr_t directmapoff_to_maddr(unsigned long offset) +{ + return (((paddr_t)offset << pfn_pdx_hole_shift) & ma_top_mask) | + (offset & ma_va_bottom_mask); +} + /** * Initializes global variables with information about the compressible * range of the current memory regions. --=20 2.34.1 From nobody Thu May 16 08:05:20 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=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1691499788; cv=none; d=zohomail.com; s=zohoarc; b=Kpi+gaOAgDRxpORePPmjarMwZNI4bzogsPAaLtXdZM8BPXF2luUm0j5n4/yw0oiXDRlaY02za6CSSWg+e1agQBJ6oo39VHANlEa/7Xl6RPZZQhKGC7XkVnE5XNnwrDlBQZtlErNfgTqvTQxU1e23JdLkPyhlZdg6QzKrlo8Tir8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691499788; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8bmCX6/SgqPEzLULBMXi4oRdiZi0jx4EL6SjA6yskLk=; b=S17Rh5ogAmSL1oIp0/MSNVRYH+Nu1sWDJ8H3L64uHDuRbUWBZM3rSTf/RbHBYyc2WuBzokxoljuRiFgYR5qMNQ35Bo7j6uyK31JMrFBqCS0Lm/IJTMfw4eF1vnzrEC29By46N8+UrFRziFFo5uDfEuLe9f4ysNlnDB5pNvdCPMs= 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 1691499788708194.15171972069265; Tue, 8 Aug 2023 06:03:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.579783.907907 (Exim 4.92) (envelope-from ) id 1qTMMD-0003TD-7y; Tue, 08 Aug 2023 13:02:41 +0000 Received: by outflank-mailman (output) from mailman id 579783.907907; Tue, 08 Aug 2023 13:02:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qTMMD-0003SD-0W; Tue, 08 Aug 2023 13:02:41 +0000 Received: by outflank-mailman (input) for mailman id 579783; Tue, 08 Aug 2023 13:02:40 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qTMMC-0003KL-6A for xen-devel@lists.xenproject.org; Tue, 08 Aug 2023 13:02:40 +0000 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [2a00:1450:4864:20::330]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id da3608df-35eb-11ee-b280-6b7b168915f2; Tue, 08 Aug 2023 15:02:39 +0200 (CEST) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3fe4cdb724cso35102535e9.1 for ; Tue, 08 Aug 2023 06:02:39 -0700 (PDT) Received: from localhost.localdomain (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id y15-20020a5d4acf000000b003144b50034esm13567072wrs.110.2023.08.08.06.02.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 06:02:37 -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: da3608df-35eb-11ee-b280-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1691499758; x=1692104558; 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=8bmCX6/SgqPEzLULBMXi4oRdiZi0jx4EL6SjA6yskLk=; b=bYvV3jm8vm2ZXHhiwwyLmeZIgAfDGl8g1mq6KQErwgRsYe/a/ByiM5MSIQS7FZHhel 6Hv3ekMucT5gR64edHqzlpOaJpy4Foi3NGc2eQgQaAiReMfAute04vzsr6W1bR/F5ewv iMY2HtiwXSxkMf1JC1nXYTTs6DCeAyM4JyN9k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691499758; x=1692104558; 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=8bmCX6/SgqPEzLULBMXi4oRdiZi0jx4EL6SjA6yskLk=; b=jTaErEwRMirqqcJkhQBv19YNwrI8JwX38zzqeis4V6ooUHyfqGe/mU7SfsNQ41oiHI a++r5xk8TV+Psc0yXOORVKQ/CEkDAd8FLJXh00Tfd2uIqMWS19KhEM2Z3IAym4JBRZJj rbDzpL2/tShna+EZeKph3MlkK+z3bdFcvx0Fm/LB7fqgYN6a7JRZTvGik4oA52qTuPFu H3tztfhQwxSmahXOwOLfN5P7aU6IcK51B6Dnd0KkGyvS+yFaRyVGkEagfngR75QLSiGv dbArUJq0XQ7E/7lgUrPuL4BlX4fCIJ+4PJuNqK+pPwF7adDCWNLo4/d3GuMQm4WqgNrk gIlw== X-Gm-Message-State: AOJu0YzuNHGy3sMewVkbeCXJ8c/zCsd4q9fdWI14QQw0+4VYFby43CGo l07KWgQFMg6MnatXqomZyZqkCiZt5o3cT73vf5I= X-Google-Smtp-Source: AGHT+IERdw9jYA65AeSDb2KHKpJuXgzQlTIsNLOUX/DL5ZjhbGQmF3n4QiyOitzjtZblISW7wP80Xg== X-Received: by 2002:adf:e50e:0:b0:314:1ebc:6e19 with SMTP id j14-20020adfe50e000000b003141ebc6e19mr8153117wrm.64.1691499758316; Tue, 08 Aug 2023 06:02:38 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Julien Grall Subject: [PATCH v3 2/4] mm/pdx: Standardize region validation wrt pdx compression Date: Tue, 8 Aug 2023 14:02:18 +0100 Message-Id: <20230808130220.27891-3-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808130220.27891-1-alejandro.vallejo@cloud.com> References: <20230808130220.27891-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1691499916989100001 Content-Type: text/plain; charset="utf-8" Regions must be occasionally validated for pdx compression validity. That is, whether any of the machine addresses spanning the region have a bit set in the pdx "hole" (which is expected to always contain zeroes). There are a few such tests through the code, and they all check for different things. This patch replaces all such occurrences with a call to a centralized function that checks a region for validity. Signed-off-by: Alejandro Vallejo Reviewed-by: Julien Grall --- v3: * Pack variable declarations on top of the function (Jan) * Restrict variable scope by moving their declaration to the top of the loop in which they are used (Jan) --- xen/arch/x86/x86_64/mm.c | 6 ++++-- xen/common/efi/boot.c | 13 ++++++++++--- xen/common/pdx.c | 10 ++++++++-- xen/include/xen/pdx.h | 9 +++++++++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index 15b36e332d..d3f7c59638 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -1158,6 +1158,8 @@ static int transfer_pages_to_heap(struct mem_hotadd_i= nfo *info) static int mem_hotadd_check(unsigned long spfn, unsigned long epfn) { unsigned long s, e, length, sidx, eidx; + paddr_t mem_base =3D pfn_to_paddr(spfn); + unsigned long mem_npages =3D epfn - spfn; =20 if ( (spfn >=3D epfn) ) return 0; @@ -1168,7 +1170,7 @@ static int mem_hotadd_check(unsigned long spfn, unsig= ned long epfn) if ( (spfn | epfn) & ((1UL << PAGETABLE_ORDER) - 1) ) return 0; =20 - if ( (spfn | epfn) & pfn_hole_mask ) + if ( !pdx_is_region_compressible(mem_base, mem_npages) ) return 0; =20 /* Make sure the new range is not present now */ @@ -1207,7 +1209,7 @@ static int mem_hotadd_check(unsigned long spfn, unsig= ned long epfn) =20 length +=3D (e - s) * sizeof(struct page_info); =20 - if ((length >> PAGE_SHIFT) > (epfn - spfn)) + if ((length >> PAGE_SHIFT) > mem_npages) return 0; =20 return 1; diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 79a654af69..be4e3a0259 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #if EFI_PAGE_SIZE !=3D PAGE_SIZE # error Cannot use xen/pfn.h here! @@ -1645,9 +1646,11 @@ static __init void copy_mapping(unsigned long mfn, u= nsigned long end, =20 static bool __init cf_check ram_range_valid(unsigned long smfn, unsigned l= ong emfn) { + paddr_t ram_base =3D pfn_to_paddr(smfn); + unsigned long ram_npages =3D emfn - smfn; unsigned long sz =3D pfn_to_pdx(emfn - 1) / PDX_GROUP_COUNT + 1; =20 - return !(smfn & pfn_hole_mask) && + return pdx_is_region_compressible(ram_base, ram_npages) && find_next_bit(pdx_group_valid, sz, pfn_to_pdx(smfn) / PDX_GROUP_COUNT) < sz; } @@ -1681,6 +1684,8 @@ void __init efi_init_memory(void) u64 len =3D desc->NumberOfPages << EFI_PAGE_SHIFT; unsigned long smfn, emfn; unsigned int prot =3D PAGE_HYPERVISOR_RWX; + paddr_t mem_base; + unsigned long mem_npages; =20 printk(XENLOG_INFO " %013" PRIx64 "-%013" PRIx64 " type=3D%u attr=3D%016" PRIx64 "\n", @@ -1732,6 +1737,9 @@ void __init efi_init_memory(void) smfn =3D PFN_DOWN(desc->PhysicalStart); emfn =3D PFN_UP(desc->PhysicalStart + len); =20 + mem_base =3D pfn_to_paddr(smfn); + mem_npages =3D emfn - smfn; + if ( desc->Attribute & EFI_MEMORY_WB ) prot |=3D _PAGE_WB; else if ( desc->Attribute & EFI_MEMORY_WT ) @@ -1759,8 +1767,7 @@ void __init efi_init_memory(void) prot |=3D _PAGE_NX; =20 if ( pfn_to_pdx(emfn - 1) < (DIRECTMAP_SIZE >> PAGE_SHIFT) && - !(smfn & pfn_hole_mask) && - !((smfn ^ (emfn - 1)) & ~pfn_pdx_bottom_mask) ) + pdx_is_region_compressible(mem_base, mem_npages)) { if ( (unsigned long)mfn_to_virt(emfn - 1) >=3D HYPERVISOR_VIRT= _END ) prot &=3D ~_PAGE_GLOBAL; diff --git a/xen/common/pdx.c b/xen/common/pdx.c index 99d4a90a50..3c88ceeb9c 100644 --- a/xen/common/pdx.c +++ b/xen/common/pdx.c @@ -88,7 +88,7 @@ bool __mfn_valid(unsigned long mfn) } =20 /* Sets all bits from the most-significant 1-bit down to the LSB */ -static uint64_t __init fill_mask(uint64_t mask) +static uint64_t fill_mask(uint64_t mask) { while (mask & (mask + 1)) mask |=3D mask + 1; @@ -96,6 +96,12 @@ static uint64_t __init fill_mask(uint64_t mask) return mask; } =20 +bool pdx_is_region_compressible(paddr_t base, unsigned long npages) +{ + return !(paddr_to_pfn(base) & pfn_hole_mask) && + !(pdx_region_mask(base, npages * PAGE_SIZE) & ~ma_va_bottom_mas= k); +} + /* We don't want to compress the low MAX_ORDER bits of the addresses. */ uint64_t __init pdx_init_mask(uint64_t base_addr) { @@ -103,7 +109,7 @@ uint64_t __init pdx_init_mask(uint64_t base_addr) (uint64_t)1 << (MAX_ORDER + PAGE_SHIFT)) - 1); } =20 -uint64_t __init pdx_region_mask(uint64_t base, uint64_t len) +uint64_t pdx_region_mask(uint64_t base, uint64_t len) { /* * We say a bit "moves" in a range if there exist 2 addresses in that diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h index 8f29598230..5674506f3a 100644 --- a/xen/include/xen/pdx.h +++ b/xen/include/xen/pdx.h @@ -79,6 +79,15 @@ extern unsigned long pfn_top_mask, ma_top_mask; (sizeof(*frame_table) & -sizeof(*frame_table))) extern unsigned long pdx_group_valid[]; =20 +/** + * Validate a region's compatibility with the current compression runtime + * + * @param base Base address of the region + * @param npages Number of PAGE_SIZE-sized pages in the region + * @return True iff the region can be used with the current compression + */ +bool pdx_is_region_compressible(paddr_t base, unsigned long npages); + /** * Calculates a mask covering "moving" bits of all addresses of a region * --=20 2.34.1 From nobody Thu May 16 08:05:20 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=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1691499788; cv=none; d=zohomail.com; s=zohoarc; b=hWZvYjXvCPnLZla3LmHAyRub+wRdM/pcrhsFGOrXigf55F0T7PD1kwIGfwC4uhVgeALRHeKzK7HRxSzs5VgyUr+blN+80mh1ApPIKFETtY7MaySLxY9dQdSXWUe2CjKXT1aEPgj0Pf5soPriXF/5M/MpypcPhYgrFUetJegJkZI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691499788; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Qw5ydlPzexz1P1bvK3hrQOjcFc77zxXZqKmERgYMjHk=; b=J08XKAxmtOQ3ghBhhxfqyxEK2mBeG5L2ZUUNDx29wp5dlN6NWKG9MQrong4vyP8/A98SvUiqsjG8dHqT8PMFYkUDHGZCUOtjxHPrEvZC9RppYwt9IzWYyxFIDRzaUn2Io2b6zNRGnUOpKa9bg1BUXifR2+RW99S6cWps5Gj2gM0= 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 1691499788823880.2762555220318; Tue, 8 Aug 2023 06:03:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.579785.907929 (Exim 4.92) (envelope-from ) id 1qTMMF-00046m-MQ; Tue, 08 Aug 2023 13:02:43 +0000 Received: by outflank-mailman (output) from mailman id 579785.907929; Tue, 08 Aug 2023 13:02:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qTMMF-000469-HI; Tue, 08 Aug 2023 13:02:43 +0000 Received: by outflank-mailman (input) for mailman id 579785; Tue, 08 Aug 2023 13:02:42 +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 1qTMME-0003uf-8Q for xen-devel@lists.xenproject.org; Tue, 08 Aug 2023 13:02:42 +0000 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [2a00:1450:4864:20::329]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id daa46d75-35eb-11ee-8613-37d641c3527e; Tue, 08 Aug 2023 15:02:40 +0200 (CEST) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fe4b95c371so23264865e9.1 for ; Tue, 08 Aug 2023 06:02:40 -0700 (PDT) Received: from localhost.localdomain (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id y15-20020a5d4acf000000b003144b50034esm13567072wrs.110.2023.08.08.06.02.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 06:02:38 -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: daa46d75-35eb-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1691499759; x=1692104559; 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=Qw5ydlPzexz1P1bvK3hrQOjcFc77zxXZqKmERgYMjHk=; b=RgIsn4uEOt+KjgK2T9EVYtD4z2FBCAK55OG2bEpL7qWYK1VEylPO8+JC7Uimb+w/h5 c/pOGK8spbPUZmHBk+F7aBBQwcoxu5wTMqYgbk/rwbWOnrRaO7RCUyUUASKpmLfFOFLi +olC7T2HgdoQgeDjsW50FW/0s6DTYxVFf2Iqo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691499759; x=1692104559; 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=Qw5ydlPzexz1P1bvK3hrQOjcFc77zxXZqKmERgYMjHk=; b=ifh0C4ftYhrYMhDioCqYR24WszCLUuquqfirScwa6I655qyZbzfchpX1ckCdtKep2Y FLK0sLuxJ7G7TJeuPXheDfl6pPo4MQ1lDv6/oOjFzPDOtlWPsEe19EmfgHs/WwxvhRAl 39K1Zi6Lla+8O7VKwqyZxk3VFrMlhUsfB4Jk6Y9j8PbhgvoUjE1RP4s5wYbiaW9Upwd6 IuFmoWN2fCK2+wIUethvCjrAWtkFY2cwOiroWb6R7AvFUtq4NHD/+TfnywgBYB+2eYD6 QFpKwEA/nJMpqsbrIw8tgHRDA7lYXg7m8P80I95HO9bZBJ5TrB5QyBFx4IL4Ra5nENej MRBA== X-Gm-Message-State: AOJu0Yy2/ZZMD7q5pV7NIeqlSBnMRvEtUC9T3S7o6wZYEBzVS+4y0RLa u3tX/u+iGfk2PTMf4s8snsOPyZ+H0N5a/O8M8F8= X-Google-Smtp-Source: AGHT+IG5t63tS6JnlI7jLQBy9wATzP5e8eansQp2xZQ2UfnvSwZDyJeO9dhLA0qeSeJUwSS4AguJmA== X-Received: by 2002:a05:600c:2212:b0:3fa:aeac:e978 with SMTP id z18-20020a05600c221200b003faaeace978mr8102633wml.0.1691499759057; Tue, 08 Aug 2023 06:02:39 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Julien Grall Subject: [PATCH v3 3/4] pdx: Reorder pdx.[ch] Date: Tue, 8 Aug 2023 14:02:19 +0100 Message-Id: <20230808130220.27891-4-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808130220.27891-1-alejandro.vallejo@cloud.com> References: <20230808130220.27891-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1691499856327100001 Content-Type: text/plain; charset="utf-8" The next patch compiles out compression-related chunks, and it's helpful to have them grouped together beforehand. Signed-off-by: Alejandro Vallejo Reviewed-by: Julien Grall --- v3: * No changes --- xen/common/pdx.c | 58 +++++++++++++++++++++--------------------- xen/include/xen/pdx.h | 59 ++++++++++++++++++++++--------------------- 2 files changed, 59 insertions(+), 58 deletions(-) diff --git a/xen/common/pdx.c b/xen/common/pdx.c index 3c88ceeb9c..d3d38965bd 100644 --- a/xen/common/pdx.c +++ b/xen/common/pdx.c @@ -20,6 +20,35 @@ #include #include =20 +/** + * Maximum (non-inclusive) usable pdx. Must be + * modifiable after init due to memory hotplug + */ +unsigned long __read_mostly max_pdx; + +unsigned long __read_mostly pdx_group_valid[BITS_TO_LONGS( + (FRAMETABLE_NR + PDX_GROUP_COUNT - 1) / PDX_GROUP_COUNT)] =3D { [0] = =3D 1 }; + +bool __mfn_valid(unsigned long mfn) +{ + if ( unlikely(evaluate_nospec(mfn >=3D max_page)) ) + return false; + return likely(!(mfn & pfn_hole_mask)) && + likely(test_bit(pfn_to_pdx(mfn) / PDX_GROUP_COUNT, + pdx_group_valid)); +} + +void set_pdx_range(unsigned long smfn, unsigned long emfn) +{ + unsigned long idx, eidx; + + idx =3D pfn_to_pdx(smfn) / PDX_GROUP_COUNT; + eidx =3D (pfn_to_pdx(emfn - 1) + PDX_GROUP_COUNT) / PDX_GROUP_COUNT; + + for ( ; idx < eidx; ++idx ) + __set_bit(idx, pdx_group_valid); +} + /* * Diagram to make sense of the following variables. The masks and shifts * are done on mfn values in order to convert to/from pdx: @@ -47,12 +76,6 @@ * ones. */ =20 -/** - * Maximum (non-inclusive) usable pdx. Must be - * modifiable after init due to memory hotplug - */ -unsigned long __read_mostly max_pdx; - /** Mask for the lower non-compressible bits of an mfn */ unsigned long __ro_after_init pfn_pdx_bottom_mask =3D ~0UL; =20 @@ -75,18 +98,6 @@ unsigned long __ro_after_init pfn_hole_mask =3D 0; /** Number of bits of the "compressible" bit slice of an mfn */ unsigned int __ro_after_init pfn_pdx_hole_shift =3D 0; =20 -unsigned long __read_mostly pdx_group_valid[BITS_TO_LONGS( - (FRAMETABLE_NR + PDX_GROUP_COUNT - 1) / PDX_GROUP_COUNT)] =3D { [0] = =3D 1 }; - -bool __mfn_valid(unsigned long mfn) -{ - if ( unlikely(evaluate_nospec(mfn >=3D max_page)) ) - return false; - return likely(!(mfn & pfn_hole_mask)) && - likely(test_bit(pfn_to_pdx(mfn) / PDX_GROUP_COUNT, - pdx_group_valid)); -} - /* Sets all bits from the most-significant 1-bit down to the LSB */ static uint64_t fill_mask(uint64_t mask) { @@ -124,17 +135,6 @@ uint64_t pdx_region_mask(uint64_t base, uint64_t len) return fill_mask(base ^ (base + len - 1)); } =20 -void set_pdx_range(unsigned long smfn, unsigned long emfn) -{ - unsigned long idx, eidx; - - idx =3D pfn_to_pdx(smfn) / PDX_GROUP_COUNT; - eidx =3D (pfn_to_pdx(emfn - 1) + PDX_GROUP_COUNT) / PDX_GROUP_COUNT; - - for ( ; idx < eidx; ++idx ) - __set_bit(idx, pdx_group_valid); -} - void __init pfn_pdx_hole_setup(unsigned long mask) { unsigned int i, j, bottom_shift =3D 0, hole_shift =3D 0; diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h index 5674506f3a..b5367a33ca 100644 --- a/xen/include/xen/pdx.h +++ b/xen/include/xen/pdx.h @@ -70,15 +70,41 @@ #ifdef CONFIG_HAS_PDX =20 extern unsigned long max_pdx; -extern unsigned long pfn_pdx_bottom_mask, ma_va_bottom_mask; -extern unsigned int pfn_pdx_hole_shift; -extern unsigned long pfn_hole_mask; -extern unsigned long pfn_top_mask, ma_top_mask; =20 #define PDX_GROUP_COUNT ((1 << PDX_GROUP_SHIFT) / \ (sizeof(*frame_table) & -sizeof(*frame_table))) extern unsigned long pdx_group_valid[]; =20 +/** + * Mark [smfn, emfn) as allocatable in the frame table + * + * @param smfn Start mfn + * @param emfn End mfn + */ +void set_pdx_range(unsigned long smfn, unsigned long emfn); + +/** + * Invoked to determine if an mfn has an associated valid frame table entry + * + * In order for it to be legal it must pass bounds, grouping and + * compression sanity checks. + * + * @param mfn To-be-checked mfn + * @return True iff all checks pass + */ +bool __mfn_valid(unsigned long mfn); + +#define page_to_pdx(pg) ((pg) - frame_table) +#define pdx_to_page(pdx) gcc11_wrap(frame_table + (pdx)) + +#define mfn_to_pdx(mfn) pfn_to_pdx(mfn_x(mfn)) +#define pdx_to_mfn(pdx) _mfn(pdx_to_pfn(pdx)) + +extern unsigned long pfn_pdx_bottom_mask, ma_va_bottom_mask; +extern unsigned int pfn_pdx_hole_shift; +extern unsigned long pfn_hole_mask; +extern unsigned long pfn_top_mask, ma_top_mask; + /** * Validate a region's compatibility with the current compression runtime * @@ -120,28 +146,6 @@ uint64_t pdx_region_mask(uint64_t base, uint64_t len); */ uint64_t pdx_init_mask(uint64_t base_addr); =20 -/** - * Mark [smfn, emfn) as accesible in the frame table - * - * @param smfn Start mfn - * @param emfn End mfn - */ -void set_pdx_range(unsigned long smfn, unsigned long emfn); - -#define page_to_pdx(pg) ((pg) - frame_table) -#define pdx_to_page(pdx) gcc11_wrap(frame_table + (pdx)) - -/** - * Invoked to determine if an mfn has an associated valid frame table entry - * - * In order for it to be legal it must pass bounds, grouping and - * compression sanity checks. - * - * @param mfn To-be-checked mfn - * @return True iff all checks pass - */ -bool __mfn_valid(unsigned long mfn); - /** * Map pfn to its corresponding pdx * @@ -166,9 +170,6 @@ static inline unsigned long pdx_to_pfn(unsigned long pd= x) ((pdx << pfn_pdx_hole_shift) & pfn_top_mask); } =20 -#define mfn_to_pdx(mfn) pfn_to_pdx(mfn_x(mfn)) -#define pdx_to_mfn(pdx) _mfn(pdx_to_pfn(pdx)) - /** * Computes the offset into the direct map of an maddr * --=20 2.34.1 From nobody Thu May 16 08:05:20 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=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1691499792; cv=none; d=zohomail.com; s=zohoarc; b=YB4KCLaXMw9c7199E6uaRA35h4P+2A7VSpPPyHRyP7oMcLxucDjUixmUl7Di1wmNlbqMIRC1uIFTjr6hqpOseBMvaldkuz3HQSNd+oZhKVoFfIkRZcjMFUW1fQ8ly0H1GrSOdEvFmRvn3AWKRlvwmQFUqrWwJIU5PIC697QLlBI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691499792; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CLKiL/jNslxYi/QSWYQzg3uu6el6+QZP5XsqGeRNlAs=; b=ZfmxzTEEdNgeCpqjGefQGDr7iOU9WklcXnHNlf/CAraqu+hVnj0kVIMLcVw4I1eapIOiZjSx7dW8CMis6Sv7exzOE8ysLiLLLIQJaem8HLhnAHuAoPB7UTdmdiouMtCbmb/TFBf2mR06w2wtgZkVoqAVYM3BbLpp4N5mIdd4mCo= 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 1691499792314966.3469096397004; Tue, 8 Aug 2023 06:03:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.579784.907925 (Exim 4.92) (envelope-from ) id 1qTMMF-00043N-DB; Tue, 08 Aug 2023 13:02:43 +0000 Received: by outflank-mailman (output) from mailman id 579784.907925; Tue, 08 Aug 2023 13:02:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qTMMF-00043G-9I; Tue, 08 Aug 2023 13:02:43 +0000 Received: by outflank-mailman (input) for mailman id 579784; Tue, 08 Aug 2023 13:02:41 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qTMMD-0003KL-8i for xen-devel@lists.xenproject.org; Tue, 08 Aug 2023 13:02:41 +0000 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [2a00:1450:4864:20::32f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id db1c4a94-35eb-11ee-b280-6b7b168915f2; Tue, 08 Aug 2023 15:02:40 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fbea14700bso48055405e9.3 for ; Tue, 08 Aug 2023 06:02:40 -0700 (PDT) Received: from localhost.localdomain (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id y15-20020a5d4acf000000b003144b50034esm13567072wrs.110.2023.08.08.06.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 06:02:39 -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: db1c4a94-35eb-11ee-b280-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1691499760; x=1692104560; 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=CLKiL/jNslxYi/QSWYQzg3uu6el6+QZP5XsqGeRNlAs=; b=Yk2dU9B70C6NTd0q+fmYujVQUDxUzjoJ1Ysp42lk4W37mG7tb3DKPXw/RhRga+2oRR M/kOXQzc5+oJVn6ptI/aUS9kSvCrV0rxeKDHsjAyrb8/4pnJY27YeCCAS5399PRQeBIY BWMKM/aK7koR6IvEahvAw0xLiWNgi/Wr4WqYc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691499760; x=1692104560; 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=CLKiL/jNslxYi/QSWYQzg3uu6el6+QZP5XsqGeRNlAs=; b=ZGrpmHoJwna1rb1N1Ea0s8BxA2L8UUjuv7e6x2BgP0jKCLQmoTEu2qe2o0SlYIQ8W4 lXFL4504GWdn79DJcOFZ09aBCOZ3ztNvY4wgynDdsLC8ADe4aYtW03ZGZkphtQZJaUwI t5X5vp2nqoiDwegiqN7UpqR3CjQIAS4qSyiOIsVAGIpZny5aWWGD6aJ5MX6vnv1P3Ufd gwckdetsMDG3fWfoDBEjZBVqKESZLWTfEEPpyaIJhRdiK63D3utrSdF25XvMPy7CqJRb zsXQ98lCpCakR6awF61ugD6W3orPIRdAPLRl4Ilxsm8wgsI3XqO43NDPJpCv4jcNO2LN lbPA== X-Gm-Message-State: AOJu0YzsViNU8HhyhmkVUmN4p/LOfTbaa0VC/beB3nSMYZpB8RjVMKZ2 k7G8xfwq5DtaLE60qcHosdEKF4cy0HP9TJg8Ttw= X-Google-Smtp-Source: AGHT+IGaM6+/0iPdaGeT67glHUk1CVKgmWsCdOnkmwkJfkQWD8hDRBMP6LVD/yt05UNn/y/OWrxcyA== X-Received: by 2002:a1c:7708:0:b0:3fe:108d:7f88 with SMTP id t8-20020a1c7708000000b003fe108d7f88mr7998422wmi.36.1691499759914; Tue, 08 Aug 2023 06:02:39 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Julien Grall Subject: [PATCH v3 4/4] pdx: Add CONFIG_PDX_COMPRESSION as a common Kconfig option Date: Tue, 8 Aug 2023 14:02:20 +0100 Message-Id: <20230808130220.27891-5-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808130220.27891-1-alejandro.vallejo@cloud.com> References: <20230808130220.27891-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1691499857306100003 Content-Type: text/plain; charset="utf-8" Adds a new compile-time flag to allow disabling pdx compression and compiles out compression-related code/data. It also shorts the pdx<->pfn conversion macros and creates stubs for masking fucntions. While at it, removes the old arch-defined CONFIG_HAS_PDX flag, as it was not removable in practice. Signed-off-by: Alejandro Vallejo Reviewed-by: Julien Grall --- v3: * Fixed a typo in Kconfig's help * Gated CONFIG_PDX_COMPRESSION under EXPERT=3Dy and left default=3DARM * Fixed commit message after renaming CONFIG_PDX_COMPRESSION (Julien) * Changed #else comment to the reason it executes (Julien) * Various blank-line related style changes (Jan) --- xen/arch/arm/Kconfig | 1 - xen/arch/x86/Kconfig | 1 - xen/arch/x86/domain.c | 19 +++++++++++++------ xen/common/Kconfig | 13 ++++++++++--- xen/common/Makefile | 2 +- xen/common/pdx.c | 16 ++++++++++++---- xen/include/xen/pdx.h | 38 +++++++++++++++++++++++++++++++++++--- 7 files changed, 71 insertions(+), 19 deletions(-) diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 57bd1d01d7..224db89c05 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -14,7 +14,6 @@ config ARM select HAS_ALTERNATIVE select HAS_DEVICE_TREE select HAS_PASSTHROUGH - select HAS_PDX select HAS_PMAP select HAS_UBSAN select IOMMU_FORCE_PT_SHARE diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 92f3a627da..30df085d96 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -24,7 +24,6 @@ config X86 select HAS_PASSTHROUGH select HAS_PCI select HAS_PCI_MSI - select HAS_PDX select HAS_SCHED_GRANULARITY select HAS_UBSAN select HAS_VPCI if HVM diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index fe86a7f853..f476df17e4 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -458,7 +458,7 @@ void domain_cpu_policy_changed(struct domain *d) } } =20 -#ifndef CONFIG_BIGMEM +#if !defined(CONFIG_BIGMEM) && defined(CONFIG_PDX_COMPRESSION) /* * The hole may be at or above the 44-bit boundary, so we need to determine * the total bit count until reaching 32 significant (not squashed out) bi= ts @@ -485,13 +485,20 @@ static unsigned int __init noinline _domain_struct_bi= ts(void) struct domain *alloc_domain_struct(void) { struct domain *d; -#ifdef CONFIG_BIGMEM - const unsigned int bits =3D 0; -#else + /* - * We pack the PDX of the domain structure into a 32-bit field within - * the page_info structure. Hence the MEMF_bits() restriction. + * Without CONFIG_BIGMEM, we pack the PDX of the domain structure into + * a 32-bit field within the page_info structure. Hence the MEMF_bits() + * restriction. With PDX compression in place the number of bits must + * be calculated at runtime, but it's fixed otherwise. + * + * On systems with CONFIG_BIGMEM there's no packing, and so there's no + * such restriction. */ +#if defined(CONFIG_BIGMEM) || !defined(CONFIG_PDX_COMPRESSION) + const unsigned int bits =3D IS_ENABLED(CONFIG_BIGMEM) ? 0 : + 32 + PAGE_SHIFT; +#else static unsigned int __read_mostly bits; =20 if ( unlikely(!bits) ) diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 0d248ab941..2c1d1fc3a2 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -23,6 +23,16 @@ config GRANT_TABLE =20 If unsure, say Y. =20 +config PDX_COMPRESSION + bool "PDX (Page inDeX) compression support" if EXPERT + default ARM + help + PDX compression is a technique that allows the hypervisor to + represent physical addresses in a very space-efficient manner. + This is very helpful reducing memory wastage in systems with + memory banks with base addresses far from each other, but carries + a performance cost. + config ALTERNATIVE_CALL bool =20 @@ -53,9 +63,6 @@ config HAS_IOPORTS config HAS_KEXEC bool =20 -config HAS_PDX - bool - config HAS_PMAP bool =20 diff --git a/xen/common/Makefile b/xen/common/Makefile index 46049eac35..0020cafb8a 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -29,7 +29,7 @@ obj-y +=3D multicall.o obj-y +=3D notifier.o obj-$(CONFIG_NUMA) +=3D numa.o obj-y +=3D page_alloc.o -obj-$(CONFIG_HAS_PDX) +=3D pdx.o +obj-y +=3D pdx.o obj-$(CONFIG_PERF_COUNTERS) +=3D perfc.o obj-bin-$(CONFIG_HAS_PMAP) +=3D pmap.init.o obj-y +=3D preempt.o diff --git a/xen/common/pdx.c b/xen/common/pdx.c index d3d38965bd..d3d63b0750 100644 --- a/xen/common/pdx.c +++ b/xen/common/pdx.c @@ -31,11 +31,16 @@ unsigned long __read_mostly pdx_group_valid[BITS_TO_LON= GS( =20 bool __mfn_valid(unsigned long mfn) { - if ( unlikely(evaluate_nospec(mfn >=3D max_page)) ) + bool invalid =3D mfn >=3D max_page; + +#ifdef CONFIG_PDX_COMPRESSION + invalid |=3D mfn & pfn_hole_mask; +#endif + + if ( unlikely(evaluate_nospec(invalid)) ) return false; - return likely(!(mfn & pfn_hole_mask)) && - likely(test_bit(pfn_to_pdx(mfn) / PDX_GROUP_COUNT, - pdx_group_valid)); + + return test_bit(pfn_to_pdx(mfn) / PDX_GROUP_COUNT, pdx_group_valid); } =20 void set_pdx_range(unsigned long smfn, unsigned long emfn) @@ -49,6 +54,8 @@ void set_pdx_range(unsigned long smfn, unsigned long emfn) __set_bit(idx, pdx_group_valid); } =20 +#ifdef CONFIG_PDX_COMPRESSION + /* * Diagram to make sense of the following variables. The masks and shifts * are done on mfn values in order to convert to/from pdx: @@ -176,6 +183,7 @@ void __init pfn_pdx_hole_setup(unsigned long mask) ma_top_mask =3D pfn_top_mask << PAGE_SHIFT; } =20 +#endif /* CONFIG_PDX_COMPRESSION */ =20 /* * Local variables: diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h index b5367a33ca..6511aba6c7 100644 --- a/xen/include/xen/pdx.h +++ b/xen/include/xen/pdx.h @@ -67,8 +67,6 @@ * region involved. */ =20 -#ifdef CONFIG_HAS_PDX - extern unsigned long max_pdx; =20 #define PDX_GROUP_COUNT ((1 << PDX_GROUP_SHIFT) / \ @@ -100,6 +98,8 @@ bool __mfn_valid(unsigned long mfn); #define mfn_to_pdx(mfn) pfn_to_pdx(mfn_x(mfn)) #define pdx_to_mfn(pdx) _mfn(pdx_to_pfn(pdx)) =20 +#ifdef CONFIG_PDX_COMPRESSION + extern unsigned long pfn_pdx_bottom_mask, ma_va_bottom_mask; extern unsigned int pfn_pdx_hole_shift; extern unsigned long pfn_hole_mask; @@ -206,7 +206,39 @@ static inline paddr_t directmapoff_to_maddr(unsigned l= ong offset) */ void pfn_pdx_hole_setup(unsigned long mask); =20 -#endif /* HAS_PDX */ +#else /* !CONFIG_PDX_COMPRESSION */ + +/* Without PDX compression we can skip some computations */ + +/* pdx<->pfn =3D=3D identity */ +#define pdx_to_pfn(x) (x) +#define pfn_to_pdx(x) (x) + +/* directmap is indexed by by maddr */ +#define maddr_to_directmapoff(x) (x) +#define directmapoff_to_maddr(x) (x) + +static inline bool pdx_is_region_compressible(unsigned long smfn, + unsigned long emfn) +{ + return true; +} + +static inline uint64_t pdx_init_mask(uint64_t base_addr) +{ + return 0; +} + +static inline uint64_t pdx_region_mask(uint64_t base, uint64_t len) +{ + return 0; +} + +static inline void pfn_pdx_hole_setup(unsigned long mask) +{ +} + +#endif /* CONFIG_PDX_COMPRESSION */ #endif /* __XEN_PDX_H__ */ =20 /* --=20 2.34.1