Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp427328imm; Tue, 3 Jul 2018 22:57:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe8Enwr7fYgCj2DVHfRpObUGc7/Hl1WbYgDGyWV/qiaDj0eyrzr/j/x8k3htGRdb2wW2p9w X-Received: by 2002:a17:902:aa01:: with SMTP id be1-v6mr725858plb.296.1530683825534; Tue, 03 Jul 2018 22:57:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530683825; cv=none; d=google.com; s=arc-20160816; b=wIlCLJkB4RTCIZ/eiTO6Pl1IeECZzWZTFF6n7acxyUxc1qbs+Oo3sinouxb2JQkpGq c/PYs/08l/Bc8+Kdg8j5ZsscalQ0PhG6mKwQMV7BITZtzJFb2iw7L7uW6Ha3Ez98C3jl kIKPh8h84n1Hzo27i/qQVXMrBTFjZ6rjqjyDVdzpFzGPq7/yxPzNjlbaqhJT21K3uRHx j/M7C/O1ELI02KH8IlDPs1+1MgVLCEL9aKZyB/K+Afn10sdrylT8xhlYNIgezwGQ7Xf6 dMqmLYqC/t4sTSXXW9AoO88WbBSyhw3Wyup3Y2OqE03u0ycn01I6aaxWP/IwDvXV+dda CjKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=BXOqITXyjXMUd8nX7tgw7dUzycTRww6JMPkIHTCu7k0=; b=WAuNZVsurFoHaGjL6xcvs5+bmb1Ko43z9cGlixJDzmYYrtUAMS5EYbVaChnevHzwEd JRofI3sMlNLkZzDbqraqLGXAWfj+uNeBu0cJRfal9FtvVoqRs+f7Pkn1Jg4yNuDj3kst G2n4IMCH9rDBfqk9KPxpprvHuz1dqmhNR+AS8AbLt85LF8lbfxFFk413GA7pdX9IX9BW 3bk8agZDepj6KuPpofMd0pgyXMvELJPn8gNEn8f0KOej1dkxtDYT5Sk1mNdNS51c0buu MhrjiVU0VRZChYL59vKVID16WTMQWGJSg8AC6KXyqu4qJdTh7E1GsR9HI430JHLfCKBl TLwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ku3LSpSE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d37-v6si2705230plb.481.2018.07.03.22.56.51; Tue, 03 Jul 2018 22:57:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ku3LSpSE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933390AbeGDFyo (ORCPT + 99 others); Wed, 4 Jul 2018 01:54:44 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:33051 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932643AbeGDFwg (ORCPT ); Wed, 4 Jul 2018 01:52:36 -0400 Received: by mail-pg0-f65.google.com with SMTP id e11-v6so2015368pgq.0 for ; Tue, 03 Jul 2018 22:52:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=BXOqITXyjXMUd8nX7tgw7dUzycTRww6JMPkIHTCu7k0=; b=ku3LSpSEG8mu8jl+j2VobLs4ECdAxg6sA1KpD2qC66SyNG4/VaFQJa4/OfaQv6Uz0q JRDsmaMZARUSPxX3bSjPPx/2fOimSU5QzDjCBhgG/QNvpXTJvLNe9QrYlbHQOBFbghl4 EoLlh6mKOIb9BUn16i4quS5kv/HRH/rvGPaf0KD1K0jEF24kiBuOZGmxqoZCPKOkz+AT HaLV7pLcZvwE6pYWdT25UogzOspk5YZo+Y1HxDHmJTjVLLFVkoJ/bbXk/Gzr4bwrXijl TDXmhRMQ6lNiaTu39xLMyqVWiCuVnrbP0WWUaeNG8RVzyj9OQUYfUQhCBKZsgnNtjemI +0aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BXOqITXyjXMUd8nX7tgw7dUzycTRww6JMPkIHTCu7k0=; b=LWLMZtEFjkeEKNwOM7ELOUmXxjXkPwYpIXD1ZMXUB7dXQcfc+wEaukPI/4WXivBJD4 G9cu1LqChHm0RLxg9bfK0QG//NgiUNT4g4CxMfOzGqIVp4RzgRfmG0fTvT5LX66HjHgW Hl/wOmu7WTZxs80G+SHA2PV1MvitzKCoOzehYFg5aKzM64a3mzHp8G18kvJcjddquz9L y2E/gYI9qcbORutZoJ162zBXULZAfbZzm80vh0+UMjQjoIccIVt3AtnD3iQkh+o6DtbV huWF7m0XpINSgrF7ec7V+bWVdF88vkvulT7+3orjvTob0nk7xC1ksdZxajrQgVOf4vKr lUcQ== X-Gm-Message-State: APt69E3WwXhb2/OTXFvxLZaaJAFHh5updVeWce/ea/ejpv7q6aHyCAxC G49Qolol/nL9Y4XWIJEsERA= X-Received: by 2002:a63:5421:: with SMTP id i33-v6mr619292pgb.417.1530683555919; Tue, 03 Jul 2018 22:52:35 -0700 (PDT) Received: from app09.andestech.com ([118.163.51.199]) by smtp.gmail.com with ESMTPSA id b22-v6sm4257226pfi.144.2018.07.03.22.52.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jul 2018 22:52:35 -0700 (PDT) From: Greentime Hu X-Google-Original-From: Greentime Hu To: greentime@andestech.com, linux-kernel@vger.kernel.org, ren_guo@c-sky.com Cc: green.hu@gmail.com Subject: [PATCH v2 1/3] nds32: To implement these icache invalidation APIs since nds32 cores don't snoop data cache. This issue is found by Guo Ren. Based on the Documentation/core-api/cachetlb.rst and it says: Date: Wed, 4 Jul 2018 13:52:08 +0800 Message-Id: X-Mailer: git-send-email 2.16.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "Any necessary cache flushing or other coherency operations that need to occur should happen here. If the processor's instruction cache does not snoop cpu stores, it is very likely that you will need to flush the instruction cache for copy_to_user_page()." "If the icache does not snoop stores then this routine(flush_icache_range) will need to flush it." Signed-off-by: Guo Ren Signed-off-by: Greentime Hu --- arch/nds32/include/asm/cacheflush.h | 9 +++++-- arch/nds32/mm/cacheflush.c | 53 ++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/arch/nds32/include/asm/cacheflush.h b/arch/nds32/include/asm/cacheflush.h index 10b48f0d8e85..8b26198d51bb 100644 --- a/arch/nds32/include/asm/cacheflush.h +++ b/arch/nds32/include/asm/cacheflush.h @@ -8,6 +8,8 @@ #define PG_dcache_dirty PG_arch_1 +void flush_icache_range(unsigned long start, unsigned long end); +void flush_icache_page(struct vm_area_struct *vma, struct page *page); #ifdef CONFIG_CPU_CACHE_ALIASING void flush_cache_mm(struct mm_struct *mm); void flush_cache_dup_mm(struct mm_struct *mm); @@ -34,13 +36,16 @@ void flush_anon_page(struct vm_area_struct *vma, void flush_kernel_dcache_page(struct page *page); void flush_kernel_vmap_range(void *addr, int size); void invalidate_kernel_vmap_range(void *addr, int size); -void flush_icache_range(unsigned long start, unsigned long end); -void flush_icache_page(struct vm_area_struct *vma, struct page *page); #define flush_dcache_mmap_lock(mapping) xa_lock_irq(&(mapping)->i_pages) #define flush_dcache_mmap_unlock(mapping) xa_unlock_irq(&(mapping)->i_pages) #else #include +#undef flush_icache_range +#undef flush_icache_page +#undef flush_icache_user_range +void flush_icache_user_range(struct vm_area_struct *vma, struct page *page, + unsigned long addr, int len); #endif #endif /* __NDS32_CACHEFLUSH_H__ */ diff --git a/arch/nds32/mm/cacheflush.c b/arch/nds32/mm/cacheflush.c index ce8fd34497bf..7fcaa4e6be78 100644 --- a/arch/nds32/mm/cacheflush.c +++ b/arch/nds32/mm/cacheflush.c @@ -13,6 +13,38 @@ extern struct cache_info L1_cache_info[2]; +void flush_icache_range(unsigned long start, unsigned long end) +{ + unsigned long line_size, flags; + line_size = L1_cache_info[DCACHE].line_size; + start = start & ~(line_size - 1); + end = (end + line_size - 1) & ~(line_size - 1); + local_irq_save(flags); + cpu_cache_wbinval_range(start, end, 1); + local_irq_restore(flags); +} +EXPORT_SYMBOL(flush_icache_range); + +void flush_icache_page(struct vm_area_struct *vma, struct page *page) +{ + unsigned long flags; + unsigned long kaddr; + local_irq_save(flags); + kaddr = (unsigned long)kmap_atomic(page); + cpu_cache_wbinval_page(kaddr, vma->vm_flags & VM_EXEC); + kunmap_atomic((void *)kaddr); + local_irq_restore(flags); +} +EXPORT_SYMBOL(flush_icache_page); + +void flush_icache_user_range(struct vm_area_struct *vma, struct page *page, + unsigned long addr, int len) +{ + unsigned long kaddr; + kaddr = (unsigned long)kmap_atomic(page) + (addr & ~PAGE_MASK); + flush_icache_range(kaddr, kaddr + len); + kunmap_atomic((void *)kaddr); +} #ifndef CONFIG_CPU_CACHE_ALIASING void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, pte_t * pte) @@ -318,27 +350,6 @@ void invalidate_kernel_vmap_range(void *addr, int size) } EXPORT_SYMBOL(invalidate_kernel_vmap_range); -void flush_icache_range(unsigned long start, unsigned long end) -{ - unsigned long line_size, flags; - line_size = L1_cache_info[DCACHE].line_size; - start = start & ~(line_size - 1); - end = (end + line_size - 1) & ~(line_size - 1); - local_irq_save(flags); - cpu_cache_wbinval_range(start, end, 1); - local_irq_restore(flags); -} -EXPORT_SYMBOL(flush_icache_range); - -void flush_icache_page(struct vm_area_struct *vma, struct page *page) -{ - unsigned long flags; - local_irq_save(flags); - cpu_cache_wbinval_page((unsigned long)page_address(page), - vma->vm_flags & VM_EXEC); - local_irq_restore(flags); -} - void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, pte_t * pte) { -- 2.16.2