From patchwork Tue Oct 21 03:55:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 39090 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 131C4203C5 for ; Tue, 21 Oct 2014 03:58:02 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id a1sf219957wgh.1 for ; Mon, 20 Oct 2014 20:58:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:cc:subject :precedence:list-id:list-unsubscribe:list-post:list-help :list-subscribe:mime-version:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive :content-type:content-transfer-encoding; bh=O0FJm+Zgr1kLIKLN4tfc97/dtbQKcTbdeEJXJ5hAjm8=; b=cWwt8jo4OpEUcF72QUzxoDamZi1Mef/5lJReUMpVHXHNbDZr8dJZQbVnyoBoslTPZS o0rKI/KR4EoZvs7JWYci5fA/SIil0O/eqENXPvg5zOl8khYV7kKWflhWMvrHfmSrrZ7D psmkxFzKbNntyy9p8Vk0Vhva56RrbpDwAjxY2QNNyNGhKXYOKlPvNlA65TrEOU7qWX99 tiIL0w26icyFmf0UWc5iRWN2i1XA94xauu4KDWtat2tO2fU7evLpr5DntFaN73fSYnZu pfA3y5zAkTb++yxZ/Ub96wgAMR0yDhZKvuZ9Jsau24cULwoLTP+X8p67bltrU7OFJf+B Bamw== X-Gm-Message-State: ALoCoQnzcOlQ1uZFx2XGeDG33jkXl+/kIsrnTjpFug/ES/b6f+G2iWlR8n/fo+Bh7mFPiXVTbrE+ X-Received: by 10.180.76.42 with SMTP id h10mr3102050wiw.6.1413863882296; Mon, 20 Oct 2014 20:58:02 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.26.72 with SMTP id j8ls8420lag.105.gmail; Mon, 20 Oct 2014 20:58:02 -0700 (PDT) X-Received: by 10.112.133.138 with SMTP id pc10mr31769486lbb.48.1413863882134; Mon, 20 Oct 2014 20:58:02 -0700 (PDT) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id jo7si9050885lbc.39.2014.10.20.20.58.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 20 Oct 2014 20:58:02 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id l4so267751lbv.26 for ; Mon, 20 Oct 2014 20:58:02 -0700 (PDT) X-Received: by 10.112.167.38 with SMTP id zl6mr31504906lbb.34.1413863881920; Mon, 20 Oct 2014 20:58:01 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp427355lbz; Mon, 20 Oct 2014 20:58:01 -0700 (PDT) X-Received: by 10.140.91.73 with SMTP id y67mr39308708qgd.52.1413863880371; Mon, 20 Oct 2014 20:58:00 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id 64si19809346qgy.68.2014.10.20.20.57.59 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 20 Oct 2014 20:58:00 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XgQXy-000203-RF; Tue, 21 Oct 2014 03:55:46 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XgQXx-0001zy-EY for xen-devel@lists.xen.org; Tue, 21 Oct 2014 03:55:45 +0000 Received: from [193.109.254.147:11549] by server-11.bemta-14.messagelabs.com id EF/14-14213-049D5445; Tue, 21 Oct 2014 03:55:44 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-9.tower-27.messagelabs.com!1413863742!11921628!1 X-Originating-IP: [209.85.216.48] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 6.12.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 19587 invoked from network); 21 Oct 2014 03:55:43 -0000 Received: from mail-qa0-f48.google.com (HELO mail-qa0-f48.google.com) (209.85.216.48) by server-9.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 21 Oct 2014 03:55:43 -0000 Received: by mail-qa0-f48.google.com with SMTP id dc16so267366qab.21 for ; Mon, 20 Oct 2014 20:55:42 -0700 (PDT) X-Received: by 10.140.19.9 with SMTP id 9mr40026769qgg.46.1413863742289; Mon, 20 Oct 2014 20:55:42 -0700 (PDT) Received: from rfranz-v430.caveonetworks.com (64.2.3.195.ptr.us.xo.net. [64.2.3.195]) by mx.google.com with ESMTPSA id 8sm9731830qab.12.2014.10.20.20.55.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Oct 2014 20:55:41 -0700 (PDT) From: Roy Franz To: xen-devel@lists.xen.org, ian.campbell@citrix.com, stefano.stabellini@citrix.com, tim@xen.org Date: Mon, 20 Oct 2014 20:55:25 -0700 Message-Id: <1413863725-27630-1-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 1.9.1 Cc: Roy Franz , Suravee Suthikulpanit , fu.wei@linaro.org Subject: [Xen-devel] [PATCH] xen/arm64: Use __flush_dcache_area instead of __flush_dcache_all X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: roy.franz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: From: Suravee Suthikulpanit When booting with EFI, __flush_dcache_all does not correctly flush data. According to Mark Rutland, __flush_dcache_all is not guaranteed to push data to the PoC if there is a system-level cache as it uses Set/Way operations. Therefore, this patch switchs to use the "__flush_dcache_area" mechanism, which is coppied from Linux. Add flushing of FDT in addition to Xen text/data. Remove now unused __flush_dcache_all and related helper functions. Invalidate the instruction tlb before turning on paging later on when starting Xen in EL2. Signed-off-by: Suravee Suthikulpanit Signed-off-by: Roy Franz Acked-by: Ian Campbell --- Changes since v2: * Pass FDT size to efi_xen_start, flush exact FDT size rather than max FDT size. (Max size could extend past end of DRAM.) Changes since v1: * Added flushing of FDT memory region * Remove used __flush_dcache_all function, and related helper functions * Fix typo in comment * Properly set base address in __flush_dcache_area call. * Add flush of instruction TLB xen/arch/arm/arm64/cache.S | 89 +++++++++++---------------------------------- xen/arch/arm/arm64/head.S | 31 +++++++++++++--- xen/arch/arm/efi/efi-boot.h | 4 +- 3 files changed, 48 insertions(+), 76 deletions(-) diff --git a/xen/arch/arm/arm64/cache.S b/xen/arch/arm/arm64/cache.S index a445cbf..eff4e16 100644 --- a/xen/arch/arm/arm64/cache.S +++ b/xen/arch/arm/arm64/cache.S @@ -20,80 +20,33 @@ */ /* - * Enable and disable interrupts. + * dcache_line_size - get the minimum D-cache line size from the CTR register. */ - .macro disable_irq - msr daifset, #2 - .endm - - .macro enable_irq - msr daifclr, #2 - .endm - -/* - * Save/disable and restore interrupts. - */ - .macro save_and_disable_irqs, olddaif - mrs \olddaif, daif - disable_irq - .endm - - .macro restore_irqs, olddaif - msr daif, \olddaif + .macro dcache_line_size, reg, tmp + mrs \tmp, ctr_el0 // read CTR + ubfm \tmp, \tmp, #16, #19 // cache line size encoding + mov \reg, #4 // bytes per word + lsl \reg, \reg, \tmp // actual cache line size .endm /* - * __flush_dcache_all() + * __flush_dcache_area(kaddr, size) * - * Flush the whole D-cache. + * Ensure that the data held in the page kaddr is written back to the + * page in question. * - * Corrupted registers: x0-x7, x9-x11 + * - kaddr - kernel address + * - size - size in question */ -ENTRY(__flush_dcache_all) - dmb sy // ensure ordering with previous memory accesses - mrs x0, clidr_el1 // read clidr - and x3, x0, #0x7000000 // extract loc from clidr - lsr x3, x3, #23 // left align loc bit field - cbz x3, finished // if loc is 0, then no need to clean - mov x10, #0 // start clean at cache level 0 -loop1: - add x2, x10, x10, lsr #1 // work out 3x current cache level - lsr x1, x0, x2 // extract cache type bits from clidr - and x1, x1, #7 // mask of the bits for current cache only - cmp x1, #2 // see what cache we have at this level - b.lt skip // skip if no cache, or just i-cache - save_and_disable_irqs x9 // make CSSELR and CCSIDR access atomic - msr csselr_el1, x10 // select current cache level in csselr - isb // isb to sych the new cssr&csidr - mrs x1, ccsidr_el1 // read the new ccsidr - restore_irqs x9 - and x2, x1, #7 // extract the length of the cache lines - add x2, x2, #4 // add 4 (line length offset) - mov x4, #0x3ff - and x4, x4, x1, lsr #3 // find maximum number on the way size - clz w5, w4 // find bit position of way size increment - mov x7, #0x7fff - and x7, x7, x1, lsr #13 // extract max number of the index size -loop2: - mov x9, x4 // create working copy of max way size -loop3: - lsl x6, x9, x5 - orr x11, x10, x6 // factor way and cache number into x11 - lsl x6, x7, x2 - orr x11, x11, x6 // factor index number into x11 - dc cisw, x11 // clean & invalidate by set/way - subs x9, x9, #1 // decrement the way - b.ge loop3 - subs x7, x7, #1 // decrement the index - b.ge loop2 -skip: - add x10, x10, #2 // increment cache number - cmp x3, x10 - b.gt loop1 -finished: - mov x10, #0 // swith back to cache level 0 - msr csselr_el1, x10 // select current cache level in csselr +ENTRY(__flush_dcache_area) + dcache_line_size x2, x3 + add x1, x0, x1 + sub x3, x2, #1 + bic x0, x0, x3 +1: dc civac, x0 // clean & invalidate D line / unified line + add x0, x0, x2 + cmp x0, x1 + b.lo 1b dsb sy - isb ret -ENDPROC(__flush_dcache_all) +ENDPROC(__flush_dcache_area) diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index 7650abe..9379dd1 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -736,20 +736,39 @@ ENTRY(lookup_processor_type) ret /* * Function to transition from EFI loader in C, to Xen entry point. - * void noreturn efi_xen_start(void *fdt_ptr); + * void noreturn efi_xen_start(void *fdt_ptr, uint32_t fdt_size); */ ENTRY(efi_xen_start) /* + * Preserve x0 (fdt pointer) across call to __flush_dcache_area, + * restore for entry into Xen. + */ + mov x20, x0 + + /* flush dcache covering the FDT updated by EFI boot code */ + bl __flush_dcache_area + + /* + * Flush dcache covering current runtime addresses + * of xen text/data. Then flush all of icache. + */ + adrp x1, _start + add x1, x1, #:lo12:_start + mov x0, x1 + adrp x2, _end + add x2, x2, #:lo12:_end + sub x1, x2, x1 + + bl __flush_dcache_area + ic ialluis + tlbi alle2 + + /* * Turn off cache and MMU as Xen expects. EFI enables them, but also * mandates a 1:1 (unity) VA->PA mapping, so we can turn off the * MMU while executing EFI code before entering Xen. * The EFI loader calls this to start Xen. - * Preserve x0 (fdf pointer) across call to __flush_dcache_all, - * restore for entry into Xen. */ - mov x20, x0 - bl __flush_dcache_all - ic ialluis /* Turn off Dcache and MMU */ mrs x0, sctlr_el2 diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h index 7abc059..d40d8b2 100644 --- a/xen/arch/arm/efi/efi-boot.h +++ b/xen/arch/arm/efi/efi-boot.h @@ -7,7 +7,7 @@ #include #include -void noreturn efi_xen_start(void *fdt_ptr); +void noreturn efi_xen_start(void *fdt_ptr, uint32_t fdt_size); #define DEVICE_TREE_GUID \ {0xb1b621d5, 0xf19c, 0x41a5, {0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0}} @@ -343,7 +343,7 @@ static void __init efi_arch_pre_exit_boot(void) static void __init efi_arch_post_exit_boot(void) { - efi_xen_start(fdt); + efi_xen_start(fdt, fdt_totalsize(fdt)); } static void __init efi_arch_cfg_file_early(EFI_FILE_HANDLE dir_handle, char *section)