Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2011128ybk; Mon, 11 May 2020 09:41:44 -0700 (PDT) X-Google-Smtp-Source: APiQypJHTZoJQY82WT9ytnt72hAo22UjrH6+tPv4p2ZWuJ0GtcO1RJwq+qx2wnK1tFlH00bY38VU X-Received: by 2002:a50:9f4a:: with SMTP id b68mr14353173edf.108.1589215304553; Mon, 11 May 2020 09:41:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589215304; cv=none; d=google.com; s=arc-20160816; b=hEBfk9QOvlV7oB/paY1kNjhYi2tALatQris+ekbc64kPxigklyd9z2KsGapdACzEqO SqnaWR7jt/Hgyww6/ifcs+zodoU7BLRfWT7CNTjyng9RKG/0na63+ZjbHOZyqym+p5WU BBgvINWH1wm99Y3gL+K7gnn5zzHECrRy43NMCx6h+sjudMwdnu743cw8t2wQxMmZNYkW aDRh7kY7vOETKDTNXbKMFaWK+lQm1OGWilEM2j2GZrv/KaNXQfeeAmAtkTRzOxA2ltF/ UC8N+EJnU1/NR3hG1eNtDi36z4nGAPtItGFK7Q7fxuJZNstqvN4tRhrnTBCE03DD2E6R XhaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=bCpTMvJJlCSM1A/nBsA2GeBioMk9jwYptfUvU7+eE2k=; b=ZLldU3a0MDV/6bXZfq+YNT6wOKpjUN11fYa3H1XRgGayRFhkqRcz3WHoH/7ZTvMyto JKnRmwONxZ4etLRCbxC1CY39UAX02H5XjaKzbDhZF1saaGBxk1xzEmBEIJOjVrqDRCx/ i46wN2Wl27kJX3Wz/KMZcJzM0795pnqHx14YKEeVvZ8IG/L0jrP2lryNQ0cR/naNkbpE bbdX/kyom3Y7bPviemsZSa0FONWn6dESYPzB4eaHREc1y/aZo7g7jlvA9xzPOkhNhnFQ L7hYnrR+DwD/UdrLpebatTrlH2vQav+6cLVk+a/ret6T9ZSljOqMqAUb1Y8olkMuUS3A n65w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w20si6032356ejq.91.2020.05.11.09.41.20; Mon, 11 May 2020 09:41:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730400AbgEKQhy (ORCPT + 99 others); Mon, 11 May 2020 12:37:54 -0400 Received: from verein.lst.de ([213.95.11.211]:36994 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730048AbgEKQhx (ORCPT ); Mon, 11 May 2020 12:37:53 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id C9A7568CEE; Mon, 11 May 2020 18:37:45 +0200 (CEST) Date: Mon, 11 May 2020 18:37:44 +0200 From: Christoph Hellwig To: Geert Uytterhoeven Cc: Christoph Hellwig , Andrew Morton , Arnd Bergmann , Roman Zippel , Jessica Yu , Michal Simek , the arch/x86 maintainers , alpha , Linux Kernel Mailing List , Linux ARM , linux-c6x-dev@linux-c6x.org, "open list:QUALCOMM HEXAGON..." , "linux-ia64@vger.kernel.org" , linux-m68k , "open list:BROADCOM NVRAM DRIVER" , Openrisc , linuxppc-dev , linux-riscv@lists.infradead.org, Linux-sh list , sparclinux , Linux-Arch , Linux MM , linux-um , "open list:TENSILICA XTENSA PORT (xtensa)" , Linux FS Devel Subject: Re: [PATCH 31/31] module: move the set_fs hack for flush_icache_range to m68k Message-ID: <20200511163744.GB32228@lst.de> References: <20200510075510.987823-1-hch@lst.de> <20200510075510.987823-32-hch@lst.de> <20200511151120.GA28634@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 11, 2020 at 05:24:30PM +0200, Geert Uytterhoeven wrote: > > Btw, do you know what part of flush_icache_range relied on set_fs? > > Do any of the m68k maintainers have an idea how to handle that in > > a nicer way when we can split the implementations? > > arch/m68k/mm/cache.c:virt_to_phys_slow() > > All instructions that look up addresses in the page tables look at the > source/destination function codes (SFC/DFC) to know if they have to use > the supervisor or user page tables. > So the actual implementation is the same: set_fs() merely configures > SFC/DFC, to select the address space to use. So instead of the magic instructions could we use the normal kernel virt to phys helpers instead of switching the addresses space? Something like this patch on top of the series: diff --git a/arch/m68k/mm/cache.c b/arch/m68k/mm/cache.c index 5ecb3310e8745..5a861a14c1e69 100644 --- a/arch/m68k/mm/cache.c +++ b/arch/m68k/mm/cache.c @@ -71,47 +71,87 @@ static unsigned long virt_to_phys_slow(unsigned long vaddr) return 0; } -/* Push n pages at kernel virtual address and clear the icache */ -/* RZ: use cpush %bc instead of cpush %dc, cinv %ic */ -void flush_icache_user_range(unsigned long address, unsigned long endaddr) +static inline void coldfire_flush_icache_range(unsigned long start, + unsigned long end) { - if (CPU_IS_COLDFIRE) { - unsigned long start, end; - start = address & ICACHE_SET_MASK; - end = endaddr & ICACHE_SET_MASK; - if (start > end) { - flush_cf_icache(0, end); - end = ICACHE_MAX_ADDR; - } - flush_cf_icache(start, end); - } else if (CPU_IS_040_OR_060) { - address &= PAGE_MASK; - - do { - asm volatile ("nop\n\t" - ".chip 68040\n\t" - "cpushp %%bc,(%0)\n\t" - ".chip 68k" - : : "a" (virt_to_phys_slow(address))); - address += PAGE_SIZE; - } while (address < endaddr); - } else { - unsigned long tmp; - asm volatile ("movec %%cacr,%0\n\t" - "orw %1,%0\n\t" - "movec %0,%%cacr" - : "=&d" (tmp) - : "di" (FLUSH_I)); + start &= ICACHE_SET_MASK; + end &= ICACHE_SET_MASK; + + if (start > end) { + flush_cf_icache(0, end); + end = ICACHE_MAX_ADDR; } + flush_cf_icache(start, end); +} + +static inline void mc68040_flush_icache_user_range(unsigned long start, + unsigned long end) +{ + start &= PAGE_MASK; + + do { + asm volatile ("nop\n\t" + ".chip 68040\n\t" + "cpushp %%bc,(%0)\n\t" + ".chip 68k" + : : "a" (virt_to_phys_slow(start))); + start += PAGE_SIZE; + } while (start < end); +} + +static inline void mc68020_flush_icache_range(unsigned long start, + unsigned long end) +{ + unsigned long tmp; + + asm volatile ("movec %%cacr,%0\n\t" + "orw %1,%0\n\t" + "movec %0,%%cacr" + : "=&d" (tmp) + : "di" (FLUSH_I)); +} + +void flush_icache_user_range(unsigned long start, unsigned long end) +{ + if (CPU_IS_COLDFIRE) + coldfire_flush_icache_range(start, end); + else if (CPU_IS_040_OR_060) + mc68040_flush_icache_user_range(start, end); + else + mc68020_flush_icache_range(start, end); } -void flush_icache_range(unsigned long address, unsigned long endaddr) +static inline void mc68040_flush_icache_range(unsigned long start, + unsigned long end) { - mm_segment_t old_fs = get_fs(); + start &= PAGE_MASK; + + do { + void *vaddr = (void *)start; + phys_addr_t paddr; + + if (is_vmalloc_addr(vaddr)) + paddr = page_to_phys(vmalloc_to_page(vaddr)); + else + paddr = virt_to_phys(vaddr); + + asm volatile ("nop\n\t" + ".chip 68040\n\t" + "cpushp %%bc,(%0)\n\t" + ".chip 68k" + : : "a" (paddr)); + start += PAGE_SIZE; + } while (start < end); +} - set_fs(KERNEL_DS); - flush_icache_user_range(address, endaddr); - set_fs(old_fs); +void flush_icache_range(unsigned long start, unsigned long end) +{ + if (CPU_IS_COLDFIRE) + coldfire_flush_icache_range(start, end); + else if (CPU_IS_040_OR_060) + mc68040_flush_icache_range(start, end); + else + mc68020_flush_icache_range(start, end); } EXPORT_SYMBOL(flush_icache_range);