From patchwork Tue May 22 17:42:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 136589 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1929458lji; Tue, 22 May 2018 10:45:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqo7X05rD69Y1F5KUzP+TXkGv7QUXQu0ZIYpQ/GcaBKGkTk+DrX07Fsg8nMmflwSbqXk9lg X-Received: by 2002:a6b:9403:: with SMTP id w3-v6mr25113257iod.189.1527011143183; Tue, 22 May 2018 10:45:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527011143; cv=none; d=google.com; s=arc-20160816; b=V+vTQg/c1xatFKv4Da2F5/z0rW0aqWNIaRtsdWi84QmGyTej7sRSg6Mm4z5yBoCajO fj0Ze8OhAoEHwSongmsORZMM9aIwskXslFyGK6zcGLDKEjsqMQcpsHWqUw5w1N5PfNkQ C1IIx7YKZnU6Dagyufq9Y0FQ9nlWig59Naa8n/QhLwS18ht0coaMh7PCYa3y4JuU1Epk exoOCuHg9gWpwFpea2Dl6tp43Mz7CbeRrTowUIBW+wOu4HOBSrtl4gZjfF6duTBX9fML 1envfdMHYKrFp437/vqw0sJZU0wbc2MgQh8g2zzjZkkr/GMtFughQHYTY4+Ic2T01c4d IBqQ== 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 :arc-authentication-results; bh=PNv0UWfxrwheAwVaHNga40EUV0Hd8oROgm7ICHF4Upg=; b=SLnHRIMQxQaCOxaxt+w5XyoFzfUTb7tjjwlCNaaGX7vJbjKj0dSSZumIrY5VBw/JsX XG9sweJ2k78HKEJ5wX/ikP0guWDe3CgFGUXj2ad6TSrnxCN7xkMFrbywJ/VPdlaEPiok c8AEhunfVSLLPEQ1gXh6dOrX/IoIYC992YYEucylmHrFkUFglLrJAbLaVwajhngVqAHF N3YNBK9TzyC3suaYQ9DnsW0wIlh0ndZdHso7CcH4/GUFoqJ8mzXfLHacyogCjqKuD3QV QXH+/E6Ye3W18j9YRb0gZf+qf+Sb6Qe9b3tSZ9OCw2ncNXJk5OZQoH2Dfd2Ps5PRvrx3 dJ0w== 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 m188-v6si348144ite.70.2018.05.22.10.45.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 May 2018 10:45: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 1fLBJa-0002As-FI; Tue, 22 May 2018 17:43:14 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1fLBJZ-0002Ab-60 for xen-devel@lists.xenproject.org; Tue, 22 May 2018 17:43:13 +0000 X-Inumbo-ID: 18e2a356-5de8-11e8-8249-2fda3a446a53 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id 18e2a356-5de8-11e8-8249-2fda3a446a53; Tue, 22 May 2018 17:46: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 269AB1435; Tue, 22 May 2018 10:43:12 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3C8443F589; Tue, 22 May 2018 10:43:11 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 22 May 2018 18:42:48 +0100 Message-Id: <20180522174254.27551-8-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180522174254.27551-1-julien.grall@arm.com> References: <20180522174254.27551-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 07/13] xen/arm: Simplify alternative patching 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: andre.przywara@arm.com, Julien Grall , sstabellini@kernel.org MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This is part of XSA-263. Signed-off-by: Julien Grall --- I am aware of the missing commit message here. I wanted to send the series on the ML to get some feedback first. --- xen/arch/arm/alternative.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c index 9ffdc475d6..bd62183def 100644 --- a/xen/arch/arm/alternative.c +++ b/xen/arch/arm/alternative.c @@ -97,12 +97,16 @@ static u32 get_alt_insn(const struct alt_instr *alt, /* * The region patched should be read-write to allow __apply_alternatives * to replacing the instructions when necessary. + * + * @update_offset: Offset between the region patched and the writable + * region for the update. 0 if the patched region is writable. */ -static int __apply_alternatives(const struct alt_region *region) +static int __apply_alternatives(const struct alt_region *region, + paddr_t update_offset) { const struct alt_instr *alt; - const u32 *replptr; - u32 *origptr; + const u32 *replptr, *origptr; + u32 *updptr; printk(XENLOG_INFO "alternatives: Patching with alt table %p -> %p\n", region->begin, region->end); @@ -118,6 +122,7 @@ static int __apply_alternatives(const struct alt_region *region) BUG_ON(alt->alt_len != alt->orig_len); origptr = ALT_ORIG_PTR(alt); + updptr = (void *)origptr + update_offset; replptr = ALT_REPL_PTR(alt); nr_inst = alt->alt_len / sizeof(insn); @@ -125,7 +130,7 @@ static int __apply_alternatives(const struct alt_region *region) for ( i = 0; i < nr_inst; i++ ) { insn = get_alt_insn(alt, origptr + i, replptr + i); - *(origptr + i) = cpu_to_le32(insn); + *(updptr + i) = cpu_to_le32(insn); } /* Ensure the new instructions reached the memory and nuke */ @@ -162,9 +167,6 @@ static int __apply_alternatives_multi_stop(void *unused) paddr_t xen_size = _end - _start; unsigned int xen_order = get_order_from_bytes(xen_size); void *xenmap; - struct virtual_region patch_region = { - .list = LIST_HEAD_INIT(patch_region.list), - }; BUG_ON(patched); @@ -178,30 +180,19 @@ static int __apply_alternatives_multi_stop(void *unused) BUG_ON(!xenmap); /* - * If we generate a new branch instruction, the target will be - * calculated in this re-mapped Xen region. So we have to register - * this re-mapped Xen region as a virtual region temporarily. - */ - patch_region.start = xenmap; - patch_region.end = xenmap + xen_size; - register_virtual_region(&patch_region); - - /* * Find the virtual address of the alternative region in the new * mapping. * alt_instr contains relative offset, so the function * __apply_alternatives will patch in the re-mapped version of * Xen. */ - region.begin = (void *)__alt_instructions - (void *)_start + xenmap; - region.end = (void *)__alt_instructions_end - (void *)_start + xenmap; + region.begin = __alt_instructions; + region.end = __alt_instructions_end; - ret = __apply_alternatives(®ion); + ret = __apply_alternatives(®ion, xenmap - (void *)_start); /* The patching is not expected to fail during boot. */ BUG_ON(ret != 0); - unregister_virtual_region(&patch_region); - vunmap(xenmap); /* Barriers provided by the cache flushing */ @@ -235,7 +226,7 @@ int apply_alternatives(const struct alt_instr *start, const struct alt_instr *en .end = end, }; - return __apply_alternatives(®ion); + return __apply_alternatives(®ion, 0); } /*