From patchwork Tue Mar 24 19:15:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 46281 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A22F321596 for ; Tue, 24 Mar 2015 19:16:13 +0000 (UTC) Received: by wibbs8 with SMTP id bs8sf1110727wib.3 for ; Tue, 24 Mar 2015 12:16:12 -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:reply-to:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:x-original-sender :x-original-authentication-results:mailing-list; bh=ySg0wTCEw6zNh+k54nH60g0Da8b7kWUhobLnl8i8/Ns=; b=llyd2375AQtv7lr3t6pdaIP+tqme421SSsB+9l0bT7wYrjO7lmmE6dHNvp4efOKYJV BD1lEB+Q8ryFqFg2krQR3pX7jBxbxSwz+TfWQmyMzNuJZQIErsqbRqVdtsXTobQe5QsF rNmi+OTgoT0/cBcQ/0oBR9kfhEGnIaIkLTGw3xfMA2UIw7oqs9xZwY/SIjs7KM6z3+UE 9o5VFt8+uBgqpvzAeKPudK9lEgUxVwYmGjkJNM84Xo7RhFHnPKdO6x3HQwNoh1bgyDQa XTvXmwAEp5t199aQR9VJOS/BbL1Ip0kCL3HwbDrqzus5RpgzOQhxviMWiAq3E0Aeg3cC wAsA== X-Gm-Message-State: ALoCoQm0mbE995YOhBPKSJ9CZzT09TOR7quoLrozUfNrsQOZr0JGKfRzMMBEsXiibytNH1g7vqZT X-Received: by 10.152.88.33 with SMTP id bd1mr1237005lab.2.1427224572880; Tue, 24 Mar 2015 12:16:12 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.36 with SMTP id n4ls8711laj.27.gmail; Tue, 24 Mar 2015 12:16:12 -0700 (PDT) X-Received: by 10.112.219.196 with SMTP id pq4mr5108963lbc.104.1427224572735; Tue, 24 Mar 2015 12:16:12 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id od8si130916lbc.43.2015.03.24.12.16.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Mar 2015 12:16:12 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbbsy1 with SMTP id sy1so1917262lbb.1 for ; Tue, 24 Mar 2015 12:16:12 -0700 (PDT) X-Received: by 10.152.5.225 with SMTP id v1mr4993418lav.76.1427224572580; Tue, 24 Mar 2015 12:16:12 -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.57.201 with SMTP id k9csp1648010lbq; Tue, 24 Mar 2015 12:16:11 -0700 (PDT) X-Received: by 10.42.77.4 with SMTP id g4mr27465061ick.17.1427224570267; Tue, 24 Mar 2015 12:16:10 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id o77si167396ioi.30.2015.03.24.12.16.09 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 24 Mar 2015 12:16:10 -0700 (PDT) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1YaUIx-0003YW-60; Tue, 24 Mar 2015 19:15:59 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1YaUIw-0003YO-Nn for edk2-devel@lists.sourceforge.net; Tue, 24 Mar 2015 19:15:58 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of linaro.org designates 209.85.212.179 as permitted sender) client-ip=209.85.212.179; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wi0-f179.google.com; Received: from mail-wi0-f179.google.com ([209.85.212.179]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1YaUIu-0000Xb-Nl for edk2-devel@lists.sourceforge.net; Tue, 24 Mar 2015 19:15:58 +0000 Received: by wibgn9 with SMTP id gn9so6928578wib.1 for ; Tue, 24 Mar 2015 12:15:50 -0700 (PDT) X-Received: by 10.180.20.144 with SMTP id n16mr30609610wie.44.1427224550726; Tue, 24 Mar 2015 12:15:50 -0700 (PDT) Received: from ards-macbook-pro.local ([90.174.5.10]) by mx.google.com with ESMTPSA id eo1sm824517wib.16.2015.03.24.12.15.48 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 24 Mar 2015 12:15:49 -0700 (PDT) From: Ard Biesheuvel To: lersek@redhat.com, ian.campbell@citrix.com, julien.grall@linaro.org, edk2-devel@lists.sourceforge.net Date: Tue, 24 Mar 2015 20:15:42 +0100 Message-Id: <1427224544-29955-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1YaUIu-0000Xb-Nl Cc: stefano.stabellini@eu.citrix.com Subject: [edk2] [PATCH 1/3] Ovmf: XenConsoleSerialPortLib: add explicit cache maintenance X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@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.170 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 This library may be used with the caches and MMU off, while the hypervisor has the caches enabled. So add explicit cache maintenance to deal with the potential incoherency. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- .../XenConsoleSerialPortLib.c | 29 ++++++++++++++++++++++ .../XenConsoleSerialPortLib.inf | 1 + 2 files changed, 30 insertions(+) diff --git a/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c b/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c index 467cb27a30c4..17d5a5a38d30 100644 --- a/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c +++ b/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -80,6 +81,13 @@ SerialPortWrite ( return 0; } + // + // We may be accessing DRAM directly, while the hypervisor has the caches + // enabled. This means we have to force a writeback to ensure that we have + // the latest data. + // + WriteBackDataCacheRange (mXenConsoleInterface, sizeof(*mXenConsoleInterface)); + Consumer = mXenConsoleInterface->out_cons; Producer = mXenConsoleInterface->out_prod; @@ -93,6 +101,13 @@ SerialPortWrite ( mXenConsoleInterface->out_prod = Producer; + // + // Ensure that the data cache is invalidated after we have written our data. + // This ensures that the hypervisor will have to fetch the value from DRAM, + // which may be where the data is if we are running with the MMU off. + // + InvalidateDataCacheRange (mXenConsoleInterface, sizeof(*mXenConsoleInterface)); + if (Sent > 0) { XenHypercallEventChannelOp (EVTCHNOP_send, &mXenConsoleEventChain); } @@ -124,6 +139,13 @@ SerialPortRead ( return 0; } + // + // We may be accessing DRAM directly, while the hypervisor has the caches + // enabled. This means we have to force a writeback to ensure that we have + // the latest data. + // + WriteBackDataCacheRange (mXenConsoleInterface, sizeof(*mXenConsoleInterface)); + Consumer = mXenConsoleInterface->in_cons; Producer = mXenConsoleInterface->in_prod; @@ -137,6 +159,13 @@ SerialPortRead ( mXenConsoleInterface->in_cons = Consumer; + // + // Ensure that the data cache is invalidated after we have written our data. + // This ensures that the hypervisor will have to fetch the value from DRAM, + // which may be where the data is if we are running with the MMU off. + // + InvalidateDataCacheRange (mXenConsoleInterface, sizeof(*mXenConsoleInterface)); + XenHypercallEventChannelOp (EVTCHNOP_send, &mXenConsoleEventChain); return Received; diff --git a/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf b/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf index 8a7411558fa3..2fd1c654be78 100644 --- a/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf +++ b/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf @@ -29,6 +29,7 @@ [LibraryClasses] BaseLib XenHypercallLib + CacheMaintenanceLib [Packages] MdePkg/MdePkg.dec