From patchwork Wed Apr 24 16:59: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: 162793 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp895711jan; Wed, 24 Apr 2019 10:01:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxytVMOpH3CdFriKYXInojWQXDIsqb9BAGrOZZCmAJ8N/q5eoEHK3VaI1kQrXU4FlRfY6AS X-Received: by 2002:a81:3050:: with SMTP id w77mr7658289yww.107.1556125315182; Wed, 24 Apr 2019 10:01:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556125315; cv=none; d=google.com; s=arc-20160816; b=JbhetmvwcJSDvqH8zxmc9fNYDG7PkUAFBPO2zwQTsnYSK5JeAeKDA22khUfi11ztQ1 dJj8ok6T3pVYQ1pyD4r04qRwAryexHfGGFehoGqfVl1LQ7tReKyDa3E5ulNY4dpCRKln PWA2vJ3JoZaCkKqHowOZSEd2tUlCEqt/Ca7tPVtu1N5slftqDM2QLLdhNLgV9OGBKZRL U6mH6T8gr1F1dYuncYvW1fSLKLwAEWRsaIP98tEkcOhLaKB+aybJsCvwS15O7Vg9Hb2F vud9T42paISChUzN37gFU2tZFe9vBDbnrWORyrxY7zHK6vC1gzX1AskU4X/il8er2hvi eFIQ== 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=0bqQbijfgv+DtHqG5cfgjQ4Vn94/7ZDbg/Qzwo04RT0=; b=T9ImULsUEdRLNnXISeVwVFHyiCmVwIgPGxWWu+0PxVCuMsGX5LL6CwY8eQTu2R1Dnd 9chUycXXd1yYwEH/px4E5+MIH9ea3sjawwb6uccCYvwycnP0efY9sOuZ1Vu3B5KHqtZR IGw4979kak3FhtgY+OiJuAaXSlC6s1qJo3o4AvsP6TXUqD7mfjEBlgX/ZNXgChso70DA ohBNbHlcO11imNGYs30KumEVXUBL8q27YIzUpuNQ/HE4N1SsPDTDaHC5iyTugipDzjDc B/GnLnmvrFIRDUq5X5dwf7xey50R8nLG2ZXqwE52LIrKQx8V8lWX6oK8g5etI+dPm3kB abuA== 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 v140si11333911ywc.419.2019.04.24.10.01.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 10:01:55 -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 1hJLFg-0007mq-3h; Wed, 24 Apr 2019 17:00:08 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJLFe-0007jX-S4 for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:06 +0000 X-Inumbo-ID: 68ce6a76-66b2-11e9-92d7-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 68ce6a76-66b2-11e9-92d7-bc764e045a96; Wed, 24 Apr 2019 17:00:06 +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 D0FD0EBD; Wed, 24 Apr 2019 10:00:05 -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 B49AC3F557; Wed, 24 Apr 2019 10:00:04 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:44 +0100 Message-Id: <20190424165955.23718-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 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 , sstabellini@kernel.org, Andrii_Anisov@epam.com 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 --- 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 Wed Apr 24 16:59:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 162789 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp895678jan; Wed, 24 Apr 2019 10:01:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqySmiMLcxHWt1oNwpVnAKGoW8EfH45owGZS6VN5H117Mks0ft28FSRdGWDdxMoym+eUCR5+ X-Received: by 2002:a0d:ec86:: with SMTP id v128mr10102527ywe.128.1556125313593; Wed, 24 Apr 2019 10:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556125313; cv=none; d=google.com; s=arc-20160816; b=vgJSNdmmb/m44sr41fudnchmSbHLO0D7wxHaivnWOMEhjtRYFQTmhc4/tUv+tUJ1xa bGcjGYEIIo3ffVOlKKOPynetLxWFGcIVOj8B6sW3kVV/AkFg57G6cMYezGEf4JqzSkb2 jmuH5QHZ2U3FStqGL0kD60If+92+QtB0cwJe8w0jvZXGkUxB3kn7uYge2bekfHQ/6T04 C2IPthxXkPiqi+SGEn5AtDoSmDd9ftkM9HCbd9n+hc9RHYX0T5BPLd+nCG+yYGDvtgKa Zn+R++eoHhY6ZTjrr53iuJPsMV6Q7kANT9IuMzb0WSEpXDut+1jQwF80uSmUV4m6TGLL t6CQ== 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=8hguHsdSinYmO30SVyc5dThRBEseWvk43zMgI2E6Y+w=; b=agZr2doDCF/wKMxAbQNwyVKgYrytZUct9tTW2lUtPPzRidFWa9HhpYOEOfrIZV3j+E T+/PdTgvgPXebkMABo/evC/WNMItsqB5MV+PBMJ1E59srNUpJy2i2J0uwES2JFqVsOxg r9ZGI4VZ3xK54uGo/wQa0nPjZIuub6qNbjgRZgeTc4x+ntIxIEMIlR1IZ6XQArAXzfEp 8So+eV8WpIuIKl+pSQbe/shJpaVgASSgdGFT4OTInziRvK1kT2BKPuEz1XDhWI340oX4 UL24zstwDnAOnbb5Z7Arl+DBwAw6x95kJusqe8TbyDWw4BTO8gQqBpEpJMqGKq68CIds 5nXg== 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 l18si13671756ybp.183.2019.04.24.10.01.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 10:01:53 -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 1hJLFi-0007n2-CT; Wed, 24 Apr 2019 17:00:10 +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 1hJLFh-0007mw-4e for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:09 +0000 X-Inumbo-ID: 69ae0bec-66b2-11e9-9840-9b0330304ec4 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 69ae0bec-66b2-11e9-9840-9b0330304ec4; Wed, 24 Apr 2019 17:00:07 +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 38C5E15BE; Wed, 24 Apr 2019 10:00:07 -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 1E1143F557; Wed, 24 Apr 2019 10:00:05 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:45 +0100 Message-Id: <20190424165955.23718-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 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 , sstabellini@kernel.org, Andrii_Anisov@epam.com 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 --- 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 d6157c35d6..df2ec3a36b 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -965,11 +965,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; @@ -1062,25 +1062,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 Wed Apr 24 16:59:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 162785 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp895601jan; Wed, 24 Apr 2019 10:01:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6QVSbc1yCr2AClMgjhgCdgQiLL1p5+uIv5XXAe1SLHQtI16IModnFyBrhN/GVDX+V/im8 X-Received: by 2002:a25:cbd3:: with SMTP id b202mr5943858ybg.247.1556125310282; Wed, 24 Apr 2019 10:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556125310; cv=none; d=google.com; s=arc-20160816; b=eZishnSjk8RmviCuo2PZgIrlQzmz9+sxMxrC7BTUWCvVKOPI2nYHRZa/C6lCB0FIsL lgsYwgv6hcE39jIDSNU4N2hYqgUNeo5WdmgCOhq+4c3wy54BX1IIAKyL/zQOgbZ6r2wv Zq3EmT8IqgrJRvDvJfakeMUbH3CzgJZD92a7UBk89njWndfu2PhcktrDpa1kKpVAfWZc +QzRXKUeEYrgndtmZdLY0ymRrhMszeKx3OWiL+OA2HgZm/WzHP4BdlBt2igtga5yfXlr I3r9AaF45aWy/feCBzfdcK6VppWcrhQBA0MQZ4WlgvqoQJevTnWyP78SChcvtS6fjlbh b4lg== 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=ZNputk6QUdrZiTQcmoyAXdm73PJc4QX+zMHIMfURwWk=; b=BIFmsfiuuQGi6W+4GYq2i38TPE6RJTsRa4QfSXja7cEo9YRqcr+NexSEKehAYqF2P9 UrwLNbPgKeHCbPgNowJOYLzIZv62mOkfZT7cPyTXwK9G2CODSOdFFbFTaE+k4tY7zKeE 5vYasXhQ2kqx5wAgmC9UWCd57jqBbrD0InkqpZoNu0OLtrJXaf0Wzp6p3lgVDAkEk3co s/l8EVM1fhwS0Soj7a0nXc9HIMLeZrisIyGqcJUpOHptk72aPU3+Espg4s41rnQes5/r opqxaur961OsQrMJGbKGXhVPJz1cEV7MQS3c0gmFK6jqrHZ4bblOaf+JSf0FNdnhhXIY SXtA== 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 134si13819849ywp.77.2019.04.24.10.01.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 10:01:50 -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 1hJLFj-0007nH-LL; Wed, 24 Apr 2019 17:00:11 +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 1hJLFi-0007n1-BB for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:10 +0000 X-Inumbo-ID: 6a7fddf2-66b2-11e9-8188-4bb1fa585020 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 6a7fddf2-66b2-11e9-8188-4bb1fa585020; Wed, 24 Apr 2019 17:00:09 +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 97A45374; Wed, 24 Apr 2019 10:00:08 -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 7B2593F557; Wed, 24 Apr 2019 10:00:07 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:46 +0100 Message-Id: <20190424165955.23718-4-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 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 , sstabellini@kernel.org, Andrii_Anisov@epam.com 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 --- 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 df2ec3a36b..6b1d41cfba 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -963,6 +963,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, @@ -973,78 +1043,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 Wed Apr 24 16:59:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 162792 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp895679jan; Wed, 24 Apr 2019 10:01:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxCz+BWV0gKUCGSWtgkNfXpK+49zMjm8K1BbcyYZPxNRSr+Z6O3YRByXYjBKYn6GW6FnRdQ X-Received: by 2002:a81:a60b:: with SMTP id d11mr28784844ywh.251.1556125313592; Wed, 24 Apr 2019 10:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556125313; cv=none; d=google.com; s=arc-20160816; b=n/RNXrs0eWKdlaGeuqJwRjzJRy3ZUcRJGmgO9HM25rKPZtAw6vrfVuT3foO84aewud 2jAl6ttRW54DZQKc5hgMjSIdeulVj2SAc4YB60vAtIK8IWYmD6XD6ALpMlwoNH0UoGY1 vtBTTO8MgJ85SFz6Ms62j7eLNaexA+35x9+V1Gj/cKB+tsiPRVNlmO3POBMn8jlfChwS N2FlW+QhljhTHgeBnlZfySBvFG2deS1ROTm4LYxFD+v8bk2VNpiqT98XDI6I55iGKGL/ T88t5pwo9Hn8j3ull/1t/87I4LkR48U1RNqjPwBJPXjXgmd1qhqIFuKzYy0v4s5gREO0 +v2A== 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=LpnIUsiNfWwPWKoaae1YH4QsdYC0swy4OnB3z1iHi1M=; b=t/ytNe0bvQ7xjtNkBB7HyIBHTqISWO6bmLECrzSAU0BwWXpYEOzXJTpJVX+p8cPxT1 kcl7qyUtFI6nIvGfBF1litGsQl6XZEQvxJofevJSOO5TD9dJv0tZVdHxsjoppQPE4mUr 5L0S8s4bwhn8PDfo7hKPGfL1q70hRgg7dAQY+ta1YEeqddtzIrEdVhbvsKyzvPuicsog fgkZ/2gKuuU1tdkE+AGfMOrJhWXikCI/LvuA5iiyo2UNgSe4hMigzkN4apLOIkfDrr+p gJP8GiosgW/E17rBJYRWq5o2WHVdImR7Dvjr9UR010yd+iaTW3ltXCnYHNqNzs3vQYVz 1hiQ== 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 o4si13515233ybp.283.2019.04.24.10.01.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 10:01:53 -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 1hJLFk-0007nS-Ux; Wed, 24 Apr 2019 17:00:12 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJLFj-0007nC-8v for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:11 +0000 X-Inumbo-ID: 6b529442-66b2-11e9-92d7-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 6b529442-66b2-11e9-92d7-bc764e045a96; Wed, 24 Apr 2019 17:00:10 +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 F363AEBD; Wed, 24 Apr 2019 10:00:09 -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 D87713F557; Wed, 24 Apr 2019 10:00:08 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:47 +0100 Message-Id: <20190424165955.23718-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 04/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 , sstabellini@kernel.org, Andrii_Anisov@epam.com 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 --- 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 6b1d41cfba..b61217abd0 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1075,7 +1075,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 Wed Apr 24 16:59:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 162790 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp895700jan; Wed, 24 Apr 2019 10:01:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxo86qGC4ayMhLMXSa+UqeRbMY237sqzv6WYTn3cwiDUWfPWnsWmxpIGd3CH+NntNIdgac9 X-Received: by 2002:a81:1e51:: with SMTP id e78mr29121392ywe.302.1556125314757; Wed, 24 Apr 2019 10:01:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556125314; cv=none; d=google.com; s=arc-20160816; b=G6k9Wa1e93gbaIErmN9dwtR9dbTM988B2CMVnGtlzzWAP2UvYIcaEJgnUBz4ssZlVi Y8x+4c8hwBeXp4jNmJMkNki5HigcwLhTMmnc+wdIoYZLMoWIzhSCOYEriUuEKpJfCLn+ AtU9Nt/qYA8fkUfR244uY4hzgoCKYnjZyhDY2JfqJkSnebAIXcD5jv+o+Rs70aX2Tr+e bis3R2BtX/iIr29clLwMTdq9rbfKrU5DNhiw4XvMZ8ymhCOVDF7Clv2GBfiZ2/Ok2Fyo hq0JNCyQ3ybqPNFp9nWHyzOhpLJ6Na+zMbc1E6I84alQ+W12xh9XleEypzCH8Uf2wkZv HRtw== 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=7igDFhkOrVPnO9OKdiiGnD56bNDkqOWtgF14/LjV8Jg=; b=kdpPSySi0QcA31sTWpwXfYYAy0GXMBaC4JsWPs1Pw1iTDSJABmKdOVMM1agN4A++zO Ub1rMvcGEqc0ZxX+TCJWTcVFe2HjAwfH+ftbM5ECfgPDAxRJl9vPnN59wwvAJU82550O e+gvDIiGwghkaMwHGAtUh9ZScX3Gftdkuckr3PV856aWPiEVCVrc4omreiKv52sUf/sv v1+hQvFIesZy21dLj51wb2B/mBjKD26u7CfpeSiu6q4cNnjqbqgOsFhymoLDxFz9sjMz ZX6S9hbVC+tSjL2OA4fWIfEgX2w4kUwbgckp9iygpIxYYiyztLGDdRVmRqGIZ7OqkUm0 XgVQ== 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 20si13039389ywo.36.2019.04.24.10.01.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 10:01:54 -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 1hJLFl-0007nY-9o; Wed, 24 Apr 2019 17:00:13 +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 1hJLFk-0007nN-9Z for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:12 +0000 X-Inumbo-ID: 6c1ccaee-66b2-11e9-ace0-d3443eb28cba Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 6c1ccaee-66b2-11e9-ace0-d3443eb28cba; Wed, 24 Apr 2019 17:00:11 +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 5A9E115BE; Wed, 24 Apr 2019 10:00:11 -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 3FD433F557; Wed, 24 Apr 2019 10:00:10 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:48 +0100 Message-Id: <20190424165955.23718-6-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 05/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 , sstabellini@kernel.org, Andrii_Anisov@epam.com 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 --- 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 b61217abd0..eee7122c88 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1046,11 +1046,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 Wed Apr 24 16:59:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 162796 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp895752jan; Wed, 24 Apr 2019 10:01:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwENAGpmwhQXZ+gzBXg+Quw4rCp7Unp7R4/TvGIMy63esoUZRGr2W05ghXLth7CDD4r1fTl X-Received: by 2002:a25:1254:: with SMTP id 81mr27113087ybs.237.1556125317408; Wed, 24 Apr 2019 10:01:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556125317; cv=none; d=google.com; s=arc-20160816; b=sL/hx9mM5BvutRJM90oSbXUJAdzFd5FgbP4e/vl1/5MavIRcejnWowg5XUplLNVDs9 3JivK6Hq2DGBmwknixgLmq1ziDLPptfR07PIu+9l3qXg1Pz2osqkihUoWC6rRxAt9e/m FLd/CpEduZ6P20iRdDK/p9Wil9TCIeeDvWNIEe1R9NHZEAX/SFc6qM1BW6C1P8+jwZq7 On9rSOtCzW/ug9eCxpY8EpsFptVOh1FTEL2xH+4Q1swmvPVPpnY5t+A88jJM0HoSU9// XY8H+0ZuLqb8HqECjOmsZ/DsDckHTXM3EF74anK/7G3cjPim9URQ3/7SL1OCADDsz6dx xyIQ== 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=lpedV1eiG5rJLQ2LjvVRzgM1eOhn2vZtAOxQCzzBEsQ=; b=t/jj6GJmykJXYUDUiKB7pIME8iwNzwiUTy6uyvdZBiBpt6v2vQr1kt1hLcZDEXPXJj 2aPhbDYZ8ZId5UiTcfc99RNLxFfqLBvhDDLpYWx2XzBwVKJQVtO489TBD2M2At6r6J4v xIPeXlvAUnw3J/b8vpWcMxLuJ2G/52buzQ1BygwlC1waxiSJhN7qqf5t12uZGDxPp/8Q 1arumolmmZ2hWFOWNvAVFLqDcdtolz1FHjzsP0qCjl504PUTYuuTqI+I43y/oe2/V6gz AIk++z1G4mxb84HoBc+V6+sIAWejtH4ykG7956qrrRxaPqZutHSIYlmxapiF4zZPvl3w d+IA== 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 a205si3441805ywc.284.2019.04.24.10.01.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 10:01:57 -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 1hJLFn-0007o1-Jr; Wed, 24 Apr 2019 17:00:15 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJLFm-0007ne-Fl for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:14 +0000 X-Inumbo-ID: 6cdf9cf3-66b2-11e9-92d7-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 6cdf9cf3-66b2-11e9-92d7-bc764e045a96; Wed, 24 Apr 2019 17:00:12 +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 B600F374; Wed, 24 Apr 2019 10:00:12 -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 9B6743F557; Wed, 24 Apr 2019 10:00:11 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:49 +0100 Message-Id: <20190424165955.23718-7-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 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 , sstabellini@kernel.org, Andrii_Anisov@epam.com 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 --- 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 eee7122c88..5eb6f47d74 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 + /* Static start-of-day pagetables that we use before the allocators * are up. These are used by all CPUs during bringup before switching * to the CPUs own pagetables. @@ -963,12 +976,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) ) { @@ -984,15 +1059,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)); @@ -1004,12 +1076,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 @@ -1017,12 +1083,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; @@ -1044,6 +1104,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 Wed Apr 24 16:59:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 162794 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp895723jan; Wed, 24 Apr 2019 10:01:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLWgRn7UiY2VSOrj+8qv9feG0/UlG1ihOqQElhe8FECIZWy+3Dk4wrsVBvgU1VOXIfyKMj X-Received: by 2002:a81:30d8:: with SMTP id w207mr17661294yww.362.1556125315720; Wed, 24 Apr 2019 10:01:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556125315; cv=none; d=google.com; s=arc-20160816; b=a62PtvMidJlmhPewZ4WoS82W5lsw+1CilrhR+ZpxGSLEJ3lWEtoYped+9mPrU61w5m 8HzELhvWm6Y941m0VHTTJ1KU+K10Yb12DiENVZ6N7USkFH9h3ddBdFqo417UCJtz4T1Q gXnbgSYOJcv0gXqkzmM7slmFYCYHJ+lDXy571Zu+jP4m8bIgu1LA0qQNdtPch5SkjJMT BPCSS8+4K8AaAeJeybSyf9YzzqmUjkgTQEYlLuk7XK7OyO2TC8ZtjlGp0wRFHZ5wWEar xqH2K4YeZtbim0DhtmRMOkqfpOr2FB2P6YPKJS4m/EIqQMG8/yGxN1/RhAvGDvNOOiYk smqA== 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=SXAhvy1mk1PIBcnA6Oz00f9u41NJpRNQO0PISrzh9Ag=; b=Gy+7srTct1xEAJOwU8e47mBUGkYaJsom6arHMveLZAMeYoVfVuVGrim7ScH8oHz34E 46w20yI75ZFOSpxuwh3spqIQYbHtlLv+RlDQdI+rY9mvh4erfmIW9VKz75k+1j1NTLig 0kQURuX7VA8RAJq/j1OgqIIlF1hm6VbdnfkPZVQEsY6qhEMVJYqXQ9oYEARj/wrq86YI XCRHteC1jwPYzy5CpyRXh2K+qQJ9e5kSYOw+Jo6DmF0rR/8QqsTHUOteBsx5m3OBayOO apnBZkkon505gsAz4zQ6fo4jEADii7+liistphiq0c8a5ecD1dgCpidzr8MXUQ41/XCv D2wA== 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 m83si14743307ywm.54.2019.04.24.10.01.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 10:01:55 -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 1hJLFp-0007ob-1c; Wed, 24 Apr 2019 17:00:17 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJLFn-0007o4-OR for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:15 +0000 X-Inumbo-ID: 6dc2e40a-66b2-11e9-92d7-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 6dc2e40a-66b2-11e9-92d7-bc764e045a96; Wed, 24 Apr 2019 17:00:14 +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 1DB67EBD; Wed, 24 Apr 2019 10:00:14 -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 028153F557; Wed, 24 Apr 2019 10:00:12 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:50 +0100 Message-Id: <20190424165955.23718-8-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 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 , sstabellini@kernel.org, Andrii_Anisov@epam.com 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 not 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 --- 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 5eb6f47d74..611ea53992 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1062,34 +1062,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 Wed Apr 24 16:59:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 162797 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp895734jan; Wed, 24 Apr 2019 10:01:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzlnKB5U/cgNlOAJM6Tol/60z+H7bndLEzz1eRBUGeLY3f8mwNr2Q93P4qti7Z2jLichijt X-Received: by 2002:a25:655:: with SMTP id 82mr26851690ybg.383.1556125316155; Wed, 24 Apr 2019 10:01:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556125316; cv=none; d=google.com; s=arc-20160816; b=FXfyUBEu3XNwqt7wGLYeDFAzUKSRF2NPtT0NQNEGhKnSwLUUkeCedtOaeoSLlLhldx FKYgyNZ/8Yn7TYQkzNS9tY4BFOi9p8+yoBaHUsmF5obrc1qg/4KPDjs5wVWwsiPdPybW HPnMxPS/0dzp84Zfgw3PUqs0pEOjym+ctaemzx1xwv6cZoJf6JHseS+x6uMZx0wPRx4L m5pk7q1qYb57PKv23ZVqHvKuCGJFpKbPtXm8eFYcx0EIuLf2oXA2EAX3qpojFfLh/hRb Ox3Jwdygg/v9OH2rnV12pu3gXrVwm/VXKYBKL6gcO+F1155JfFy7NAY8MykkpjWu/5k1 fTrw== 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=ufJGPF65hyJPA8b2qjto24PDzi2+yA54VwpoEX8bzlc=; b=P+ndEewayJaJp/BBdqQw40cMsLdG+3JAU6ZpKc4UjoBSxAfcJ1HBZ47i8iINHc1Iuy D67Fx0WGAFcvuoPV96IKehkwUwmO1JPslBl64d4ddUlOwQfPEmULE7kj/N6zkXJs26YB Qz46R0HLrDYKM4jvr216i524aBpRkhNrvo+BkZAZ6bJ/HytGZCqwmwoa0fFmRLeK4cEI njaFR4i36nSTNRUyFt3RizJRs6Hyc6DhOkl4C4SE70dGu5jlZ7bZefxXvkTzx9ro/GEP fGH5E9R+/FHaomH3KKNafJuyFXV0/0yoNEI6LOULQFbERcMKX9O3ww/l2fHekt9gxfjN yGcA== 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 k184si9217473ywg.467.2019.04.24.10.01.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 10:01:56 -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 1hJLFp-0007ol-CT; Wed, 24 Apr 2019 17:00:17 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJLFo-0007oY-Vy for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:17 +0000 X-Inumbo-ID: 6e82a483-66b2-11e9-92d7-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 6e82a483-66b2-11e9-92d7-bc764e045a96; Wed, 24 Apr 2019 17:00:15 +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 78DDD15BE; Wed, 24 Apr 2019 10:00:15 -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 5E7353F557; Wed, 24 Apr 2019 10:00:14 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:51 +0100 Message-Id: <20190424165955.23718-9-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 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 , sstabellini@kernel.org, Andrii_Anisov@epam.com 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 --- 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 611ea53992..97e876d866 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -969,13 +969,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) { @@ -1035,8 +1028,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; @@ -1094,8 +1087,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) @@ -1126,7 +1118,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; @@ -1151,24 +1143,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 Wed Apr 24 16:59:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 162791 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp895674jan; Wed, 24 Apr 2019 10:01:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwGvD1q5qjogDw3vHMhu0EjsvoX4lbu/1YeCNaVRp95hL1aFemjvZJOXx/hKE8sKDzHOIa+ X-Received: by 2002:a25:6f83:: with SMTP id k125mr27758995ybc.106.1556125313400; Wed, 24 Apr 2019 10:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556125313; cv=none; d=google.com; s=arc-20160816; b=vivkTaH3Qjr8y2Lb8tXxam3sxiI1BGnlRqZCi7IFq6tQuk/JHNQ1rgXNPYJ2eHobWW k4g/gxXGR6Fat6sC/ItGCIkG+lRJVI307fw3wt1LZoaI/RP1ZiyHkBYbwYL2CHSPOu2C TItyvq4jOqPySv0CTcY3nL5cgqQoQj8jl9lptlGaerNWDhp38zm7jT0WETVzXCBR7Wr0 6NJyWFFYdvVNCqQopEr02enHy1Esvc813rH9SmJZ4mUBCU/dWySSVNwYxXq7LqRxz6Ld t5JP3zWlGgqdxVBtSaNeeeO9kfDQOBzGcNHKcZKoXQVHgzxEEiz7WesI6UlYHrpAgf1o Idzg== 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=CVOwkPIQIV7WD0PjnnuTpAx04DTIUnAjo6Z3+BVP+34=; b=qEjFRNyiCgwWvyiCc6DSFWkUXGJIxULLsIJn91m6hqbt8YvDFyiEFhcc94HEM7Zl03 y8I8mBh7fUt3FhWJallsD5nl/5cnmuVzIb3wrJ31QPpIlsjZRNOpqFgSGgxmOd64Lzfy ZcJiKtbm22hit6JpnFXGhcobqi/7ajq5dFEixQ/bNalbGZUzfsyTniS5e6YmT7hjzqCI rBqrxZQS7CgBppkJHRNGMIHnqI6GOBsc266r68CzUPhXfJBTiG4r3wI9zycfF7n1yMcE bRH2VjHQS3k4aeI3vYQY4Y38gaISlgBPIVuLV+KqNUcKhTc5+AmDq6YFAl+RjWykiUCp ajng== 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 d9si7146576ywa.58.2019.04.24.10.01.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 10:01:53 -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 1hJLFr-0007pc-Mo; Wed, 24 Apr 2019 17:00:19 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJLFq-0007ou-7w for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:18 +0000 X-Inumbo-ID: 6f5498a0-66b2-11e9-92d7-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 6f5498a0-66b2-11e9-92d7-bc764e045a96; Wed, 24 Apr 2019 17:00:17 +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 D40E7374; Wed, 24 Apr 2019 10:00:16 -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 B99843F557; Wed, 24 Apr 2019 10:00:15 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:52 +0100 Message-Id: <20190424165955.23718-10-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 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 , sstabellini@kernel.org, Andrii_Anisov@epam.com 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 --- 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 97e876d866..115e8340f1 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -969,6 +969,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) { @@ -1031,6 +1041,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; @@ -1049,15 +1060,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) ) @@ -1082,7 +1095,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 Wed Apr 24 16:59:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 162795 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp895735jan; Wed, 24 Apr 2019 10:01:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqyisv/yTuDwXgQz2k9wUSKk693v6VZcfEBRMVzAtQhfjplocwsWBJU2QKnnaXKC+t8CdFV1 X-Received: by 2002:a25:6ec3:: with SMTP id j186mr27090597ybc.344.1556125316225; Wed, 24 Apr 2019 10:01:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556125316; cv=none; d=google.com; s=arc-20160816; b=g4CrTwd93NSDIVf8N4dYB+7DzJUL9E3mw7lLBgNKABWbSxAXbXnqjcVIsTzbSF9zSX 4hkhQ3ExV6ImqtztRIhW5/+ASiwX1XfVRzO2+m03BUU82XhlQ6vWz6MBRjtgdiSEFS4K GcI9hY2N4wff0/zHHFxCwsSt82UUKAzdc635uw+4u9T34BxhbimpsSg4GoYPC6ARP+Pv FvS/rzvZNMOLx3RfsbEuAJM9FHKu++lPHjDpz9R3OVGtQJe0CllhKSz9418mWI2NO+6d 3I60vNsUHz6aWy2sneykRqPMMMT0JaOqq5aHDaeREFd7qFX1PClmtS420GDD/teZgrU+ 9/dA== 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=YXcAIG4oObdlYQYj4+ikPZYdAa4sUe5JCoqRJj5pq0M=; b=WroAEdyGlov2NLJWi+ktadaILHK1wHSrogDZtkUmOcgo+HPsKw9SrYcfaGmTsRwtMz US/QZmgBTUPjpuUMrVWz3k8F9FjHliBcHvCR6kSGK2xBPjlads5zpyFkJ4XPgAZUL4wW uUAL7m2csgi78pWIlnFTKmztK7GSghwn1FYKUMCYlGSiPlJ4D5ra8agIBAiZzCOmYGmY Elzzk+2Y23/tgKDtiwniFDcw6b4gBj4lhMEgxUQr9qWYpy8d9lfSAhFfWWo3OrPVRj7S wXZU+zQi8IgUWl/aTBCe8WHJMBrjn4+h6OwwqoGkqZEGfobzDkXDe6veUBNcn0Hr3+jb OmfQ== 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 q188si2096202ybb.359.2019.04.24.10.01.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 10:01:56 -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 1hJLFt-0007pz-16; Wed, 24 Apr 2019 17:00:21 +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 1hJLFr-0007pX-HF for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:19 +0000 X-Inumbo-ID: 7037dc5e-66b2-11e9-9f38-6b2c9412e21c Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 7037dc5e-66b2-11e9-9f38-6b2c9412e21c; Wed, 24 Apr 2019 17:00:18 +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 49331EBD; Wed, 24 Apr 2019 10:00:18 -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 209803F557; Wed, 24 Apr 2019 10:00:16 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:53 +0100 Message-Id: <20190424165955.23718-11-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 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 , sstabellini@kernel.org, Andrii_Anisov@epam.com 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 --- 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 115e8340f1..022967ff9f 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -979,6 +979,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) { @@ -1038,30 +1085,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) ) @@ -1098,7 +1180,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; } @@ -1114,6 +1196,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), @@ -1134,9 +1225,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 Wed Apr 24 16:59:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 162787 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp895659jan; Wed, 24 Apr 2019 10:01:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqwiUzrwVKF7VnNGsLco8E5/XTdQUBMHMESZJ64b55JhZ0ISIuPqmXTX7el6eOayHrUVEf6g X-Received: by 2002:a0d:e10c:: with SMTP id k12mr28107412ywe.353.1556125312697; Wed, 24 Apr 2019 10:01:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556125312; cv=none; d=google.com; s=arc-20160816; b=HtIb9MshckJlHb3wqgbgh6xRzoF8xt28mCFW3sI/64KXg0/06zA40wxdFD/prDjiYo bDCW8LARAk1Yp91QzkGdmPkLf5TzHX/Z56KH/ncahohadSrYlGcY2tIc5/qNnzhisbFb gKV2BhayP2ZN8CKhM0TPGRxXDmybFJzcV8veGJy4C7U/vb8D8gjbBLa1iYa0vTxvzLD3 WoGDtFLf1sWSW/A/dk//HzKmpVK0jj/4DGsMbn67lFmkQ5xuWpko6BrBnJ7jXwWqXAsy BnqaRkpTcbDbKX0hhU2lzVpX0tvSr2de9wPS1BtyOpa4HL/XAPyzBu9jIv0R+AY+tA4S +Atg== 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=kGVrH3Kn+5uS2Ad5pkgcMxLuMSOBZq7zhjVLK9j1V3c=; b=EzCowqer5+DcKZBXlD9Dum6lL0vM/MgNwl1DaWaRA2wBm3QUdBOKRaJdjRy5F/cDAI 9MwgkuS1W/bYF5DqB5GVhDBjkS1tY1gHcEgW5e74i1Wsae5lCq0AgM7+sMeT4QMF+bIB Mx53CGeeZUoPbbl/PDOxJM8K1e5vqY5osgYygTVQ7mWMbOD2Hre+vgHDN45CVzVjbP3I 3YzGf4irbuFKRTwF0OA6ALbHXts2k9eS/L+GTRAAnaSgaXH3YeXs7FfPrlxttHAwAqIS dJFF0X1nvhC0jZkJeT8E/YDIT/eSD/MYY6bF+WWZe8Ta+iQmw9V2HqwQd39EkzKjz7vq abrQ== 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 u188si13144927ywb.220.2019.04.24.10.01.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 10:01:52 -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 1hJLFu-0007qj-Bt; Wed, 24 Apr 2019 17:00:22 +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 1hJLFs-0007pn-QE for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:20 +0000 X-Inumbo-ID: 70fe5c76-66b2-11e9-a695-fff1a3e162a4 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 70fe5c76-66b2-11e9-a695-fff1a3e162a4; Wed, 24 Apr 2019 17:00:19 +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 9609115BE; Wed, 24 Apr 2019 10:00:19 -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 7B9DD3F557; Wed, 24 Apr 2019 10:00:18 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:54 +0100 Message-Id: <20190424165955.23718-12-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 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 , sstabellini@kernel.org, Andrii_Anisov@epam.com 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 --- 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 022967ff9f..7e6df9f877 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -343,19 +343,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 Wed Apr 24 16:59:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 162788 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp895677jan; Wed, 24 Apr 2019 10:01:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxEWkwIDV3qi66Ycn1zVn7upXomfvIotUFPR2Ee6be430hDdyK4IPNRecxkH+oE72hKmbJY X-Received: by 2002:a25:d6cc:: with SMTP id n195mr27504041ybg.516.1556125313420; Wed, 24 Apr 2019 10:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556125313; cv=none; d=google.com; s=arc-20160816; b=Dn0gnxvQtfIenQULvzFgCUqTUhvLVr/hJRLQCDdwIQZDJWXshGlCw1NQVl5BIgPwUQ 5F8uAckGcWwHWVGhSrPRefD1e5z4b23ICYMywXi2eP2BZlVYcEGI9eLqOBIwhnrOuWEG vchXEAzf5VUSrwBhnWEYABWcvmIEkb6fA0FuVCrMk2U7lgxjX+H6pELXfdaZ1YOGgWh4 axoIsM02J0QQB7H/Cq6W7A9p8hSRAeT5lsPbaTTdK+rxSh7r31RlM8MxW7a35hYmU8UI q5lmN8DyYqpZ+kbzrtLeY1CuYCQS72stzDVyIP8whuZQV75wENGjh24UcfO5Iyf2IGV5 zNVQ== 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=NlbK9HPyMEbbgtBdlomy8/Y3Jhvfacl6cJjNdD5yKCw=; b=PGhYEBGhUITh6B3V+bAthvu/aLbGs0jl09CNHAoSN5nFC72grfqrsyRDWzmX2Y/SIb OHHHorRIgFkpL93iXKP82w+l5F+29R59d/zrSvhRu9KFyUBra5SzmYURoy0yQLpRoo5F hhDlF+H2wdzkmlo4bE6MAp2kGw2XpLJIr4gtgA/FMh7ZnsC4DXB9wcgPoMZ2nosBAyoS IEztHRWrdvsP4Q+zNkSOdbw7x1X9oEzZiGTREMbPSbRtoh0+cdsv614RrB5D118iH/qN iq4gSHUT7MoNIepZTi1Nd7KNfOAmib9fuFNILVcbGy8m2YwcbP5Ch9NbjG7Px8si9RW7 V7rQ== 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 126si5894942yby.399.2019.04.24.10.01.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 10:01:53 -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 1hJLFu-0007qw-Ma; Wed, 24 Apr 2019 17:00:22 +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 1hJLFu-0007qV-22 for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:22 +0000 X-Inumbo-ID: 71db77c8-66b2-11e9-9fa8-dfc6e70f8e3d Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 71db77c8-66b2-11e9-9fa8-dfc6e70f8e3d; Wed, 24 Apr 2019 17:00:21 +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 F1477374; Wed, 24 Apr 2019 10:00:20 -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 D6D073F557; Wed, 24 Apr 2019 10:00:19 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:55 +0100 Message-Id: <20190424165955.23718-13-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 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 , sstabellini@kernel.org, Andrii_Anisov@epam.com 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 --- 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 7e6df9f877..5810d569ee 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1272,52 +1272,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) { @@ -1326,8 +1280,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)", rc); /* * From now on, init will not be used for execution anymore, @@ -1345,7 +1303,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)", rc); + init_domheap_pages(pa, pa + len); printk("Freed %ldkB init memory.\n", (long)(__init_end-__init_begin)>>10); }