From patchwork Tue May 14 12:31:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 164203 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2561947ili; Tue, 14 May 2019 05:32:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+KVOT+MCwnnxrty+I+WpADKUMa5AJIRpb+ycwZ8MCILdsjmQuLOJ3sv0xH/qohBY0R2Ab X-Received: by 2002:a05:6602:11a:: with SMTP id s26mr1179398iot.201.1557837163611; Tue, 14 May 2019 05:32:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557837163; cv=none; d=google.com; s=arc-20160816; b=ea2j9RFT/+nShyTPxiaOFSPq31LcLEZpO0xVcI3e1qG2j7rfisiO+KDBUduhYat2Of FPyrzi7sF56lvzEKZ7cKJ/J5d27t2hxvwR6EtzAPEGhLcKnSqyA8BRo6JnX0dd4HYKtL 13OWD3fP3LZHOZ6GRbGa2ambDpGAd44F8fOfJ8FdUCpoAcMtHn9K8B6HsrUXLrxPn75p Jhyytv5SOtQl3YqZN2TYw+IlztzLqdxnEWSkG0FdAWhfZL7JpNQfLP/gCHpR5ZdrRpgC IXwB2tRkDbRxrk/GEropEbJpJZHznXLYr6xkwd7j8JPxLl02/vso4mXSrc1tDV9rQxkl lJTw== 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=KZfDxa9HDPTMdTvVn3yYmFaSRApeZAiwsNjCCCAspik=; b=HViEzBUZMIwtR8kSO5QiCJN74v1gbgguGuSSSlgM3gQBNSGr9mhDC66sNSpwt5JzEk IQf1NAvIp/ERkuANCRqIBdzmulbBp1PDXg5AetwSUv99bPz059LMT3U5iPH0ekRIN1BZ SPTn95Et2NRqVnhvvu9gOkGLKslWB3Qt+j1hW+ggh5ilr6CBKMmIRYF7rgXGqKGWjekV JI4LXuu+e4VcbL8+TLZi+5i4zE4QLjKwUUiCOlraQab/2Bb9sO+b01VN1pJxlwwfSWFC L3ZBYv9usAyqzbb0Y6oonyWE9BSTqnrkH7HayFdioKmTsvQPxKA8kW4R3FUsPKycKaEe WLkg== 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 m4si8286450ioq.50.2019.05.14.05.32.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 05:32:43 -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 1hQWal-0005L3-6n; Tue, 14 May 2019 12:31:35 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQWaj-0005Kr-Vd for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:34 +0000 X-Inumbo-ID: 34e55125-7644-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 34e55125-7644-11e9-8980-bc764e045a96; Tue, 14 May 2019 12:31:32 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B456815AB; Tue, 14 May 2019 05:31:32 -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 80F4A3F71E; Tue, 14 May 2019 05:31:31 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:14 +0100 Message-Id: <20190514123125.29086-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 01/12] xen/arm: lpae: Add a macro to generate offsets from an address 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" There are few places requiring to generate offsets from an address. Rather than open-coding everywhere, we can introduce a macro to do the job for us. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Acked-by: Stefano Stabellini --- Changes in v2: - Add Andrii's reviewed-by --- xen/arch/arm/p2m.c | 23 +++-------------------- xen/include/asm-arm/lpae.h | 9 +++++++++ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 92c2413f20..06fa342a8f 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -368,12 +368,7 @@ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, p2m_type_t _t; /* Convenience aliases */ - const unsigned int offsets[4] = { - zeroeth_table_offset(addr), - first_table_offset(addr), - second_table_offset(addr), - third_table_offset(addr) - }; + DECLARE_OFFSETS(offsets, addr); ASSERT(p2m_is_locked(p2m)); BUILD_BUG_ON(THIRD_MASK != PAGE_MASK); @@ -888,7 +883,6 @@ static int __p2m_set_entry(struct p2m_domain *p2m, p2m_type_t t, p2m_access_t a) { - paddr_t addr = gfn_to_gaddr(sgfn); unsigned int level = 0; unsigned int target = 3 - (page_order / LPAE_SHIFT); lpae_t *entry, *table, orig_pte; @@ -897,12 +891,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m, bool removing_mapping = mfn_eq(smfn, INVALID_MFN); /* Convenience aliases */ - const unsigned int offsets[4] = { - zeroeth_table_offset(addr), - first_table_offset(addr), - second_table_offset(addr), - third_table_offset(addr) - }; + DECLARE_OFFSETS(offsets, gfn_to_gaddr(sgfn)); ASSERT(p2m_is_write_locked(p2m)); @@ -1199,15 +1188,9 @@ bool p2m_resolve_translation_fault(struct domain *d, gfn_t gfn) unsigned int level = 0; bool resolved = false; lpae_t entry, *table; - paddr_t addr = gfn_to_gaddr(gfn); /* Convenience aliases */ - const unsigned int offsets[4] = { - zeroeth_table_offset(addr), - first_table_offset(addr), - second_table_offset(addr), - third_table_offset(addr) - }; + DECLARE_OFFSETS(offsets, gfn_to_gaddr(gfn)); p2m_write_lock(p2m); diff --git a/xen/include/asm-arm/lpae.h b/xen/include/asm-arm/lpae.h index 545b0c8f24..c22780f8f3 100644 --- a/xen/include/asm-arm/lpae.h +++ b/xen/include/asm-arm/lpae.h @@ -218,6 +218,15 @@ TABLE_OFFSET_HELPERS(64); #undef TABLE_OFFSET #undef TABLE_OFFSET_HELPERS +/* Generate an array @var containing the offset for each level from @addr */ +#define DECLARE_OFFSETS(var, addr) \ + const unsigned int var[4] = { \ + zeroeth_table_offset(addr), \ + first_table_offset(addr), \ + second_table_offset(addr), \ + third_table_offset(addr) \ + } + #endif /* __ASSEMBLY__ */ /* From patchwork Tue May 14 12:31:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 164192 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2561696ili; Tue, 14 May 2019 05:32:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqzIKBhQoU6XLy9mvUOwl57zrwFFGlXqiTqVitt1TOP5tywDGlvC5Ab6OJSU0h4HBOWr9xRa X-Received: by 2002:a02:1cc6:: with SMTP id c189mr22530256jac.119.1557837153409; Tue, 14 May 2019 05:32:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557837153; cv=none; d=google.com; s=arc-20160816; b=NESnBlq3kGAzyRG7xRryC4lSaM9hgc7rsJRO8zApdgbWuXw3pWHMW+PySGXKWHJOjB m+tNeIDZFIVHANPZahAckKl2doB+d3bJVeYh0cy/k/me5+zqNuHLOxwtQ2QnXLEddrPG q1fa28U7dssNXvrniz2QPQpRip4jBTjrzq9hzsM33xmg7UOxI+e+G1THbgZODDzK2Vvb QtRQb0zR5tcLlPPgB5e4+N7Ot/uNOvTwxRE8YirU84CFZEmc87kqE0TH3vnwl0Ya5ALG /FWtykOakKV9P5hSQODEsrykQnaBpA4uAxBn9ldXU9pyMxAKgG4irKsi39gooveBemc+ 2w/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=DzCZSgyav+mtmOFNt5O6rV4PUjXSBF4b36MR1VD+oL8=; b=X2yaVsuuzxR47rQb78Tx4Iqi9C9QbpvrlhGcbNyzS+s6XtVSXHf3qrFsWQzE+VTFqZ E61YL50OCAqp7ryuRFnzHs+SO0E23Setmm+VmDVocw1QPZqh0Ld3vh5yAqEAh306LuUP Q3svYvHEJGxjU0MvJsPK8NmTXMl70dYxBEML6k9EGPA0Sp7v38V8MtLvHi6eoc0Rv0Nn T+FYmGig6dYNBER4nQsfO9aRsoR+wZXnRFBUZf14U9y+svMorKdrmYQvpxQu68mvei5t sVsO2tKRIhKhJaTdANub07JtCKTi4lVzEcU4WeE8L3HulAY10vklN3EntP/cIlz2aR8U 2u/w== 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 a6si8949483ios.154.2019.05.14.05.32.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 05:32: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 1hQWam-0005LE-Gh; Tue, 14 May 2019 12:31:36 +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 1hQWal-0005L9-P6 for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:35 +0000 X-Inumbo-ID: 35d8d544-7644-11e9-bbf8-af7ffef685ad Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 35d8d544-7644-11e9-bbf8-af7ffef685ad; Tue, 14 May 2019 12:31:34 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 318DC15AD; Tue, 14 May 2019 05:31:34 -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 F25383F71E; Tue, 14 May 2019 05:31:32 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:15 +0100 Message-Id: <20190514123125.29086-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 02/12] xen/arm: mm: Rename create_xen_entries() to xen_pt_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" create_xen_entries() is doing more than creating entries. It can also modify and remove entries. Rename the function to make clear what the function is actually doing. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Acked-by: Stefano Stabellini --- Changes in v2: - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index b408de7c75..36e22fc9ad 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -970,11 +970,11 @@ enum xenmap_operation { static DEFINE_SPINLOCK(xen_pt_lock); -static int create_xen_entries(enum xenmap_operation op, - unsigned long virt, - mfn_t mfn, - unsigned long nr_mfns, - unsigned int flags) +static int xen_pt_update(enum xenmap_operation op, + unsigned long virt, + mfn_t mfn, + unsigned long nr_mfns, + unsigned int flags) { int rc = 0; unsigned long addr = virt, addr_end = addr + nr_mfns * PAGE_SIZE; @@ -1067,25 +1067,24 @@ int map_pages_to_xen(unsigned long virt, unsigned long nr_mfns, unsigned int flags) { - return create_xen_entries(INSERT, virt, mfn, nr_mfns, flags); + return xen_pt_update(INSERT, virt, mfn, nr_mfns, flags); } int populate_pt_range(unsigned long virt, unsigned long nr_mfns) { - return create_xen_entries(RESERVE, virt, INVALID_MFN, nr_mfns, 0); + return xen_pt_update(RESERVE, virt, INVALID_MFN, nr_mfns, 0); } int destroy_xen_mappings(unsigned long v, unsigned long e) { ASSERT(v <= e); - return create_xen_entries(REMOVE, v, INVALID_MFN, (e - v) >> PAGE_SHIFT, 0); + return xen_pt_update(REMOVE, 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 create_xen_entries(MODIFY, s, INVALID_MFN, (e - s) >> PAGE_SHIFT, - flags); + return xen_pt_update(MODIFY, s, INVALID_MFN, (e - s) >> PAGE_SHIFT, flags); } enum mg { mg_clear, mg_ro, mg_rw, mg_rx }; From patchwork Tue May 14 12:31:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 164195 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2561745ili; Tue, 14 May 2019 05:32:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqysT1o2wN0VUTfN2hjNtj/OoJxTtlqz0HGkXaVJlD2pNq+uVz8PMZvJtTAV4rGXk5Pwvdib X-Received: by 2002:a24:4754:: with SMTP id t81mr3278004itb.106.1557837155494; Tue, 14 May 2019 05:32:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557837155; cv=none; d=google.com; s=arc-20160816; b=bxCYaIP3sJhq56xnKhiK/DnsEIrXOlDxQEXVDehVg2b5qy3WlCD7ijST6jR49UJUGs Xht9wsW6lbVgW0TTpbPDsJ3VaW0FqyHG6bb2jpKCr8l4/2wON5apYOsLfulp66HSTqH/ 1Assnfa4pnGNbX+LOduC0iopqUFwvYbI5BSeVzrLc4yY+TjRpvaJ0m+WvT/fj+eLL5Et 7HeH6fj0kPCGjlYuH7xIanuUQpJvNbhVWvnlsQDl2ZbZIhg5rtSIXxBVr6vVNYOHueJb kjqCWdDMjV4lDVKqrdEsxJnqZPQ6Kv1xK1szfJyH92I1k/u/NFQzFY+upluQSMImz7lm /0QQ== 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=Sd5LlFTLrSwuH9XsPqTgL8PejG5Vyahgchhl9qG0fuk=; b=tnYFjz2Lg2qiA3Zh2nuBJTGkwRRkqABRWkmWPwMKBZH2Dtp1rQphKUoXvGQsK1IK1k A37ZyM7N5yEFatVjKfeETo9RDbhHL7SR6vkvLr5ed20XBo7pA9SrwH4sF+xHP6JgnAGJ grDcU5O0vKBCF70xl0F/ZZEMPZKQNeBsitY2LjKH4+S+NdkgvEhyc9KQoOn1SY079R3Q YGMrsuUPRYRKnpeii4aCdWJJvFTVrYZD5Vco+A6ctaIAQEnRZqmEU/LqeerWgp47EBfF DQcG2Z77HYAyF6xU5UlzhNpyFaFDmOT1I+rqld7c8OOsjnRdobQNlvTFZZ3e0KGtdeoh Y+dw== 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 q24si8945475ios.118.2019.05.14.05.32.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 05:32:35 -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 1hQWan-0005Lb-Q8; Tue, 14 May 2019 12:31:37 +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 1hQWan-0005LK-1a for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:37 +0000 X-Inumbo-ID: 36ade63a-7644-11e9-a640-97876d6490b5 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 36ade63a-7644-11e9-a640-97876d6490b5; Tue, 14 May 2019 12:31:36 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A2CC4341; Tue, 14 May 2019 05:31:35 -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 6FB0F3F71E; Tue, 14 May 2019 05:31:34 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:16 +0100 Message-Id: <20190514123125.29086-4-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 03/12] xen/arm: mm: Move out of xen_pt_update() the logic to update an entry 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" In preparation of rework of the Xen PT, the logic to update an entry in moved out in a separate function. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 140 +++++++++++++++++++++++++++++------------------------- 1 file changed, 74 insertions(+), 66 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 36e22fc9ad..f956aa6399 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -968,6 +968,76 @@ enum xenmap_operation { RESERVE }; +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; + + entry = &xen_second[second_linear_offset(addr)]; + if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) ) + { + int rc = create_xen_table(entry); + if ( rc < 0 ) { + printk("%s: L2 failed\n", __func__); + return rc; + } + } + + BUG_ON(!lpae_is_valid(*entry)); + + third = mfn_to_virt(lpae_get_mfn(*entry)); + entry = &third[third_table_offset(addr)]; + + 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)); + pte.pt.ro = PAGE_RO_MASK(flags); + pte.pt.xn = PAGE_XN_MASK(flags); + BUG_ON(!pte.pt.ro && !pte.pt.xn); + pte.pt.table = 1; + write_pte(entry, pte); + 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 + { + 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; + default: + BUG(); + } + + return 0; +} + static DEFINE_SPINLOCK(xen_pt_lock); static int xen_pt_update(enum xenmap_operation op, @@ -978,78 +1048,16 @@ static int xen_pt_update(enum xenmap_operation op, { int rc = 0; unsigned long addr = virt, addr_end = addr + nr_mfns * PAGE_SIZE; - lpae_t pte, *entry; - lpae_t *third = NULL; spin_lock(&xen_pt_lock); for(; addr < addr_end; addr += PAGE_SIZE, mfn = mfn_add(mfn, 1)) { - entry = &xen_second[second_linear_offset(addr)]; - if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) ) - { - rc = create_xen_table(entry); - if ( rc < 0 ) { - printk("%s: L2 failed\n", __func__); - goto out; - } - } - - BUG_ON(!lpae_is_valid(*entry)); - - third = mfn_to_virt(lpae_get_mfn(*entry)); - entry = &third[third_table_offset(addr)]; - - 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)); - rc = -EINVAL; - goto out; - } - if ( op == RESERVE ) - break; - 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); - pte.pt.table = 1; - write_pte(entry, pte); - 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); - rc = -EINVAL; - goto out; - } - if ( op == REMOVE ) - pte.bits = 0; - else - { - 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); - rc = -EINVAL; - goto out; - } - } - write_pte(entry, pte); - break; - default: - BUG(); - } + rc = xen_pt_update_entry(op, addr, mfn, flags); + if ( rc ) + break; } -out: + /* * Flush the TLBs even in case of failure because we may have * partially modified the PT. This will prevent any unexpected From patchwork Tue May 14 12:31:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 164194 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2561734ili; Tue, 14 May 2019 05:32:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqz/nhcmiOVsptLpPtnE7RGTlP4jPYZO8Hsh1ZoVLj3IxTq7IdISmOF6tHdVHK0KCAKa8+se X-Received: by 2002:a24:edc6:: with SMTP id r189mr3695795ith.158.1557837154970; Tue, 14 May 2019 05:32:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557837154; cv=none; d=google.com; s=arc-20160816; b=eleij6U9O4yBeY2fqQ/xU0Ro0aoKoaGWUHqhMbxd5XarsJUAx87bg/UWs3ZbzP8QpI xc5Sg103XUY2YUvMdxIApVFGlSLHBSKEb3/TKDLyeyIx5WI6WCBJ5CFC7vcXnXkBGdh2 gSfUtmAxS8MYhjQaHTrP/06eYPOP/6XzlqtRa7C2FLd6PmbdzsGbMYDdesCjOnqq2k4h 7pC3NSibL2mTlD8b06dS2okasQQlFCo/krSTek6iozdSO0VqN68vXYaLt9IMeVJAqJ96 SNOSdBLaortaCf0aAxkDfoZD0TXE9zBewDSwdwQUjACRZpJu6tEELxG5aHMj2AR/yYEv rzEw== 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=C4BrL4lMuSUFy2yyQfrathgWRBWylzhjV7bD6DZgLuY=; b=mmjonJ8S4smDW7px8lQ/IiYMi+KA9F97Cq8hOu09BKsuS6edXRZw98CMaoayTHGnYV siRNEc/p3u1oM16ouc0wvztGzVMAGUmdXKgC6fWJhO9gazxVZAfYNPQvzbbwQCfgqHG8 QOpaMPL2f6RfRGpheIjMbjDn5xpbta3DMrJ123xJ0TsmkFhUrR5CvycKLyMYu6bZhHG+ PasBbMTG8vzAWWbRbKixWswUXD/pemHqPw3WoRVH5ihfkv5vvCnkvyRu5PC9YiFJ2Q0O tMDyHEzQ7eQ9AL7jEwHnFQlo7DGrWdokR4PqQPFpahLehe6GDH1U6a9Yym9MrFYln6fR LcFw== 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 r128si8906185ior.24.2019.05.14.05.32.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 05:32:34 -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 1hQWap-0005MA-9c; Tue, 14 May 2019 12:31:39 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQWao-0005Le-0o for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:38 +0000 X-Inumbo-ID: 377b0a74-7644-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 377b0a74-7644-11e9-8980-bc764e045a96; Tue, 14 May 2019 12:31:37 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1FBEB15AB; Tue, 14 May 2019 05:31:37 -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 E08DF3F71E; Tue, 14 May 2019 05:31:35 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:17 +0100 Message-Id: <20190514123125.29086-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 04/12] xen/arm: mm: Only increment mfn when valid in xen_pt_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, the MFN will be incremented even if it is invalid. This will result to have a valid MFN after the first iteration. While this is not a major problem today, this will be in the future if the code expect an invalid MFN at every iteration. Such behavior is prevented by avoiding to increment an invalid MFN. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- Changes in v2: - Move the patch earlier on in the series - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index f956aa6399..9de2a1150f 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1051,11 +1051,14 @@ static int xen_pt_update(enum xenmap_operation op, spin_lock(&xen_pt_lock); - for(; addr < addr_end; addr += PAGE_SIZE, mfn = mfn_add(mfn, 1)) + for( ; addr < addr_end; addr += PAGE_SIZE ) { rc = xen_pt_update_entry(op, addr, mfn, flags); if ( rc ) break; + + if ( !mfn_eq(mfn, INVALID_MFN) ) + mfn = mfn_add(mfn, 1); } /* From patchwork Tue May 14 12:31:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 164196 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2561757ili; Tue, 14 May 2019 05:32:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqw0m1iiEFjRCEgyRgO5dA6LgG2Hz+iTrbD0a7wfTUsyXScWHufXZ7OV7ZDvLHvMLXZhAOIB X-Received: by 2002:a5d:83c5:: with SMTP id u5mr3166854ior.137.1557837156133; Tue, 14 May 2019 05:32:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557837156; cv=none; d=google.com; s=arc-20160816; b=LeGpzlfyVzt6T/pkfQK23osjujGarbdiNs/prBKOsoZodzGtkUXvwpiHCcQLoa+vtD G0YJPvXRe91kwsQa8AVXpc1NgdT4wfOaYsxS+ymlUrGE723IQXzOa4sT1GMr8OzDvDfT wmW8NFLmHzIxyJFbl7ey6XedznFtJjc5DbWC1dbMjcdQcPRRb6ZofWfjpBISbl6ifYiA b90KMntuWaKDr7TPHQC6xJliPqwSGUDCY8wnXQbvA8HEa1/JGvU0iqXBMT3rsg+tWBNK hE18EK6cke9E/BX2xMJAuvV/N+83cFQLpZOv2qhnNUOwYNwIjYHC2J6UuTukW6B6dACv 1mbw== 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=EoGUuu7rYiZT8b39UakCMSwcCzcEDBQRX+JSS26gZQM=; b=SODkJ8Jf7JBhmY/CLdstPrWsmvKrYd/3EVMgXfjs4M+RI2xQ4Ne++e8vCYABJKRQuG 5y8VgcaotUyyfD7rw/IgstYGrp7MYhoQuNFmgOEdRdM6NADHlKdzIQrrxv8PXzxAgPZO wbFC1NsAP/Fbic66RU26Qy4rSt0yd05pmyoHqx8Z7BHKqCebDDahTvQVj8tdH6ECPELM FDeEs2gsaTwsbAuJ4RGAjoc5lNEg7JnuY2JoVKKyoQIJD0Bzctk8DIKk+U41McaHkTIt jCMXlJ0nYZNjC3kIBg3l1lLJdl+MzG/TaV86s/ugfle+sfWLOboqXce36d3qBO9YXiIY ncag== 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 v62si9080186jaa.67.2019.05.14.05.32.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 05:32:36 -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 1hQWaq-0005Md-K4; Tue, 14 May 2019 12:31:40 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQWaq-0005MN-3t for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:40 +0000 X-Inumbo-ID: 3860fc25-7644-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 3860fc25-7644-11e9-8980-bc764e045a96; Tue, 14 May 2019 12:31:38 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9137315AD; Tue, 14 May 2019 05:31:38 -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 5DFA63F71E; Tue, 14 May 2019 05:31:37 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:18 +0100 Message-Id: <20190514123125.29086-6-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 05/12] 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 --- 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 9de2a1150f..2192dede55 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1083,7 +1083,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..caf2fac1ff 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] Present bit + * [6] Populate page table */ #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 Tue May 14 12:31:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 164200 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2561872ili; Tue, 14 May 2019 05:32:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwDY1apmvksuB95T8nHSEoARb4qvIixoJvYK4sJ/pz2fIblIk8pp2eAeOVoYFt5q3L09rDP X-Received: by 2002:a5d:85d9:: with SMTP id e25mr18994352ios.26.1557837160690; Tue, 14 May 2019 05:32:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557837160; cv=none; d=google.com; s=arc-20160816; b=Ea+8shFCIM/YY0qhD/dlLPUU8rb8fOtG+AJn1hZNRCYmuMNR0tnEELwX9XSD2yj/Kz TsEkAUOSb/N2fJgJEm47PeHDXkIq2LMLeZ6Ynz/H4UBUd9aqUkN1AZpGrCLSu7WCYegu 2nSwdZafxTq4h454lEuJC8IKMHjmuWLyfiIxBppcZ8tfN8CNSOB5AN2tuNVSEQaa8BsB wFCN3AtIqyEXy5uHZdtfiBhAS3VmaBXOr/fhbsjGj3j4tta3OD19sID5lMXLwStt5PTM fwsKtGnMa6GYMFkyXp/3DE0Jc0TXNEYkTM54sPp5kgsaspBBPObsjlWY/MJWmTmyC1wp 9PVw== 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=rYohg+P0gAZ9Q0QlMGjYyMkis+pGx79Rxxhq+p8NUg0=; b=RVlBjA8vGTjn3spy9tNIu0ootkblH8X0njGsquqL0990VA28kHMnhvqxgNCe55sihk J8XtYdt32SPJpdBm3eweZpWqAOt64tbNK4UgenPr1iD3yCnGc+9adOc2YYL6oAgcvDAC YFf7pOxFbauyHjKa2NXi83f92NuFoXJw9SzcOeLkyuDnosJ6wWT5gks6DWMCDMwazeCG YiMdnSyXdOezHY1XuxMuDBV+U+2NASUcolcAG/EUo/1jaA1GyPY2Iqf79NaCkRbGOHbP oTH5vFVVYoXTWeqTh1nTjvXGx019xoynJB+e7fNVvZr47iB/ZbOU1tLJXRqmDbXnx1Wa 6KGw== 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 i203si1456914iti.6.2019.05.14.05.32.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 05:32:40 -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 1hQWar-0005N5-V0; Tue, 14 May 2019 12:31:41 +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 1hQWar-0005Mx-8b for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:41 +0000 X-Inumbo-ID: 39653716-7644-11e9-99f3-63d46a5efb4e Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 39653716-7644-11e9-99f3-63d46a5efb4e; Tue, 14 May 2019 12:31:40 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0ED03341; Tue, 14 May 2019 05:31:40 -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 CF54E3F71E; Tue, 14 May 2019 05:31:38 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:19 +0100 Message-Id: <20190514123125.29086-7-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 06/12] 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 --- 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 | 115 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 97 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 2192dede55..45a6f9287f 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -50,6 +50,19 @@ struct domain *dom_xen, *dom_io, *dom_cow; #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)] @@ -968,12 +981,74 @@ 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 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) ) { @@ -989,15 +1064,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)); @@ -1009,12 +1081,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 @@ -1022,12 +1088,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; @@ -1049,6 +1109,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 Tue May 14 12:31:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 164197 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2561791ili; Tue, 14 May 2019 05:32:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqysd1vCvh97K4NcIhC8ID5Sf4siL+eZChwN9WftFuhJiw4R63ouL8/i+ylH7vhyRoL5wtYJ X-Received: by 2002:a6b:6f08:: with SMTP id k8mr14761054ioc.104.1557837157325; Tue, 14 May 2019 05:32:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557837157; cv=none; d=google.com; s=arc-20160816; b=AsfXb4yOM0y7l/i9izFc8lIzBCMBGD6JB/LqwmaDb28WL4/IXEbyWhgQC7pfmSPE9U 7Yz6O9ef5yeH1TqkWGEDrL9UMwbzwZDaafW61No2Fyjs2XgWAxuDwITFjCq6bciAcCap 3Tpq1If5dXT3XJvNOs3mAbcEkq2BfI92cEhj+5x7sJ2ineTwXKIZQCwTLXszvQ6DYY6G ebhzD+LZr3zM7wBWUIOCOiE1e9X0473xhJhn8BnpF0hb+1Dqp5VyDETKALaixCfgsgmS vZDdfI4rrpBLg9T6oD9KnwSBUMT+n4XObg8zerYexq5KSaBSveIjwWKSPhN1n6mw+oub cZkA== 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=636CpUsBf7lH75u4OaPdW//ylanrxAd2Ry/1iH7WNaQ=; b=T6563PMaDGVgK+d8Mq32YcvA2MPrnm/tFNt492mKeqpllQc2Nc227u8a4rMFvYKfpa s5vyU3ixi1UYsfFghmF5bkmVTchNWSgMTwjAJ0vby3p/WO62w7M2jJeMLuFkIFP10O7i 9G3SaXOwVYyNQDr9oX3vZtW+dv+I+7qlMG7KGi5TVKgVIpHxKkROCgV0xM6BXy7lIW5P O3IRnZeKbtQtWwf7NXq4z9p5Jg2Fke0iyIe0VhhK9OgyQsVhjGq2CM/wmwjcisk3QbOj CQJRZRx1RyU3mkpioQBr8gZtjIFmeSqCvDnZ29OXOGlPPMyklQPfOblagfnLoa9a5Dha 9nNg== 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 m84si9147090ioa.89.2019.05.14.05.32.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 05:32:37 -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 1hQWau-0005O8-91; Tue, 14 May 2019 12:31:44 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQWat-0005NT-26 for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:43 +0000 X-Inumbo-ID: 3a201512-7644-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 3a201512-7644-11e9-8980-bc764e045a96; Tue, 14 May 2019 12:31:41 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 80C1315AB; Tue, 14 May 2019 05:31:41 -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 4CF8D3F71E; Tue, 14 May 2019 05:31:40 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:20 +0100 Message-Id: <20190514123125.29086-8-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 07/12] 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 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 45a6f9287f..86e1faeeb5 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1067,34 +1067,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 Tue May 14 12:31:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 164201 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2561883ili; Tue, 14 May 2019 05:32:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHpMh2aATbj+Uh6N/evgg3VI1zWFzzK54LSY+IJlcKsP8MVLe7q1FawpOyThC4OLeiqU8K X-Received: by 2002:a02:3ecb:: with SMTP id s194mr23166491jas.29.1557837161254; Tue, 14 May 2019 05:32:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557837161; cv=none; d=google.com; s=arc-20160816; b=KnLycs6j69S2LrJRCKZ5rrP6bACKEt2rf8MiP36UR/O1CjoujdzRy2hfaFeT1j8QCP tHmDL2T74QqXfgs/ZdCaXXmdBVkfGU9xDIY55SkI8+j9ykD4vLqMUalsgBdb15nGP9pd UY5vLZkVqfqunQHl7R5YQ2+L4XtD5Zklo4z+D8QgYAyj/KleHww7oDmH3tKhid5TxmwC 0w6++bVrqJhI3Ly5ovOGqYoKgNiMpY5xhxBacDlYtaAoLLPAiQ3/nlMs2Fwh6F5lEnWp P5ecz3hVDooL66koBWWVj0dX0ZvNs8W/85X9iEC09OePWk147q+L4oIuNmkVOQn18cRl 9MlQ== 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=ST9YiMniTUOihPYzALvzcZ7J/M2Kx93Y2ZytPcWb5jw=; b=VoxrGNIPcOiijEKevDiH3AuCW3Nw564d2d2f9fG1K8XCB30nmGGWiyK5Wl5eobq9fr biAaLygxZDGYHTzQPsqTRfuJpW7BJUPNm2yfBlOeRV3X+/RH18E3SaHz5y1JYOxrfreJ 80pGdJGEUblzfuyyahCPJ8FtQ2VQiSxQEDIoHQVgwCj3CC/+1YA5QInZza9jshlAufiD +oZJ5+Hl2Wf2tzGd8Jq+WdTp7rpcC1aREiOvnAVv+cO0lEC4MhioIcrTC7oyZCwUGk0+ C9SJSJhw6vO8PGLp1EgmcQA5/LIZuXQ21IYPGlGcAK5/eCNwPct/Tb9DhnjMi/b3gRDO pZog== 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 p79si1364431itb.120.2019.05.14.05.32.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 05:32:41 -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 1hQWav-0005QF-M7; Tue, 14 May 2019 12:31:45 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQWau-0005O9-Ca for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:44 +0000 X-Inumbo-ID: 3b0516d9-7644-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 3b0516d9-7644-11e9-8980-bc764e045a96; Tue, 14 May 2019 12:31:43 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F250415AD; Tue, 14 May 2019 05:31:42 -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 BEE743F71E; Tue, 14 May 2019 05:31:41 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:21 +0100 Message-Id: <20190514123125.29086-9-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 08/12] 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 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 86e1faeeb5..651e296041 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -974,13 +974,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) { @@ -1040,8 +1033,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; @@ -1099,8 +1092,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) @@ -1131,7 +1123,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; @@ -1156,24 +1148,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 Tue May 14 12:31:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 164199 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2561864ili; Tue, 14 May 2019 05:32:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzgH/qJUUl9tV3CypwYYTu+Nl33/0UqHaLbFXKHA7d5Z9N1xkqa97DM92gySpsTByMpnFIw X-Received: by 2002:a24:8342:: with SMTP id d63mr865271ite.66.1557837160144; Tue, 14 May 2019 05:32:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557837160; cv=none; d=google.com; s=arc-20160816; b=dExmpjRtcVKpFrHSHm4fP3mw00b7g4vBcrByL8ebpkP7np/QbHflAICSrzS1qu0j7m CisAWEkLGv+yE50dSc6tkbktbFJ0+9t9yQlFOROW+IEzsNCb6ob12glpBBkKQ4rWygea BM+y9boHo/uOmv11VisMxkiDtH3tVWWuLwzlbDdduMBYv26UEZ2Cn6Giyn8Dl+K5j60G ibdFMZkt6jHOXctBT9XvNZc0oDYJkG+l2zY9wP9N4ON9hcXFoRx/TBpSmOaJqfwRDf1f ML9WB/Xl0IzKe3oSla66jsBPvqkrbilFVifVBirGJifwo+bOyJgbeHXAmCNFQOfwZ76G uIDQ== 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=asJQ6oXkvoubr6wNyHe0lSspww4TN4X8SItzDIZBE0Q=; b=Qc8sP7GIdrbVf0/KMAzXjItT+TbsyY3KWlSlLDHZCVcGwrDNwgkiJuztlu7w7hB9kk s0GCGyTcfWari7pPk2pMh9cMBvSSGPDlYXQLNQu1B5H6XAh4H+LNIU7ts763VjXW7miB k5EwOsI60ykCN3R7tmHcZJIlLJKdOXE+KBfetQsma6z+ZYIpFGAENdZVj98z5wa1bKZr O6a0xQMWnnNiGBTK4Rb7WzxXBHu9u5uElADrkJN3tRw68CwGO9mca7mDI05CDzbMHCHH 5czgd2mWt/pk4MH3nlCk3yiXeAVpQKP/BYa3tJTLy6O/ir95m/qRjeRWgLGHItPBvFPc 81eg== 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 q129si9635249jaq.0.2019.05.14.05.32.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 05:32:40 -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 1hQWaw-0005Qu-55; Tue, 14 May 2019 12:31:46 +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 1hQWav-0005Q2-GG for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:45 +0000 X-Inumbo-ID: 3be35306-7644-11e9-9745-a782c9656c67 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 3be35306-7644-11e9-9745-a782c9656c67; Tue, 14 May 2019 12:31:44 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 70476341; Tue, 14 May 2019 05:31:44 -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 3C40F3F71E; Tue, 14 May 2019 05:31:43 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:22 +0100 Message-Id: <20190514123125.29086-10-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 09/12] 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 practice all the page-tables updated will reside in xenheap, in practive 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 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 651e296041..f5979f549b 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -974,6 +974,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) { @@ -1036,6 +1046,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; @@ -1054,15 +1065,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) ) @@ -1087,7 +1100,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 Tue May 14 12:31:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 164198 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2561821ili; Tue, 14 May 2019 05:32:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHZ1eqXVIiRw9zidn1oF8ZF7E00rrkQKXY3/FFq9gdJTe1POyrsjuWOKP4kB0X9jC2U7gs X-Received: by 2002:a6b:db03:: with SMTP id t3mr11648665ioc.252.1557837158255; Tue, 14 May 2019 05:32:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557837158; cv=none; d=google.com; s=arc-20160816; b=Chy5fIlx45x4/ovPpnfzLyI1C4gJMTXKL9gcmSPGCiU7cPy/SqAPY2SfZ82I6Dm44n 6ZwiDf7X+eri4k0HvQt+cObhht6CUEL/Q3g70WfVSrRddxEdKzifiq+2uR+d2xTsuRQI wVZZJby2fBB913UqbAa3Sc880tZX1n9CpZXE+slottmhqirpHdgnPeZigG4JnTRymtsl hgo6WDlpUn2zosWWA1rMdFrgjtO5ja2Z9DSq5Sa6Bxx3VytMrj2BfmJQM7eMfYFokMW9 BFCG2Mq5JffaWPPoT4FiGZZtKJKRFg89vXvTptpBTd0UMFPvDn6Jz2OT/bS8TsvwqkK/ doUg== 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=APJzreMBZxF3B6yZ1frc+3ECyif+0gi/aTIo6kpCy18=; b=iUYIKbtrlIX67UfOE8XkVVzBTcg/DRGXMEWNWZIQoPWlHAHQ8tjU9ncypwAQalwPFJ GxDqjEQJn0AVbthwPlNv2cDWCoUWCj93oVJglN3oLjgq8K/XGPRr+NNdP8vVbzjt1HWX q9dn4SQcdQ6OLf1YNCboh/n3TnRh0bo/0A3JTKPJlhZwxOIGrtCzWEyUCtnWeXgQEM6I JDB5WcjACQ8upmD/B4ySZluD3trszyLh4uhVEys/4Hf2JUUn1v3nEEQ4X+sqP9Am4rdD IWGNe/BGaReYGWTD/Wqy2EsTM0MFuIwg0m+H7nBVqhgfeCI1M/u1sHH1dMisYAnyAF/K XXYw== 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 k4si9223288ior.117.2019.05.14.05.32.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 05:32:38 -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 1hQWay-0005UG-Nc; Tue, 14 May 2019 12:31:48 +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 1hQWax-0005Sd-CG for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:47 +0000 X-Inumbo-ID: 3cc2bb54-7644-11e9-aba7-3fae97ee57bb Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 3cc2bb54-7644-11e9-aba7-3fae97ee57bb; Tue, 14 May 2019 12:31:46 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E121015AB; Tue, 14 May 2019 05:31:45 -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 ADCC53F71E; Tue, 14 May 2019 05:31:44 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:23 +0100 Message-Id: <20190514123125.29086-11-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 10/12] 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 --- Changes in v2: - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 106 insertions(+), 15 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index f5979f549b..9a40754f44 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -984,6 +984,53 @@ 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; + } + + ASSERT(lpae_is_valid(*entry)); + + /* 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) { @@ -1043,30 +1090,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) ) @@ -1103,7 +1185,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; } @@ -1119,6 +1201,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), @@ -1139,9 +1230,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 Tue May 14 12:31:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 164202 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2561891ili; Tue, 14 May 2019 05:32:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqwDr+bWGUGM4QBC2qjXZ2BlHLnL9ZOB9F9vkFeu4ofw1l7jZKOmaGIEd3+Ryl56B8ur/GGO X-Received: by 2002:a24:354c:: with SMTP id k73mr3472068ita.175.1557837161529; Tue, 14 May 2019 05:32:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557837161; cv=none; d=google.com; s=arc-20160816; b=bRjhY/E7IMndtQBF1hdAUTX1iecKiB2GA4n4Vu7IWJ3v6u/RR4h8JL0PvPffTjFcC9 ky68PvvNffhW4cseCD1hAZ7pNFfjvtE/QzZrGAvZeQ8y/EyV9bb08d512SXoudGnz9lJ O0MwuDHqugwInXkY7oGU76JsZjGxy+UwaKzh1B97qiW4pJiXpTrwLjg6+tDlj4JNRn4N UrtKkFXK029Rm7O3JoyEttx5DzGwgEgEoqX2zHVhfWg6geFM4FtMp6ybT7G3BCzRBxJB 9eXGFIp8LK7MT8wLdmun8EqLC+wBWCXFer4Eg5+jporjWufL2cOOtKCuBkcuIaTRN7Nw I9iw== 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=q/5fO5w8i5zfDMpa1uLC2hOGVREryTjNX266uOdlSzI=; b=DTF8tkL4dHd0zg34PGjUDADEZCwcuqPBs764axqE6ytkHb/ZEfNV2mr62K+QGd8+U0 o1ofdLlAV2RjK+v8nC1ZeNgWCom2//J8/Yz1SnGnpCCDnfjsw/wQuJH6Si6suGztUgM2 Yqu5UoQj0AEMx5vtB0ioOgJwU6Q6lnyg4prDqDZPZFXW0KzW7AgeW7nBGC0VDyKxy2my 5cVtVMVwkoIWxl4+ZDNIoz+ccdRAMDX8IGtKUQ5XaSRKSFXkspN5cYMCh8MnIz8JEIfb vLZ44ZExdHvHjH/FbEqEwUCnkJozwqm2vG7pNGHTSfG5z0YnYY5D9q9mragx+fFGAFrq 1A7A== 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 n70si10693213iod.141.2019.05.14.05.32.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 05:32:41 -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 1hQWb0-0005Vt-3w; Tue, 14 May 2019 12:31:50 +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 1hQWay-0005U8-LN for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:48 +0000 X-Inumbo-ID: 3dba290c-7644-11e9-8b9c-93296919fc85 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 3dba290c-7644-11e9-8b9c-93296919fc85; Tue, 14 May 2019 12:31:47 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5E11C341; Tue, 14 May 2019 05:31:47 -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 2ACDC3F71E; Tue, 14 May 2019 05:31:46 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:24 +0100 Message-Id: <20190514123125.29086-12-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 11/12] 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 --- 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 9a40754f44..23ca61e8f0 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 Tue May 14 12:31:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 164204 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2561968ili; Tue, 14 May 2019 05:32:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1jHBzZfQ3FQXxvWzQZO89OBnjqquOAwzGlDilcPJJFMCW1CLrMvxAmmQIOkdmBSfX6AS/ X-Received: by 2002:a05:6602:143:: with SMTP id v3mr12033868iot.45.1557837164421; Tue, 14 May 2019 05:32:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557837164; cv=none; d=google.com; s=arc-20160816; b=JJT7Ozyk8DS+2FPOOVtss6TvbT+Fb0h2BsKgNUD734nX8oINGgmLSKn0maMk+Aj5qr idJVMgt3RbZRN2ybTr7c80HqegbFU69l2C8iMHVKKDlVhMABKFNa8FZoKcoBbx3CnUUk W1Qytq5ueZd3oASABJqZv0SGtE2LNE4rjEzRtsquN6Amj9aF+5wRsNfROsMWxbiu4PUh 2/mpbemL5nXoygRbxv7VyYXjBXmEQ5fWPvfQ1MhjlLepk9gF3pI+PHC+m3vsm8IzBT8e rZL1lkZJHjY8FvFEc9JlZdAUrTGZmvasWi8EjRI2CKqsxiTpcGarzY9GOxn7yITlFOL0 7PHQ== 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=NYceLMcH0dnOtniPH4yWjGE7uP2ifN97Cb0B1oVMZOo=; b=PLeJL2RAy6tsCEsfGDBEPmZUBYMWEIKxWkDP5KdkRbJbfs9ynHoB+teehAXMVWknFm jCWUcOb58aMVSaiauBjJXQox130PT/svPRf7Fda3r2B3MxHRbl6CsCLSogBI8FLXIy0t X/3Grg6GvnCyyN6gy0sVeN8VMzAtHBKiBIXesinaxGMxdchSG3JQyo2HljT3Bl0DPobr nrhrtlL1ZdPaX85X2/QPnd6w8V8cBX0vzpZyc2ITxBhj4w5vF7M06b0uMh3/Owf6WdaW 0xg12I3gTGtGX4J6y9mzMjOC8mvHeODlgKMm18Ru85twogy3KS6NLZrT6JPeXGFy/Oht xLQQ== 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 c63si1393623itd.123.2019.05.14.05.32.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 05:32:44 -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 1hQWb2-0005YQ-H5; Tue, 14 May 2019 12:31:52 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQWb0-0005WX-OY for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:50 +0000 X-Inumbo-ID: 3e86e24d-7644-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 3e86e24d-7644-11e9-8980-bc764e045a96; Tue, 14 May 2019 12:31:49 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CF7E115AD; Tue, 14 May 2019 05:31:48 -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 9BE8A3F71E; Tue, 14 May 2019 05:31:47 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:25 +0100 Message-Id: <20190514123125.29086-13-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 12/12] 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(). Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- 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 23ca61e8f0..d74101bcd2 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1277,52 +1277,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) { @@ -1331,8 +1285,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, @@ -1350,7 +1308,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); }