From patchwork Fri Jun 14 17:51:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 166872 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2351214ilk; Fri, 14 Jun 2019 10:53:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqxoAeKUlJUDSzQmMtmXgriPNVvxeUNrCxvayvfd0v84/tpZ6AxiJ8ldC/bMotSy8bOFmtG8 X-Received: by 2002:a6b:7606:: with SMTP id g6mr12718320iom.288.1560534810479; Fri, 14 Jun 2019 10:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560534810; cv=none; d=google.com; s=arc-20160816; b=SJlyiRxoA2Wp1TXpeA0micAUPvtIYA0Eiai+LfgsWsejPIHDF2enjEgmgsQxdIsNFt s2Zty2I5wZORqhenxGbeOZDbrn4j8EIDQAq28xEbKpGlfhiLRQ1RibY2C0D1Re5PsbrM 26S8k6/iOCumLGjCGo9St93omXCjZkUk10NrDbG0bB2jzWwLmJ6JUiTEyZ84L4QG77Et iA7eqP8DZJ6eMGhyrKr+1YhD1/V0g0Y77NDBUSVzHrtwCTJPEt4YCiRN1tzDBL+mnqpt 7lHEyGP3+IBvTZUtNCOxn3FY1ss7DDoRveRU2YiNA7z6grk1ZcNpPqGV8MmIvKoVP8rd CBzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=Yd7gtfLJeHGzkP2f2xWn9TBnjz7Zjz3L5dSjowRT1rs=; b=KExcQcbm3vppSmCXGIj9EFm0PghWCSECmdNCOoPvTV73tlZU/7ug9z3gw9B+/5uYIN d5QvY2uJKsJVgKp3uUL9bhbXrtGsgzTjZVyrAq5sHIgGmaXZIFvSRTV4vd8gnqPXxtvX g9bbY/B1BKXSeVhmY3QK67uuvAFylB62SzCkq/JRVdQXEriV6cRKrcVcrIDe1pwD/5mQ kuFFWUju9pdZqjJ96xODloNwLgDpKrPGrKfgSxmuh80vN8w3n1OQHhBzOkD3thE//Cxw eGIoNd5FFT0nk6J3pPO8//26cabbK8S/g+Q1GUfAMq5vumGFLOf2QwOrYGub2x9Sw5zO KAZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id f23si5057820jaa.12.2019.06.14.10.53.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Jun 2019 10:53:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hbqMq-0001p6-M4; Fri, 14 Jun 2019 17:52:00 +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 1hbqMo-0001nK-EF for xen-devel@lists.xenproject.org; Fri, 14 Jun 2019 17:51:58 +0000 X-Inumbo-ID: 1802f8a0-8ecd-11e9-a2e8-0f098cab047c Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 1802f8a0-8ecd-11e9-a2e8-0f098cab047c; Fri, 14 Jun 2019 17:51:53 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3CDC4344; Fri, 14 Jun 2019 10:51:53 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 52C373F718; Fri, 14 Jun 2019 10:51:52 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 14 Jun 2019 18:51:36 +0100 Message-Id: <20190614175144.20046-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190614175144.20046-1-julien.grall@arm.com> References: <20190614175144.20046-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v3 1/9] xen/arm: Rework HSCTLR_BASE 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , Stefano Stabellini , Andrii_Anisov@epam.com, Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The current value of HSCTLR_BASE for Arm64 is pretty wrong. It would actually turn on SCTLR_EL2.nAA (bit 6) on hardware implementing ARMv8.4-LSE. Furthermore, the documentation of what is cleared/set in SCTLR_EL2 is also not correct and looks like to be a verbatim copy from Arm32. HSCTLR_BASE is replaced with a bunch of per-architecture new defines helping to understand better what is the initial value for SCTLR_EL2/HSCTLR. Note the defines *_CLEAR are only used to check the state of each bits are known. Lastly, the documentation is dropped from arm{32,64}/head.S as it would be pretty easy to get out-of-sync with the definitions. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Reviewed-by: Stefano Stabellini --- Note this patch was part of MM-PART2 before. As this was the only patch of the series not merged, it is now part of MM-PART3. Changes in v3: - Add comment on top of HSCTLR_CLEAR/SCTLR_CLEAR to explain that it is only used one time at pre-processing time - Fix typo in the commit message - Add Andrii's reviewed-by Changes in v2: - Use BIT(..., UL) instead of _BITUL --- xen/arch/arm/arm32/head.S | 12 +-------- xen/arch/arm/arm64/head.S | 10 +------- xen/include/asm-arm/processor.h | 56 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 21 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index 5f817d473e..18ded49a04 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -224,17 +224,7 @@ cpu_init_done: ldr r0, =(TCR_RES1|TCR_SH0_IS|TCR_ORGN0_WBWA|TCR_IRGN0_WBWA|TCR_T0SZ(0)) mcr CP32(r0, HTCR) - /* - * Set up the HSCTLR: - * Exceptions in LE ARM, - * Low-latency IRQs disabled, - * Write-implies-XN disabled (for now), - * D-cache disabled (for now), - * I-cache enabled, - * Alignment checking enabled, - * MMU translation disabled (for now). - */ - ldr r0, =(HSCTLR_BASE|SCTLR_Axx_ELx_A) + ldr r0, =HSCTLR_SET mcr CP32(r0, HSCTLR) /* diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index ddd3a33108..08094a273e 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -352,15 +352,7 @@ skip_bss: msr tcr_el2, x0 - /* Set up the SCTLR_EL2: - * Exceptions in LE ARM, - * Low-latency IRQs disabled, - * Write-implies-XN disabled (for now), - * D-cache disabled (for now), - * I-cache enabled, - * Alignment checking disabled, - * MMU translation disabled (for now). */ - ldr x0, =(HSCTLR_BASE) + ldr x0, =SCTLR_EL2_SET msr SCTLR_EL2, x0 /* Ensure that any exceptions encountered at EL2 diff --git a/xen/include/asm-arm/processor.h b/xen/include/asm-arm/processor.h index bbcba061ca..e9d2ae2715 100644 --- a/xen/include/asm-arm/processor.h +++ b/xen/include/asm-arm/processor.h @@ -127,6 +127,9 @@ #define SCTLR_A32_ELx_TE BIT(30, UL) #define SCTLR_A32_ELx_FI BIT(21, UL) +/* Common bits for SCTLR_ELx for Arm64 */ +#define SCTLR_A64_ELx_SA BIT(3, UL) + /* Common bits for SCTLR_ELx on all architectures */ #define SCTLR_Axx_ELx_EE BIT(25, UL) #define SCTLR_Axx_ELx_WXN BIT(19, UL) @@ -135,7 +138,58 @@ #define SCTLR_Axx_ELx_A BIT(1, UL) #define SCTLR_Axx_ELx_M BIT(0, UL) -#define HSCTLR_BASE _AC(0x30c51878,U) +#ifdef CONFIG_ARM_32 + +#define HSCTLR_RES1 (BIT( 3, UL) | BIT( 4, UL) | BIT( 5, UL) |\ + BIT( 6, UL) | BIT(11, UL) | BIT(16, UL) |\ + BIT(18, UL) | BIT(22, UL) | BIT(23, UL) |\ + BIT(28, UL) | BIT(29, UL)) + +#define HSCTLR_RES0 (BIT(7, UL) | BIT(8, UL) | BIT(9, UL) | BIT(10, UL) |\ + BIT(13, UL) | BIT(14, UL) | BIT(15, UL) | BIT(17, UL) |\ + BIT(20, UL) | BIT(24, UL) | BIT(26, UL) | BIT(27, UL) |\ + BIT(31, UL)) + +/* Initial value for HSCTLR */ +#define HSCTLR_SET (HSCTLR_RES1 | SCTLR_Axx_ELx_A | SCTLR_Axx_ELx_I) + +/* Only used a pre-processing time... */ +#define HSCTLR_CLEAR (HSCTLR_RES0 | SCTLR_Axx_ELx_M |\ + SCTLR_Axx_ELx_C | SCTLR_Axx_ELx_WXN |\ + SCTLR_A32_ELx_FI | SCTLR_Axx_ELx_EE |\ + SCTLR_A32_ELx_TE) + +#if (HSCTLR_SET ^ HSCTLR_CLEAR) != 0xffffffffU +#error "Inconsistent HSCTLR set/clear bits" +#endif + +#else + +#define SCTLR_EL2_RES1 (BIT( 4, UL) | BIT( 5, UL) | BIT(11, UL) |\ + BIT(16, UL) | BIT(18, UL) | BIT(22, UL) |\ + BIT(23, UL) | BIT(28, UL) | BIT(29, UL)) + +#define SCTLR_EL2_RES0 (BIT( 6, UL) | BIT( 7, UL) | BIT( 8, UL) |\ + BIT( 9, UL) | BIT(10, UL) | BIT(13, UL) |\ + BIT(14, UL) | BIT(15, UL) | BIT(17, UL) |\ + BIT(20, UL) | BIT(21, UL) | BIT(24, UL) |\ + BIT(26, UL) | BIT(27, UL) | BIT(30, UL) |\ + BIT(31, UL) | (0xffffffffULL << 32)) + +/* Initial value for SCTLR_EL2 */ +#define SCTLR_EL2_SET (SCTLR_EL2_RES1 | SCTLR_A64_ELx_SA |\ + SCTLR_Axx_ELx_I) + +/* Only used a pre-processing time... */ +#define SCTLR_EL2_CLEAR (SCTLR_EL2_RES0 | SCTLR_Axx_ELx_M |\ + SCTLR_Axx_ELx_A | SCTLR_Axx_ELx_C |\ + SCTLR_Axx_ELx_WXN | SCTLR_Axx_ELx_EE) + +#if (SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != 0xffffffffffffffffUL +#error "Inconsistent SCTLR_EL2 set/clear bits" +#endif + +#endif /* HCR Hyp Configuration Register */ #define HCR_RW (_AC(1,UL)<<31) /* Register Width, ARM64 only */ From patchwork Fri Jun 14 17:51:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 166866 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2351188ilk; Fri, 14 Jun 2019 10:53:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqyq/2ltxeEKgdDymJ7Pb6GOG12p285EUahPu0oXV3gMMHClZPUSEpNzFV1ksvp9sF4EcQBT X-Received: by 2002:a02:710f:: with SMTP id n15mr2358547jac.119.1560534809305; Fri, 14 Jun 2019 10:53:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560534809; cv=none; d=google.com; s=arc-20160816; b=Lb7JH0lzN2GFSETCRrRBC/GWkwe0gPVIftnAKDyQCARzcERq9B6VPGMcCNrpXLhCJ9 rwZmdLnVRSP+hFGZ39WSIfZx4KahNczMoV2HswlWgOzm5WOlfutsMvhVm83IxXAAJ/df yuKOp4i3NVHpbzwxdeHmrmJETrA72GjdIZf4/j+qSn/JE2sVm6J+o2fwcqzKrFNOqydI 4REUAnBZUA2aVp2UTmV7cYPatHMkHcsv+sjQ9LjGTBSgG9fpn9UvK1ujx4jY9xQueCCd aJBm1RqyXtfIBLgdEW5CjGyK32GcWo//k6W0XKZCs0yg6GLJeG35krSc3/kWgjh3fgLF SX+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=HYLcYkqpiKKexJCCsOS2Z3CzG0m9BDEYryGleFEV7YA=; b=YpXC5b2kQX+e9obgYmHwv7R8aAeU/5fIL7JlCh7shkGIBv3ErADnal5CVv2+dQaP8J x07McfqIfUOZEbJnsRkn/SGHOg375PWuTiznk28eo+RM+bbhkjkbQbWTDVEvejTXNEvR FzJhkRA4F5LySXNcbaessvpvOhIFXjE8L7fTeDJ2havp6bOSX04BJSd6tN36dV7I24lf SrL8YAn4ImL77e9fuluI46vEujDWFzFFfaCm2DQUKugFgVeWAB2eYrD5TeMrkRkmQWrl acelJHmn4eGfFY34WgCKHotIV8csqKnx1pMcSnEFT5Q4/8JVXsOAXgNMvk7vp2ZlTFat Cw9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id m4si3680972iok.21.2019.06.14.10.53.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Jun 2019 10:53:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hbqMq-0001ow-Ac; Fri, 14 Jun 2019 17:52:00 +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 1hbqMo-0001nJ-EK for xen-devel@lists.xenproject.org; Fri, 14 Jun 2019 17:51:58 +0000 X-Inumbo-ID: 18b281da-8ecd-11e9-806d-bbdfc0d74393 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 18b281da-8ecd-11e9-806d-bbdfc0d74393; Fri, 14 Jun 2019 17:51:54 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 59628346; Fri, 14 Jun 2019 10:51:54 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 713AF3F718; Fri, 14 Jun 2019 10:51:53 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 14 Jun 2019 18:51:37 +0100 Message-Id: <20190614175144.20046-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190614175144.20046-1-julien.grall@arm.com> References: <20190614175144.20046-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v3 2/9] xen/arm: mm: Introduce _PAGE_PRESENT and _PAGE_POPULATE 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , Stefano Stabellini , Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, the flags are not enough to describe what kind of update will done on the VA range. They need to be used in conjunction with the enum xenmap_operation. It would be more convenient to have all the information for the update in a single place. Two new flags are added to remove the relience on xenmap_operation: - _PAGE_PRESENT: Indicate whether we are adding/removing the mapping - _PAGE_POPULATE: Indicate whether we only populate page-tables Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Reviewed-by: Stefano Stabellini --- Changes in v3: - Clarify the description of the new flags Changes in v2: - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 2 +- xen/include/asm-arm/page.h | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 23e9565ddc..b13d9adf40 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1056,7 +1056,7 @@ int map_pages_to_xen(unsigned long virt, int populate_pt_range(unsigned long virt, unsigned long nr_mfns) { - return xen_pt_update(RESERVE, virt, INVALID_MFN, nr_mfns, 0); + return xen_pt_update(RESERVE, virt, INVALID_MFN, nr_mfns, _PAGE_POPULATE); } int destroy_xen_mappings(unsigned long v, unsigned long e) diff --git a/xen/include/asm-arm/page.h b/xen/include/asm-arm/page.h index 2bcdb0f1a5..37e1d9aadb 100644 --- a/xen/include/asm-arm/page.h +++ b/xen/include/asm-arm/page.h @@ -76,6 +76,8 @@ * * [0:2] Memory Attribute Index * [3:4] Permission flags + * [5] Page present + * [6] Only populate page tables */ #define PAGE_AI_MASK(x) ((x) & 0x7U) @@ -86,12 +88,15 @@ #define PAGE_XN_MASK(x) (((x) >> _PAGE_XN_BIT) & 0x1U) #define PAGE_RO_MASK(x) (((x) >> _PAGE_RO_BIT) & 0x1U) +#define _PAGE_PRESENT (1U << 5) +#define _PAGE_POPULATE (1U << 6) + /* * _PAGE_DEVICE and _PAGE_NORMAL are convenience defines. They are not * meant to be used outside of this header. */ -#define _PAGE_DEVICE _PAGE_XN -#define _PAGE_NORMAL MT_NORMAL +#define _PAGE_DEVICE (_PAGE_XN|_PAGE_PRESENT) +#define _PAGE_NORMAL (MT_NORMAL|_PAGE_PRESENT) #define PAGE_HYPERVISOR_RO (_PAGE_NORMAL|_PAGE_RO|_PAGE_XN) #define PAGE_HYPERVISOR_RX (_PAGE_NORMAL|_PAGE_RO) From patchwork Fri Jun 14 17:51:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 166870 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2351255ilk; Fri, 14 Jun 2019 10:53:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzXDiRHjq/P/5qVnTSejOv9X9iLaYeqHW5lMtwefK+sWlAT7BgflwJzgBszD60qMPz6wNY X-Received: by 2002:a02:a90a:: with SMTP id n10mr53577752jam.61.1560534812194; Fri, 14 Jun 2019 10:53:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560534812; cv=none; d=google.com; s=arc-20160816; b=yVqebnXXccH84bebFjcitQak8cVGHN3goY/9MPEsuEaEaEb0/WCbcfwO7U/TaLUI4s VTD/j289Q75TWoM7ctvxm4oH9ErXsG/PbgbaIKQAHJ7Y58o9ygSmUnsa/wQB/NvF3QPz eU20bSQi6DczMGxjGawm7TunjPIRU+K3CyGFket+gdUe+a7+394sZZhAl+sWOxzsrWSi I5b8tVEyE0QLTIjJaIfoAl5JcYZXRX1dSvHvjf1f6ckkM4S8eqq53VCrVGbWW01pWsxI KIagCilOiSDRkNhSZvmoHBvVX13tloirw3GIkFWvnBkHO/qM4A6wpAzeuS0ULnGHn9GW 7ypw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=jdpVZmVWQv0dglxKluP7KkrBSiyRCb1yf1g1wN+atyE=; b=Lw7bDwuWQb3KeuhD799xowE8q3YdUkZqXE4ID0lkm4NNs6gIxhTDTNCt8vcf6gmBRk Ds9nll/4QZNqEMGKMwgqeSYj5uIuhbTKqymMXJhCEp95a0d63JazqHUJwZVwdLaIr4RQ mdEICx9aOsmz4ZAPHJgZpyfCDwzi/aaI65GP2AxpO47ci9eMHULcpbliZI4/c2pEpWTb JdAc1bLfrlC6U/34yPLW68OnIEqARPuL4zrCMDPmmVQOPRA5VeL/3GFpPBGMew9ZpHhU qJIUpTggplBqi9hGx3oTyYKPg19kp17NWIXGIH8Id3FOI1oGghcFyTBuRYtr7KImrfg+ b/5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id q8si4069982iob.45.2019.06.14.10.53.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Jun 2019 10:53:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hbqMr-0001pH-0V; Fri, 14 Jun 2019 17:52:01 +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 1hbqMo-0001nI-EA for xen-devel@lists.xenproject.org; Fri, 14 Jun 2019 17:51:58 +0000 X-Inumbo-ID: 1953a0f6-8ecd-11e9-939b-63e2fa18f954 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 1953a0f6-8ecd-11e9-939b-63e2fa18f954; Fri, 14 Jun 2019 17:51:55 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 75A492B; Fri, 14 Jun 2019 10:51:55 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8DB523F718; Fri, 14 Jun 2019 10:51:54 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 14 Jun 2019 18:51:38 +0100 Message-Id: <20190614175144.20046-4-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190614175144.20046-1-julien.grall@arm.com> References: <20190614175144.20046-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v3 3/9] xen/arm: mm: Sanity check any update of Xen page tables 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , Stefano Stabellini , Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The code handling Xen PT update has quite a few restrictions on what it can do. This is not a bad thing as it keeps the code simple. There are already a few checks scattered in current page table handling. However they are not sufficient as they could still allow to modify/remove entry with contiguous bit set. The checks are divided in two sets: - per entry check: They are gathered in a new function that will check whether an update is valid based on the flags passed and the current value of an entry. - global check: They are sanity check on xen_pt_update() parameters. Additionally to contiguous check, we also now check that the caller is not trying to modify the memory attributes of an entry. Lastly, it was probably a bit over the top to forbid removing an invalid mapping. This could just be ignored. The new behavior will be helpful in future changes. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Reviewed-by: Stefano Stabellini --- Changes in v3: - Only allow modification on valid entry Changes in v2: - Correctly detect the removal of a page - Fix ASSERT on flags in the else case - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 104 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index b13d9adf40..dcf041578b 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -50,6 +50,19 @@ #undef mfn_to_virt #define mfn_to_virt(mfn) __mfn_to_virt(mfn_x(mfn)) +#ifdef NDEBUG +static inline void +__attribute__ ((__format__ (__printf__, 1, 2))) +mm_printk(const char *fmt, ...) {} +#else +#define mm_printk(fmt, args...) \ + do \ + { \ + dprintk(XENLOG_ERR, fmt, ## args); \ + WARN(); \ + } while (0); +#endif + #define DEFINE_PAGE_TABLES(name, nr) \ lpae_t __aligned(PAGE_SIZE) name[LPAE_ENTRIES * (nr)] @@ -941,12 +954,81 @@ enum xenmap_operation { RESERVE }; +/* Sanity check of the entry */ +static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) +{ + /* Sanity check when modifying a page. */ + if ( (flags & _PAGE_PRESENT) && mfn_eq(mfn, INVALID_MFN) ) + { + /* We don't allow modifying an invalid entry. */ + if ( !lpae_is_valid(entry) ) + { + mm_printk("Modifying invalid entry is not allowed.\n"); + return false; + } + + /* We don't allow changing memory attributes. */ + if ( entry.pt.ai != PAGE_AI_MASK(flags) ) + { + mm_printk("Modifying memory attributes is not allowed (0x%x -> 0x%x).\n", + entry.pt.ai, PAGE_AI_MASK(flags)); + return false; + } + + /* We don't allow modifying entry with contiguous bit set. */ + if ( entry.pt.contig ) + { + mm_printk("Modifying entry with contiguous bit set is not allowed.\n"); + return false; + } + } + /* Sanity check when inserting a page */ + else if ( flags & _PAGE_PRESENT ) + { + /* We should be here with a valid MFN. */ + ASSERT(!mfn_eq(mfn, INVALID_MFN)); + + /* We don't allow replacing any valid entry. */ + if ( lpae_is_valid(entry) ) + { + mm_printk("Changing MFN for a valid entry is not allowed (%#"PRI_mfn" -> %#"PRI_mfn").\n", + mfn_x(lpae_get_mfn(entry)), mfn_x(mfn)); + return false; + } + } + /* Sanity check when removing a page. */ + else if ( (flags & (_PAGE_PRESENT|_PAGE_POPULATE)) == 0 ) + { + /* We should be here with an invalid MFN. */ + ASSERT(mfn_eq(mfn, INVALID_MFN)); + + /* We don't allow removing page with contiguous bit set. */ + if ( entry.pt.contig ) + { + mm_printk("Removing entry with contiguous bit set is not allowed.\n"); + return false; + } + } + /* Sanity check when populating the page-table. No check so far. */ + else + { + ASSERT(flags & _PAGE_POPULATE); + /* We should be here with an invalid MFN */ + ASSERT(mfn_eq(mfn, INVALID_MFN)); + } + + return true; +} + static int xen_pt_update_entry(enum xenmap_operation op, unsigned long addr, mfn_t mfn, unsigned int flags) { lpae_t pte, *entry; lpae_t *third = NULL; + /* _PAGE_POPULATE and _PAGE_PRESENT should never be set together. */ + ASSERT((flags & (_PAGE_POPULATE|_PAGE_PRESENT)) != (_PAGE_POPULATE|_PAGE_PRESENT)); + entry = &xen_second[second_linear_offset(addr)]; if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) ) { @@ -962,15 +1044,12 @@ static int xen_pt_update_entry(enum xenmap_operation op, unsigned long addr, third = mfn_to_virt(lpae_get_mfn(*entry)); entry = &third[third_table_offset(addr)]; + if ( !xen_pt_check_entry(*entry, mfn, flags) ) + return -EINVAL; + switch ( op ) { case INSERT: case RESERVE: - if ( lpae_is_valid(*entry) ) - { - printk("%s: trying to replace an existing mapping addr=%lx mfn=%"PRI_mfn"\n", - __func__, addr, mfn_x(mfn)); - return -EINVAL; - } if ( op == RESERVE ) break; pte = mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags)); @@ -982,12 +1061,6 @@ static int xen_pt_update_entry(enum xenmap_operation op, unsigned long addr, break; case MODIFY: case REMOVE: - if ( !lpae_is_valid(*entry) ) - { - printk("%s: trying to %s a non-existing mapping addr=%lx\n", - __func__, op == REMOVE ? "remove" : "modify", addr); - return -EINVAL; - } if ( op == REMOVE ) pte.bits = 0; else @@ -995,12 +1068,6 @@ static int xen_pt_update_entry(enum xenmap_operation op, unsigned long addr, pte = *entry; pte.pt.ro = PAGE_RO_MASK(flags); pte.pt.xn = PAGE_XN_MASK(flags); - if ( !pte.pt.ro && !pte.pt.xn ) - { - printk("%s: Incorrect combination for addr=%lx\n", - __func__, addr); - return -EINVAL; - } } write_pte(entry, pte); break; @@ -1022,6 +1089,25 @@ static int xen_pt_update(enum xenmap_operation op, int rc = 0; unsigned long addr = virt, addr_end = addr + nr_mfns * PAGE_SIZE; + /* + * The hardware was configured to forbid mapping both writeable and + * executable. + * When modifying/creating mapping (i.e _PAGE_PRESENT is set), + * prevent any update if this happen. + */ + if ( (flags & _PAGE_PRESENT) && !PAGE_RO_MASK(flags) && + !PAGE_XN_MASK(flags) ) + { + mm_printk("Mappings should not be both Writeable and Executable.\n"); + return -EINVAL; + } + + if ( !IS_ALIGNED(virt, PAGE_SIZE) ) + { + mm_printk("The virtual address is not aligned to the page-size.\n"); + return -EINVAL; + } + spin_lock(&xen_pt_lock); for( ; addr < addr_end; addr += PAGE_SIZE ) From patchwork Fri Jun 14 17:51:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 166873 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2351267ilk; Fri, 14 Jun 2019 10:53:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFJwEcsO4Ewu/iSeJ8/5golDI9UikyLZvirzNmTRJj1wF0mCsP4MUdb//v46lD8sZ9ur/k X-Received: by 2002:a02:b798:: with SMTP id f24mr65693943jam.97.1560534812500; Fri, 14 Jun 2019 10:53:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560534812; cv=none; d=google.com; s=arc-20160816; b=VQxt/M8fbK2U/sgs+ue3v3L3swC2fO4B1FStR2+8ebstyInmntjZ1kBS5lrJ3tpR8i NF/JTrMo9xYNJZChhW+rLweZxV+F4ayR9Lo0IN3lpSc/aEFIj/PuZd2pxryCQyVEesw1 jP6lQQ2YEPnxbyM+2zXxlPOQfdjgALNBt8pW1BcxB6czP+PMbjlr5hQVGV3OVYkqKFOC x6iaIxSk6iriI2YZ0Xd/wgdwoGeDAaAxPZA3Up4GCR8Z4RhOH2MxINK5BA5C4dR+8v94 U/3SkWfGcll2FE9TfIzAZdvYydGj8owH+pAA3jNIBJGT/309pNBMmJtwTedDHWoVRSOr 7qNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=1kXkSf/vh2dq+0XkIAgAaTpHwRwzHitb95Vu2KlD+Fs=; b=DOeSY6pXPLwIIGqF6J+7qdcUdNf35NsAoCqEP/ed5XGKEkgj/QkKCDdDYZi9GrxCWF JoGzZ/HtA3tcNqilk3iGwqUcH03W7ukxMfJgKSMPWIzC0tIMk2/CQIA1j2TgOU+lckm9 7ZioTP7ecjrwy2vYJL1UDeCvhpqE9soHXxoRA7WJRw268bCj6+f1/JFGS4TmZgoJ/BIs +wwXkCGCQjAQPiZmfC/wIvdTdSbRX7HDsp/AEqgLmhuwHqrMWdCO5d2iF6vpyG7LU2YC TVBTAKPM22+h/VJSDgUOqhW8/e/83WoJfu7GM8OWfqnQpANsdN38s634AaYeblCfV1yh ZRqg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id s6si3921720iot.110.2019.06.14.10.53.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Jun 2019 10:53:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hbqMq-0001oo-0Z; Fri, 14 Jun 2019 17:52:00 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hbqMo-0001nG-6z for xen-devel@lists.xenproject.org; Fri, 14 Jun 2019 17:51:58 +0000 X-Inumbo-ID: 19fa9a05-8ecd-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 19fa9a05-8ecd-11e9-8980-bc764e045a96; Fri, 14 Jun 2019 17:51:56 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 92969367; Fri, 14 Jun 2019 10:51:56 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AA3023F718; Fri, 14 Jun 2019 10:51:55 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 14 Jun 2019 18:51:39 +0100 Message-Id: <20190614175144.20046-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190614175144.20046-1-julien.grall@arm.com> References: <20190614175144.20046-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v3 4/9] xen/arm: mm: Rework xen_pt_update_entry to avoid use xenmap_operation 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , Stefano Stabellini , Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" With the newly introduced flags, it is now possible to know how the page will be updated through the flags. All the use of xenmap_operation are now replaced with the flags. At the same time, validity check are now removed as they are gathered in xen_pt_check_entry(). Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Reviewed-by: Stefano Stabellini --- Changes in v3: - Add Stefano's reviewed-by Changes in v2: - Fix typo in the commit message - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index dcf041578b..b2b8bd3dc6 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1047,34 +1047,33 @@ static int xen_pt_update_entry(enum xenmap_operation op, unsigned long addr, if ( !xen_pt_check_entry(*entry, mfn, flags) ) return -EINVAL; - switch ( op ) { - case INSERT: - case RESERVE: - if ( op == RESERVE ) - break; + /* If we are only populating page-table, then we are done. */ + if ( flags & _PAGE_POPULATE ) + return 0; + + /* We are removing the page */ + if ( !(flags & _PAGE_PRESENT) ) + memset(&pte, 0x00, sizeof(pte)); + else + { + /* We are inserting a mapping => Create new pte. */ + if ( !mfn_eq(mfn, INVALID_MFN) ) + { pte = mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags)); - pte.pt.ro = PAGE_RO_MASK(flags); - pte.pt.xn = PAGE_XN_MASK(flags); - BUG_ON(!pte.pt.ro && !pte.pt.xn); + + /* Third level entries set pte.pt.table = 1 */ pte.pt.table = 1; - write_pte(entry, pte); - break; - case MODIFY: - case REMOVE: - if ( op == REMOVE ) - pte.bits = 0; - else - { - pte = *entry; - pte.pt.ro = PAGE_RO_MASK(flags); - pte.pt.xn = PAGE_XN_MASK(flags); - } - write_pte(entry, pte); - break; - default: - BUG(); + } + else /* We are updating the permission => Copy the current pte. */ + pte = *entry; + + /* Set permission */ + pte.pt.ro = PAGE_RO_MASK(flags); + pte.pt.xn = PAGE_XN_MASK(flags); } + write_pte(entry, pte); + return 0; } From patchwork Fri Jun 14 17:51:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 166864 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2351155ilk; Fri, 14 Jun 2019 10:53:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqzxxnb/rlic4pRwBo7IF4YimIzEv5E1ew62ioAjAiJd+hn6BI0e/93e4qqI0pQDjgKJfnbN X-Received: by 2002:a6b:6a01:: with SMTP id x1mr9360270iog.77.1560534807672; Fri, 14 Jun 2019 10:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560534807; cv=none; d=google.com; s=arc-20160816; b=iXZAasx8aCk/QMUUBWLXPnLV9EvCsFfu0XUOIJ+nbS1urr5SWFzzIvuFc5gPlRlOyv tzzDA9J3Kxpjm3T+UQ5ETg3ZjX4ujWsLjniT8laEKD8AUM1MBWjfxh296GiynHVOamHC vJ0EJcTd+EqSsU+r8DF0Q5L+F3kIlWUR4iy3ldV6w2eF/n/0y77bGhCFBYTrbRILli9n eWjd2/EweWBRbEnZvCRyTwyCgQWzzJONENzAvl1TVTvKBl0nC5luEAnwl8km8lQyCwd/ TmyLIUiSv6tW7PdceBuAVQqaI4mvgE4lmbHYa0sZs68fuS/+q/MPBRP0EvXlavA/+OVW oIcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=TLbVBiRxpCACXFWErrzlEPAd6dkqHtjfmcGCqfhjWSA=; b=j3tFDogsfZVE8t1EyBhR+UBvoVbBYcFDJuo3iD1097oDMYbYDNgcTiKmcEtvGOq0I2 lYijuTGV7ldWSQ/Td6qrrXeyrF31J5lSDa4LMzErLQZ7w/FjX0qvP1LmDCZWWcNnFj31 K43WrFXW7Y9jN8E2QAzqWT90IOveEb5A0MFxbr8CzCoexdQSIAebpqLF4cJJ/8xIwwlS Pt5b8HU1o/q3hX1/HAe5HF/CURXAAgS2NpIebefYuB01xdMfeAWbiaAaYuKkAlZae92P KTThNKjiw0v2e5Cj73Smh8f/DGJGgDEJ6MTwgGLVoIrtamxovmsCm3RNugCC8AFSbw/S Loxw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id g21si3853188ion.115.2019.06.14.10.53.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Jun 2019 10:53:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hbqMr-0001pa-HP; Fri, 14 Jun 2019 17:52:01 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hbqMp-0001oQ-GI for xen-devel@lists.xenproject.org; Fri, 14 Jun 2019 17:51:59 +0000 X-Inumbo-ID: 1ab88dd2-8ecd-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 1ab88dd2-8ecd-11e9-8980-bc764e045a96; Fri, 14 Jun 2019 17:51:57 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AF6D6344; Fri, 14 Jun 2019 10:51:57 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C75443F718; Fri, 14 Jun 2019 10:51:56 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 14 Jun 2019 18:51:40 +0100 Message-Id: <20190614175144.20046-6-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190614175144.20046-1-julien.grall@arm.com> References: <20190614175144.20046-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v3 5/9] xen/arm: mm: Remove enum xenmap_operation 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , Stefano Stabellini , Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The enum xenmap_operation is not used anymore. So remove it. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Acked-by: Stefano Stabellini --- Changes in v3: - Add Stefano's acked-by Changes in v2: - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index b2b8bd3dc6..3f6d0e29d5 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -947,13 +947,6 @@ static int create_xen_table(lpae_t *entry) return 0; } -enum xenmap_operation { - INSERT, - REMOVE, - MODIFY, - RESERVE -}; - /* Sanity check of the entry */ static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) { @@ -1020,8 +1013,8 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) return true; } -static int xen_pt_update_entry(enum xenmap_operation op, unsigned long addr, - mfn_t mfn, unsigned int flags) +static int xen_pt_update_entry(unsigned long addr, mfn_t mfn, + unsigned int flags) { lpae_t pte, *entry; lpae_t *third = NULL; @@ -1079,8 +1072,7 @@ static int xen_pt_update_entry(enum xenmap_operation op, unsigned long addr, static DEFINE_SPINLOCK(xen_pt_lock); -static int xen_pt_update(enum xenmap_operation op, - unsigned long virt, +static int xen_pt_update(unsigned long virt, mfn_t mfn, unsigned long nr_mfns, unsigned int flags) @@ -1111,7 +1103,7 @@ static int xen_pt_update(enum xenmap_operation op, for( ; addr < addr_end; addr += PAGE_SIZE ) { - rc = xen_pt_update_entry(op, addr, mfn, flags); + rc = xen_pt_update_entry(addr, mfn, flags); if ( rc ) break; @@ -1136,24 +1128,24 @@ int map_pages_to_xen(unsigned long virt, unsigned long nr_mfns, unsigned int flags) { - return xen_pt_update(INSERT, virt, mfn, nr_mfns, flags); + return xen_pt_update(virt, mfn, nr_mfns, flags); } int populate_pt_range(unsigned long virt, unsigned long nr_mfns) { - return xen_pt_update(RESERVE, virt, INVALID_MFN, nr_mfns, _PAGE_POPULATE); + return xen_pt_update(virt, INVALID_MFN, nr_mfns, _PAGE_POPULATE); } int destroy_xen_mappings(unsigned long v, unsigned long e) { ASSERT(v <= e); - return xen_pt_update(REMOVE, v, INVALID_MFN, (e - v) >> PAGE_SHIFT, 0); + return xen_pt_update(v, INVALID_MFN, (e - v) >> PAGE_SHIFT, 0); } int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int flags) { ASSERT(s <= e); - return xen_pt_update(MODIFY, s, INVALID_MFN, (e - s) >> PAGE_SHIFT, flags); + return xen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, flags); } enum mg { mg_clear, mg_ro, mg_rw, mg_rx }; From patchwork Fri Jun 14 17:51:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 166867 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2351225ilk; Fri, 14 Jun 2019 10:53:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTJrm/ArQ+yYmobBvRXLzPdFl+AehNddpME/Mb0CAeUgG5gGV6rV7gbHl7ynxE4NGkX1CP X-Received: by 2002:a6b:4107:: with SMTP id n7mr4232696ioa.12.1560534810614; Fri, 14 Jun 2019 10:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560534810; cv=none; d=google.com; s=arc-20160816; b=T6HV9i9+c4QjBua48dF9HSzshCba/XLd8OVJOSHTGfJ5a8gWyn8J6pfrYlxAmmvXIV zJkbYC/apTTrtaB4mgAuB0SnPKKeePUK4VLb/migPq6J8b2JF5KLz42HtRwHnO9KIVHb BaAUMmIatuQLbm0XaVQ7B2aVWTkM9yWyQb8V/JQ1/Mzge0ByXSULOM+j9vzs1W4dnOOR Ph15ifsFlhMOSlulXzjyDpdAByXFzPtKGSMYBCbXBz87yCPduW5QskXdgBjOrT9GgJLp qaQxtbIRPyHbdt+s6ICfvi9H6YBywD2pnP05GmKE9xR11hwnuymmYnpjqp0GNS8s/UVc E//A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=6I6oLvgAH33N4xLc0KBuDXtK8crW9qnBmFRQ96NfwLI=; b=OrlvqdvfGfVssjzOTEb1fDvgCVA0OM+lipDg5hHEQwWJPLx5WhJIQn7SBm7M0TkeQC dPN09mWoJucKBjixKOB8uT8Gd52gpkq0SwlbO0MTrgVVgd2Dajuc0jsGDWk8zVFrYPLM jWesOj7/+gAT6W1hKAIq/ERI7JMd9sQkiYkbQ+nea4b6w/Cv5LePHK5D0pfMQ+ZZxWe6 VACe0skv9JLtFzyvPR/xbcPEJ46kYvOEl4AziE0IA6ePwvYf/o9/zvZDTqtD4t6utyBz RjS/K27Qt21BG3CJt6dyUAL6d+Y9GClkkg+JGNqav8RhuT5toNmY48UXZBE1WXBv2Dy3 pqxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id b79si4055304iof.13.2019.06.14.10.53.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Jun 2019 10:53:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hbqMr-0001ps-Up; Fri, 14 Jun 2019 17:52:01 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hbqMp-0001ob-Oj for xen-devel@lists.xenproject.org; Fri, 14 Jun 2019 17:51:59 +0000 X-Inumbo-ID: 1b4d369a-8ecd-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 1b4d369a-8ecd-11e9-8980-bc764e045a96; Fri, 14 Jun 2019 17:51:58 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CC1D0346; Fri, 14 Jun 2019 10:51:58 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E41BF3F718; Fri, 14 Jun 2019 10:51:57 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 14 Jun 2019 18:51:41 +0100 Message-Id: <20190614175144.20046-7-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190614175144.20046-1-julien.grall@arm.com> References: <20190614175144.20046-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v3 6/9] xen/arm: mm: Use {, un}map_domain_page() to map/unmap Xen page-tables 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , Stefano Stabellini , Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Currently, the virtual address of the 3rd level page-tables is obtained using mfn_to_virt(). On Arm32, mfn_to_virt can only work on xenheap page. While in theory all the page-tables updated will reside in xenheap, in practice the page-tables covering Xen memory (e.g xen_mapping) is part of Xen binary. Furthermore, a follow-up change will update xen_pt_update_entry() to walk all the levels and therefore be more generic. Some of the page-tables will also part of Xen memory and therefore will not be reachable using mfn_to_virt(). The easiest way to reach those pages is to use {, un}map_domain_page(). While on arm32 this means an extra mapping in the normal cases, this is not very important as xen page-tables are not updated often. In order to allow future change in the way Xen page-tables are mapped, two new helpers are introduced to map/unmap the page-tables. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Acked-by: Stefano Stabellini --- Changes in v3: - Fix typo in the commit message - Add Stefano's acked-by Changes in v2: - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 3f6d0e29d5..c3dd2c08ba 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -947,6 +947,16 @@ static int create_xen_table(lpae_t *entry) return 0; } +static lpae_t *xen_map_table(mfn_t mfn) +{ + return map_domain_page(mfn); +} + +static void xen_unmap_table(const lpae_t *table) +{ + unmap_domain_page(table); +} + /* Sanity check of the entry */ static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) { @@ -1016,6 +1026,7 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) static int xen_pt_update_entry(unsigned long addr, mfn_t mfn, unsigned int flags) { + int rc; lpae_t pte, *entry; lpae_t *third = NULL; @@ -1034,15 +1045,17 @@ static int xen_pt_update_entry(unsigned long addr, mfn_t mfn, BUG_ON(!lpae_is_valid(*entry)); - third = mfn_to_virt(lpae_get_mfn(*entry)); + third = xen_map_table(lpae_get_mfn(*entry)); entry = &third[third_table_offset(addr)]; + rc = -EINVAL; if ( !xen_pt_check_entry(*entry, mfn, flags) ) - return -EINVAL; + goto out; /* If we are only populating page-table, then we are done. */ + rc = 0; if ( flags & _PAGE_POPULATE ) - return 0; + goto out; /* We are removing the page */ if ( !(flags & _PAGE_PRESENT) ) @@ -1067,7 +1080,12 @@ static int xen_pt_update_entry(unsigned long addr, mfn_t mfn, write_pte(entry, pte); - return 0; + rc = 0; + +out: + xen_unmap_table(third); + + return rc; } static DEFINE_SPINLOCK(xen_pt_lock); From patchwork Fri Jun 14 17:51:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 166869 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2351246ilk; Fri, 14 Jun 2019 10:53:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqweeqjHUmcPLp4x0JptE/E+Y7bJKqbbwCIWSyYDCb1kKQsWwivmKqstJo5S5chkjyOv/s51 X-Received: by 2002:a05:6602:2248:: with SMTP id o8mr18650389ioo.90.1560534811799; Fri, 14 Jun 2019 10:53:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560534811; cv=none; d=google.com; s=arc-20160816; b=tLM52yogZNY0OQdksI1CQ7kEFz+sMuzcykBIXxraldDZBsOkNZE2WH6TfsV9EF5eMZ 9FA2O89i4sAjPAeSQHzwgEop8uQJikPIR9t/9FceIMe6UvDrZ2aXkeUGJbJjkORZtWm6 P396yVl11PQsbr9zmD1l/SYwMb4hsH1NkluATx4V4rPuNe4MdoedCuN6TIymW3aq/zY+ NYtWV0g6YM3+Qsb4XKzyz35XNHLe1cnHhMp4e3I43MSdDKqENKj0gl0EtciZdZbTWp/4 aiULQ1nUVCtm6W5c6fQNzd3j9Lrndd8ZiitwX1lh7N3AGqkWJcPHGh8Ot2X+XI05kJUt uV1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=+0vFTbJdPHjly1Z7RnfvhN2UGJ201XvrJu1lZbYgJBo=; b=0CO8wr5t8N/wTe7FxbbN2NSTJlU8gFDtaxZhq6CVyb0upB+XTNGudbwjHeToWLeCJT sRjS8N7qTWIXcQqLa60lJOvikDTQBUh4qiw7pvbpnJX7oIHuoRaYbVaUYLWME2NpLEAk 0XCtQH7q3ljbykTIVcmwgqZ9U2ijnNnlie8u8zlmlFXvuOuGjOpELmIYJhumtKvBGCvB zT7tuPHjLIjwK+owRfXbi59/hxK5TnvPMBYOUopVy3i00wen80rFJe9RDGUDxwpVnwcr +yqE0MpPnfbOqgxRD0KM95KQDfU2m4N3KBZouPdoBPz6EDNz1kQtJ9rkPzqmujM7+OeT cttQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 73si3852984iou.65.2019.06.14.10.53.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Jun 2019 10:53:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hbqMx-0001v4-6E; Fri, 14 Jun 2019 17:52:07 +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 1hbqMv-0001uG-O5 for xen-devel@lists.xenproject.org; Fri, 14 Jun 2019 17:52:05 +0000 X-Inumbo-ID: 1c0310ca-8ecd-11e9-8bda-e7d4a65d852c Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 1c0310ca-8ecd-11e9-8bda-e7d4a65d852c; Fri, 14 Jun 2019 17:52:00 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E8DC63EF; Fri, 14 Jun 2019 10:51:59 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0CC423F718; Fri, 14 Jun 2019 10:51:58 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 14 Jun 2019 18:51:42 +0100 Message-Id: <20190614175144.20046-8-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190614175144.20046-1-julien.grall@arm.com> References: <20190614175144.20046-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v3 7/9] xen/arm: mm: Rework Xen page-tables walk during update 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , Stefano Stabellini , Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Currently, xen_pt_update_entry() is only able to update the region covered by xen_second (i.e 0 to 0x7fffffff). Because of the restriction we end to have multiple functions in mm.c modifying the page-tables differently. Furthermore, we never walked the page-tables fully. This means that any change in the layout may requires major rewrite of the page-tables code. Lastly, we have been quite lucky that no one ever tried to pass an address outside this range because it would have blown-up. xen_pt_update_entry() is reworked to walk over the page-tables every time. The logic has been borrowed from arch/arm/p2m.c and contain some limitations for the time being: - Superpage cannot be shattered - Only level 3 (i.e 4KB) can be done Note that the parameter 'addr' has been renamed to 'virt' to make clear we are dealing with a virtual address. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Acked-by: Stefano Stabellini --- Changes in v3: - Remove an ASSERT() - Add Stefano's acked-by Changes in v2: - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 104 insertions(+), 15 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index c3dd2c08ba..028fbd38ad 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -957,6 +957,51 @@ static void xen_unmap_table(const lpae_t *table) unmap_domain_page(table); } +#define XEN_TABLE_MAP_FAILED 0 +#define XEN_TABLE_SUPER_PAGE 1 +#define XEN_TABLE_NORMAL_PAGE 2 + +/* + * Take the currently mapped table, find the corresponding entry, + * and map the next table, if available. + * + * The read_only parameters indicates whether intermediate tables should + * be allocated when not present. + * + * Return values: + * XEN_TABLE_MAP_FAILED: Either read_only was set and the entry + * was empty, or allocating a new page failed. + * XEN_TABLE_NORMAL_PAGE: next level mapped normally + * XEN_TABLE_SUPER_PAGE: The next entry points to a superpage. + */ +static int xen_pt_next_level(bool read_only, unsigned int level, + lpae_t **table, unsigned int offset) +{ + lpae_t *entry; + int ret; + + entry = *table + offset; + + if ( !lpae_is_valid(*entry) ) + { + if ( read_only ) + return XEN_TABLE_MAP_FAILED; + + ret = create_xen_table(entry); + if ( ret ) + return XEN_TABLE_MAP_FAILED; + } + + /* The function xen_pt_next_level is never called at the 3rd level */ + if ( lpae_is_mapping(*entry, level) ) + return XEN_TABLE_SUPER_PAGE; + + xen_unmap_table(*table); + *table = xen_map_table(lpae_get_mfn(*entry)); + + return XEN_TABLE_NORMAL_PAGE; +} + /* Sanity check of the entry */ static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) { @@ -1023,30 +1068,65 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) return true; } -static int xen_pt_update_entry(unsigned long addr, mfn_t mfn, - unsigned int flags) +static int xen_pt_update_entry(mfn_t root, unsigned long virt, + mfn_t mfn, unsigned int flags) { int rc; + unsigned int level; + /* We only support 4KB mapping (i.e level 3) for now */ + unsigned int target = 3; + lpae_t *table; + /* + * The intermediate page tables are read-only when the MFN is not valid + * and we are not populating page table. + * This means we either modify permissions or remove an entry. + */ + bool read_only = mfn_eq(mfn, INVALID_MFN) && !(flags & _PAGE_POPULATE); lpae_t pte, *entry; - lpae_t *third = NULL; + + /* convenience aliases */ + DECLARE_OFFSETS(offsets, (paddr_t)virt); /* _PAGE_POPULATE and _PAGE_PRESENT should never be set together. */ ASSERT((flags & (_PAGE_POPULATE|_PAGE_PRESENT)) != (_PAGE_POPULATE|_PAGE_PRESENT)); - entry = &xen_second[second_linear_offset(addr)]; - if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) ) + table = xen_map_table(root); + for ( level = HYP_PT_ROOT_LEVEL; level < target; level++ ) { - int rc = create_xen_table(entry); - if ( rc < 0 ) { - printk("%s: L2 failed\n", __func__); - return rc; + rc = xen_pt_next_level(read_only, level, &table, offsets[level]); + if ( rc == XEN_TABLE_MAP_FAILED ) + { + /* + * We are here because xen_pt_next_level has failed to map + * the intermediate page table (e.g the table does not exist + * and the pt is read-only). It is a valid case when + * removing a mapping as it may not exist in the page table. + * In this case, just ignore it. + */ + if ( flags & (_PAGE_PRESENT|_PAGE_POPULATE) ) + { + mm_printk("%s: Unable to map level %u\n", __func__, level); + rc = -ENOENT; + goto out; + } + else + { + rc = 0; + goto out; + } } + else if ( rc != XEN_TABLE_NORMAL_PAGE ) + break; } - BUG_ON(!lpae_is_valid(*entry)); + if ( level != target ) + { + mm_printk("%s: Shattering superpage is not supported\n", __func__); + rc = -EOPNOTSUPP; + goto out; + } - third = xen_map_table(lpae_get_mfn(*entry)); - entry = &third[third_table_offset(addr)]; + entry = table + offsets[level]; rc = -EINVAL; if ( !xen_pt_check_entry(*entry, mfn, flags) ) @@ -1083,7 +1163,7 @@ static int xen_pt_update_entry(unsigned long addr, mfn_t mfn, rc = 0; out: - xen_unmap_table(third); + xen_unmap_table(table); return rc; } @@ -1099,6 +1179,15 @@ static int xen_pt_update(unsigned long virt, unsigned long addr = virt, addr_end = addr + nr_mfns * PAGE_SIZE; /* + * For arm32, page-tables are different on each CPUs. Yet, they share + * some common mappings. It is assumed that only common mappings + * will be modified with this function. + * + * XXX: Add a check. + */ + const mfn_t root = virt_to_mfn(THIS_CPU_PGTABLE); + + /* * The hardware was configured to forbid mapping both writeable and * executable. * When modifying/creating mapping (i.e _PAGE_PRESENT is set), @@ -1119,9 +1208,9 @@ static int xen_pt_update(unsigned long virt, spin_lock(&xen_pt_lock); - for( ; addr < addr_end; addr += PAGE_SIZE ) + for ( ; addr < addr_end; addr += PAGE_SIZE ) { - rc = xen_pt_update_entry(addr, mfn, flags); + rc = xen_pt_update_entry(root, addr, mfn, flags); if ( rc ) break; From patchwork Fri Jun 14 17:51:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 166868 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2351236ilk; Fri, 14 Jun 2019 10:53:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzD1S1a1+OI8erOLzMpA2mxhq/JLxbV25zaqwCVFRYb2SNOi2KJToCMRBhK2Ke52CsZsfv5 X-Received: by 2002:a02:3308:: with SMTP id c8mr775jae.103.1560534811348; Fri, 14 Jun 2019 10:53:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560534811; cv=none; d=google.com; s=arc-20160816; b=pxSKMT092FEtiBtsYrKDGAY9gTon17uDaP67VjCD4SOTyE5/9NA8ufF8nk3V2/hOAf asYjpj3S+j+oo5Q1Ee0ryKEIiIGJA2l6flrIY3KU1zB1V+1gw40lVGlQHgFx8fipcFY5 6nAkp26VXirDjLyd42yDMk4OYiSd3Jyfi+32ikPpZiueWOUnta7ReQ5RKK09xuIsRpbK PyaDgSICyTgGPSy9nTdx62hb803Kxejo21wtxdqYaapKMr6yEyFPBAgcMk/1LlmPY323 T8L4fAtEE6m6s0dr/3aI5KY3MEpLLVmF9vXpai6ZQ9tSxA457gyb0kYfvxAeMVvK1lzf eNtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=H2E8C87rypFj2pp+Mxu+vqaZWf/38uSzUl4kiCl0O18=; b=RgiiMMSZvaXPPPULGOlIc4r4s0Z1Xi/Ge8hSNcxkjXDbYnsShwkwGaUBw+QW+/h+pb rTWrztR5zRLSxBtcKSHOV2rmrKaUXrfZB+IpiScqdorZ/4pjEQYEzFBfrAijbHfHPaoZ 2Ws9ZBe8k3aycCPFOPwzXdN4pSdIJzt89Agyx345Qmup15kr8faL4VJq0Chky0FyiZrc m5g1qjm0OI3q9lZoyVU19USVl9BCryfNyQ+PTVuhOxFvtYfsRpUXoLoTYOiBXfRgQ4hm Jwr6ZCyWeBhgtmC+LWBuNaJhpEy2BM+A3cpNzirP5jGaHB1xnAo1h0GCdGT0KApne2LT zfNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id l7si3815669iof.39.2019.06.14.10.53.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Jun 2019 10:53:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hbqMu-0001t2-Fs; Fri, 14 Jun 2019 17:52:04 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hbqMs-0001rD-J4 for xen-devel@lists.xenproject.org; Fri, 14 Jun 2019 17:52:02 +0000 X-Inumbo-ID: 1ca75bb1-8ecd-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 1ca75bb1-8ecd-11e9-8980-bc764e045a96; Fri, 14 Jun 2019 17:52:01 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 112D7344; Fri, 14 Jun 2019 10:52:01 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 295123F718; Fri, 14 Jun 2019 10:52:00 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 14 Jun 2019 18:51:43 +0100 Message-Id: <20190614175144.20046-9-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190614175144.20046-1-julien.grall@arm.com> References: <20190614175144.20046-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v3 8/9] xen/arm: mm: Don't open-code Xen PT update in {set, clear}_fixmap() 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , Stefano Stabellini , Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" {set, clear}_fixmap() are currently open-coding update to the Xen page-tables. This can be avoided by using the generic helpers map_pages_to_xen() and destroy_xen_mappings(). Both function are not meant to fail for fixmap, hence the BUG_ON() checking the return. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Acked-by: Stefano Stabellini --- Changes in v3: - Add Stefano's acked-by Changes in v2: - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 028fbd38ad..46bc3d8075 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -348,19 +348,19 @@ static inline lpae_t mfn_to_xen_entry(mfn_t mfn, unsigned attr) /* Map a 4k page in a fixmap entry */ void set_fixmap(unsigned map, mfn_t mfn, unsigned int flags) { - lpae_t pte = mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags)); - pte.pt.table = 1; /* 4k mappings always have this bit set */ - pte.pt.xn = 1; - write_pte(xen_fixmap + third_table_offset(FIXMAP_ADDR(map)), pte); - flush_xen_tlb_range_va(FIXMAP_ADDR(map), PAGE_SIZE); + int res; + + res = map_pages_to_xen(FIXMAP_ADDR(map), mfn, 1, flags); + BUG_ON(res != 0); } /* Remove a mapping from a fixmap entry */ void clear_fixmap(unsigned map) { - lpae_t pte = {0}; - write_pte(xen_fixmap + third_table_offset(FIXMAP_ADDR(map)), pte); - flush_xen_tlb_range_va(FIXMAP_ADDR(map), PAGE_SIZE); + int res; + + res = destroy_xen_mappings(FIXMAP_ADDR(map), FIXMAP_ADDR(map) + PAGE_SIZE); + BUG_ON(res != 0); } /* Create Xen's mappings of memory. From patchwork Fri Jun 14 17:51:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 166871 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2351281ilk; Fri, 14 Jun 2019 10:53:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqwinMj7cRkJSdN72l2aj8RfTwR8nMYW9hhouRivdTO8mzicr8j6JaKyyHuTB1iVHuDYHZnA X-Received: by 2002:a6b:621a:: with SMTP id f26mr3180828iog.127.1560534813101; Fri, 14 Jun 2019 10:53:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560534813; cv=none; d=google.com; s=arc-20160816; b=dJViIlOd7eYlC/SMcoHwVS6arLKp30P+qSWFURc6jmcfaMFcgwM9YfZDe3mhVipCzV R1sWVWwTrcMdYxJtVZYG69uJmldWuKyGRci3LGgVW8LJmgBEm92lVH2pkdoqD5CC4dLK 6qILdbitBKL9HkQNdvD1t+ftd+5AeL8r82ao2fshNS/EKcY8XamJ59sBnfo/qVpp1665 tCs86jU3FzG8KsEFInqN4pH+3VbWBbIJaEDbhB0/iInPef3y4kGNR1lEGIKLVAC8cCbe r3d0bthvoEvrmIYruJAEA/L8gc6lDctkH4x3jnyGv09xImAzsSNlWTsC0VNjb045ynTV /5eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=0Oaluw5j5Q6sORl18a5YpVe/ACZm6T5I0vplJWuO8TE=; b=S2Urofp3E9oBbc40WqNSL+rEyh16IjaU7eLFgVfkBPn+hRGZkwX15O99oCzdRAW0Qk Nd1n78oKmJDFMXyCLO1ZHHv9CsOKGBJfLDflgbSX0v7HrHvD2TtCriDkVQEVH6/Oz260 lwacXVWdjF8S8VOM93OKNpHH8+sy6pRe8Y4WIohkDNkVmRSZ/2K3hYQVrKudlcKM+NtY 6gC10Lqj9xu772+zWEACPVD/l4pXYeWKaDLrje5mObLX/CiIVKlX3DiICm5ZYuxKq97B svM2p2ShmlyQZoEwKg8Hd0bpNPkc8OXkg0LOGCFpgEu6HKVGK95FghqWOZde5Leo8nIQ 8wuw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id y24si4244748ioc.1.2019.06.14.10.53.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Jun 2019 10:53:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hbqMw-0001ul-R7; Fri, 14 Jun 2019 17:52:06 +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 1hbqMv-0001tw-Fv for xen-devel@lists.xenproject.org; Fri, 14 Jun 2019 17:52:05 +0000 X-Inumbo-ID: 1d6a061c-8ecd-11e9-afa5-8b6a9b7e3b28 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 1d6a061c-8ecd-11e9-afa5-8b6a9b7e3b28; Fri, 14 Jun 2019 17:52:02 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2FD21346; Fri, 14 Jun 2019 10:52:02 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 458A83F718; Fri, 14 Jun 2019 10:52:01 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 14 Jun 2019 18:51:44 +0100 Message-Id: <20190614175144.20046-10-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190614175144.20046-1-julien.grall@arm.com> References: <20190614175144.20046-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v3 9/9] xen/arm: mm: Remove set_pte_flags_on_range() 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , Stefano Stabellini , Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" set_pte_flags_on_range() is yet another function that will open-code update to a specific range in the Xen page-tables. It can be completely dropped by using either modify_xen_mappings() or destroy_xen_mappings(). Note that modify_xen_mappings() will keep the field 'pxn' cleared for the all the cases. This is because the field is RES0 for the stage-1 hypervisor as only a single VA range is supported (see D5.4.5 in DDI0487D.b). Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Reviewed-by: Stefano Stabellini --- Changes in v3: - Update commit message to explain why the field 'pxn' is now cleared. Changes in v2: - Add missing newline in panic - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 58 ++++++++++--------------------------------------------- 1 file changed, 10 insertions(+), 48 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 46bc3d8075..35dc1f7e71 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1255,52 +1255,6 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int flags) return xen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, flags); } -enum mg { mg_clear, mg_ro, mg_rw, mg_rx }; -static void set_pte_flags_on_range(const char *p, unsigned long l, enum mg mg) -{ - lpae_t pte; - int i; - - ASSERT(is_kernel(p) && is_kernel(p + l)); - - /* Can only guard in page granularity */ - ASSERT(!((unsigned long) p & ~PAGE_MASK)); - ASSERT(!(l & ~PAGE_MASK)); - - for ( i = (p - _start) / PAGE_SIZE; - i < (p + l - _start) / PAGE_SIZE; - i++ ) - { - pte = xen_xenmap[i]; - switch ( mg ) - { - case mg_clear: - pte.pt.valid = 0; - break; - case mg_ro: - pte.pt.valid = 1; - pte.pt.pxn = 1; - pte.pt.xn = 1; - pte.pt.ro = 1; - break; - case mg_rw: - pte.pt.valid = 1; - pte.pt.pxn = 1; - pte.pt.xn = 1; - pte.pt.ro = 0; - break; - case mg_rx: - pte.pt.valid = 1; - pte.pt.pxn = 0; - pte.pt.xn = 0; - pte.pt.ro = 1; - break; - } - write_pte(xen_xenmap + i, pte); - } - flush_xen_tlb_local(); -} - /* Release all __init and __initdata ranges to be reused */ void free_init_memory(void) { @@ -1309,8 +1263,12 @@ void free_init_memory(void) uint32_t insn; unsigned int i, nr = len / sizeof(insn); uint32_t *p; + int rc; - set_pte_flags_on_range(__init_begin, len, mg_rw); + rc = modify_xen_mappings((unsigned long)__init_begin, + (unsigned long)__init_end, PAGE_HYPERVISOR_RW); + if ( rc ) + panic("Unable to map RW the init section (rc = %d)\n", rc); /* * From now on, init will not be used for execution anymore, @@ -1328,7 +1286,11 @@ void free_init_memory(void) for ( i = 0; i < nr; i++ ) *(p + i) = insn; - set_pte_flags_on_range(__init_begin, len, mg_clear); + rc = destroy_xen_mappings((unsigned long)__init_begin, + (unsigned long)__init_end); + if ( rc ) + panic("Unable to remove the init section (rc = %d)\n", rc); + init_domheap_pages(pa, pa + len); printk("Freed %ldkB init memory.\n", (long)(__init_end-__init_begin)>>10); }