From patchwork Thu Jan 28 18:12:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kani, Toshi" X-Patchwork-Id: 8153051 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 30A45BEEE5 for ; Thu, 28 Jan 2016 18:14:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5D8392034C for ; Thu, 28 Jan 2016 18:14:01 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8010720364 for ; Thu, 28 Jan 2016 18:14:00 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 75F6B1A22ED; Thu, 28 Jan 2016 10:14:00 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from g4t3425.houston.hp.com (g4t3425.houston.hp.com [15.201.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2D9731A2309 for ; Thu, 28 Jan 2016 10:13:59 -0800 (PST) Received: from g9t2301.houston.hp.com (g9t2301.houston.hp.com [16.216.185.78]) by g4t3425.houston.hp.com (Postfix) with ESMTP id 3498F4D; Thu, 28 Jan 2016 18:13:58 +0000 (UTC) Received: from misato.fc.hp.com (misato.fc.hp.com [16.78.168.61]) by g9t2301.houston.hp.com (Postfix) with ESMTP id 4BC8F53; Thu, 28 Jan 2016 18:13:57 +0000 (UTC) From: Toshi Kani To: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, bp@suse.de, dan.j.williams@intel.com Subject: [PATCH 2/2] pmem: Flush cache on unaligned request Date: Thu, 28 Jan 2016 11:12:50 -0700 Message-Id: <1454004770-6318-3-git-send-email-toshi.kani@hpe.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1454004770-6318-1-git-send-email-toshi.kani@hpe.com> References: <1454004770-6318-1-git-send-email-toshi.kani@hpe.com> Cc: linux-nvdimm@lists.01.org, x86@kernel.org, linux-kernel@vger.kernel.org, micah.parrish@hpe.com, brian.boylston@hpe.com X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP arch_memcpy_to_pmem() calls __copy_user_nocache() to copy data via non-temporal stores. However, __copy_user_nocache() still performs cached copy when a request is not naturally aligned or is less then 4 bytes. Call clflush_cache_range() to flush destination when a request leads to cached copy. Signed-off-by: Toshi Kani Cc: Thomas Gleixner Cc: Ingo Molnar Cc: H. Peter Anvin Cc: Borislav Petkov Cc: Dan Williams Cc: Ross Zwisler Cc: Vishal Verma --- arch/x86/include/asm/pmem.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/include/asm/pmem.h b/arch/x86/include/asm/pmem.h index c57fd1e..f135064 100644 --- a/arch/x86/include/asm/pmem.h +++ b/arch/x86/include/asm/pmem.h @@ -45,6 +45,17 @@ static inline void arch_memcpy_to_pmem(void __pmem *dst, const void *src, if (WARN(unwritten, "%s: fault copying %p <- %p unwritten: %d\n", __func__, dst, src, unwritten)) BUG(); + + /* + * Flush the caches when the request is not naturally aligned. + * Non-temporal stores are not used for unaligned copy. + */ + if (((n >= 8) && + (!IS_ALIGNED((unsigned long)dst, 8) || !IS_ALIGNED(n, 8))) || + ((n < 8) && + (!IS_ALIGNED((unsigned long)dst, 4) || (n != 4)))) { + clflush_cache_range(dst, n); + } } /**