From patchwork Thu Oct 16 03:47:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 38795 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CFC9E20973 for ; Thu, 16 Oct 2014 03:50:55 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id b6sf1380952lbj.11 for ; Wed, 15 Oct 2014 20:50:54 -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=li/UV9oWEC1ccrQOwvDSQWelwRrERHu/ncL6Mr7IRTI=; b=h76h7MLUw2lpMuxzi+unWe7MyeczQTpiSR0UrhObBSLS4k7PCBLtTI8f6hnJZUOtuG S/Eo8IubGDq4D26pTaTvbtmtpqNsG6XmDPhE4XEJwxMSdLT4jo09bexX5kH6tgRiw5jb VNi001VVMopUnZntMC9h3xKb9Pn86SG7cho8BjGxX1qi137UQ4Ou08wOjid0fK4t/5lR zRd1CN22hBqWWH0CYZE7hgpA26yzn/AE0QlrwUV49pzFNCw76hHVocU2uTHHvjiuiw87 WKCkT7SYRs7rcXLJii3E8i5DgQ1p/y/hpZXJ1Yb+n/bQ0+bs6uRRKIT4B2OXx58fn0jA S/xA== X-Gm-Message-State: ALoCoQkzbMCvQdflqpc0mHae0Dw8286p+N6eXiCkh/vc/8wh/rhkbYG60sQHNU3La+Pw7XhY/xLI X-Received: by 10.112.99.72 with SMTP id eo8mr2833675lbb.7.1413431454218; Wed, 15 Oct 2014 20:50:54 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.45.101 with SMTP id l5ls104785lam.103.gmail; Wed, 15 Oct 2014 20:50:54 -0700 (PDT) X-Received: by 10.152.116.68 with SMTP id ju4mr16541720lab.13.1413431454003; Wed, 15 Oct 2014 20:50:54 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com [209.85.217.178]) by mx.google.com with ESMTPS id lj3si25588673lab.112.2014.10.15.20.50.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 Oct 2014 20:50:53 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by mail-lb0-f178.google.com with SMTP id w7so2112412lbi.37 for ; Wed, 15 Oct 2014 20:50:53 -0700 (PDT) X-Received: by 10.152.243.8 with SMTP id wu8mr16510008lac.21.1413431453832; Wed, 15 Oct 2014 20:50:53 -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 c5csp728625lbz; Wed, 15 Oct 2014 20:50:53 -0700 (PDT) X-Received: by 10.221.37.3 with SMTP id tc3mr16215156vcb.29.1413431452435; Wed, 15 Oct 2014 20:50:52 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id rw5si3284972vcb.14.2014.10.15.20.50.51 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 15 Oct 2014 20:50:52 -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 1Xec3L-0001EM-4s; Thu, 16 Oct 2014 03:48:39 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Xec3J-0001EH-59 for xen-devel@lists.xen.org; Thu, 16 Oct 2014 03:48:37 +0000 Received: from [85.158.143.35] by server-3.bemta-4.messagelabs.com id 8F/8B-02699-4104F345; Thu, 16 Oct 2014 03:48:36 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-8.tower-21.messagelabs.com!1413431313!13247357!1 X-Originating-IP: [209.85.220.43] 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 7452 invoked from network); 16 Oct 2014 03:48:35 -0000 Received: from mail-pa0-f43.google.com (HELO mail-pa0-f43.google.com) (209.85.220.43) by server-8.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 16 Oct 2014 03:48:35 -0000 Received: by mail-pa0-f43.google.com with SMTP id lf10so2597382pab.30 for ; Wed, 15 Oct 2014 20:48:33 -0700 (PDT) X-Received: by 10.70.38.232 with SMTP id j8mr17638496pdk.44.1413431313558; Wed, 15 Oct 2014 20:48:33 -0700 (PDT) Received: from rfranz-i7.local (c-24-10-97-91.hsd1.ca.comcast.net. [24.10.97.91]) by mx.google.com with ESMTPSA id rz8sm18345550pbc.63.2014.10.15.20.48.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Oct 2014 20:48:32 -0700 (PDT) From: Roy Franz To: xen-devel@lists.xen.org, ian.campbell@citrix.com, stefano.stabellini@citrix.com, tim@xen.org, jbeulich@suse.com, keir@xen.org Date: Wed, 15 Oct 2014 20:47:59 -0700 Message-Id: <1413431279-17559-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 V2 for-4.5] 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.178 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 Tested-by: Suravee Suthikulpanit --- 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 | 30 +++++++++++++--- 2 files changed, 46 insertions(+), 73 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..85dd37a 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -740,16 +740,36 @@ ENTRY(lookup_processor_type) */ 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 */ + mov x1, 0x200000 /* max size of FDT allowed */ + 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