Received: by 10.223.185.116 with SMTP id b49csp1987030wrg; Thu, 22 Feb 2018 06:29:59 -0800 (PST) X-Google-Smtp-Source: AH8x2278uhKOTwEDakDfSzo3tWGNmhJwlwyLcRMk1Eh5KiTmye46t704NkKwQkamZzrdOgxVBvBc X-Received: by 10.99.179.8 with SMTP id i8mr5778934pgf.337.1519309799646; Thu, 22 Feb 2018 06:29:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519309799; cv=none; d=google.com; s=arc-20160816; b=kHU7xy7KBNSl5td8McTUMT12xZzkE1BW6hWFyCUxTDPT7K6XAY3ofGpWmBi751Ley1 WzmF1neYksHmk/uqqUfkbMqUF5XWkr0DR9n4Ew6Xm93AZOqtZ7YLc00dHW7oH8TJhy3i YqT0dBrjwSsae4xD096QKCdtP1h+V8Z41PqXbI7NZhcG5aDN0qzQND30B2TFKuUrQsPJ v2C4ziQsGACcDPEhwDsatIfpP2NdRD4Y38CSluIgxxFxmeI91LC1fSWDqf7h92tMedgi gLWV5TqfKKGv7YeKVO1VJvfeK6nSEiJP74DLrSZVNINl97xVIxCV8aIn7tyX98VH0JDB 3ghQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id:arc-authentication-results; bh=O1rQ2neZdhW8vVQxaX8PVWYI7a/A0gwEMMYexQMB6Sk=; b=AcxHfjFRHmynT7gJbj0IcrzNYyXZLlnzXHaN4evASZv/iQL3osTu0n2LdvlH6d+W75 prLxu6OOFnHoyiaGV8K6ZEpWRwsh4tlIK7LMwcjE/HjLvvhwb+7UTNR7kyTtBN0bUwZC z/HlsdeFHNTLltr1bV+c4suC8+vZKUrINutk3cfGMzMFSlpvr8FaOncB4xMj0Bmwjg4K TR8F86/TMaoOZMzXw9O7yXEJy2X6rDw6olmq2uMuVcY21TsDCIbS4e9UWBc6C7EnnEH9 9UdHnVDy5kz3sxgDnCDE/cUfXW6dhFg9gucpO5uDOkooRgKPeqxHkBMBWOSokDgVEUWD X7ng== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 206si65537pgb.647.2018.02.22.06.29.44; Thu, 22 Feb 2018 06:29:59 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932966AbeBVO1d (ORCPT + 99 others); Thu, 22 Feb 2018 09:27:33 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:20467 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932942AbeBVO10 (ORCPT ); Thu, 22 Feb 2018 09:27:26 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 3znGrw0Qlcz9twmZ; Thu, 22 Feb 2018 15:27:12 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id gHHI93AT-cvn; Thu, 22 Feb 2018 15:27:12 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 3znGrv6nqTz9twm7; Thu, 22 Feb 2018 15:27:11 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 055928BB37; Thu, 22 Feb 2018 15:27:25 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id vSXJz5dYfSAi; Thu, 22 Feb 2018 15:27:24 +0100 (CET) Received: from po15720vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.5]) by messagerie.si.c-s.fr (Postfix) with ESMTP id CDB808BB2E; Thu, 22 Feb 2018 15:27:24 +0100 (CET) Received: by po15720vm.idsi0.si.c-s.fr (Postfix, from userid 0) id BD92E67B4B; Thu, 22 Feb 2018 15:27:24 +0100 (CET) Message-Id: <3e9cfc87e78d61310d1b628960a465327c20d895.1519305411.git.christophe.leroy@c-s.fr> In-Reply-To: <455276187b369bf019e91715b7488e86cd932d49.1519305410.git.christophe.leroy@c-s.fr> References: <455276187b369bf019e91715b7488e86cd932d49.1519305410.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [PATCH v5 3/6] powerpc/mm/slice: Enhance for supporting PPC32 To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Scott Wood , aneesh.kumar@linux.vnet.ibm.com Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Nicholas Piggin Date: Thu, 22 Feb 2018 15:27:24 +0100 (CET) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for the following patch which will fix an issue on the 8xx by re-using the 'slices', this patch enhances the 'slices' implementation to support 32 bits CPUs. On PPC32, the address space is limited to 4Gbytes, hence only the low slices will be used. The high slices use bitmaps. As bitmap functions are not prepared to handle bitmaps of size 0, this patch ensures that bitmap functions are called only when SLICE_NUM_HIGH is not nul. Signed-off-by: Christophe Leroy --- v2: First patch of v1 serie split in two parts ; added slice_bitmap_xxx() macros. v3: Moving slice related stuff in slice.h and slice_32/64.h slice_bitmap_xxx() are now static inline functions and platform dependent SLICE_LOW_TOP declared ull on PPC32 with correct casts allows to keep it 0x100000000 v4: Moved slice_32.h and slice_64.h to respective subarch dirs Moved somes #ifdefs from asm/slice.h to respective subarch slice.h SLICE_LOW_ details distributed in repective subarch slices allthough they are identical for the moment v5: Split in two parts. The moving of slice related stuffs into slice.h files is now done in the preceding patch Based on several feedback received, this version removes the slice_bitmap_xxx() wrappers and comes back to the initial approach of checking that SLICE_NUM_HIGH is not nul before using bitmap_xxx() functions. Unlike the others, this approach has the advantage of allowing the reader to immediatly know what's going on and avoid all this set of copy/empty wrappers in subarch slice.h files. It also significantly reduces the size of the patch, which is a prerequisite for backporting it to stable releases. arch/powerpc/include/asm/nohash/32/slice.h | 18 +++++++++++++++ arch/powerpc/include/asm/slice.h | 4 +++- arch/powerpc/mm/slice.c | 37 +++++++++++++++++++++++------- 3 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 arch/powerpc/include/asm/nohash/32/slice.h diff --git a/arch/powerpc/include/asm/nohash/32/slice.h b/arch/powerpc/include/asm/nohash/32/slice.h new file mode 100644 index 000000000000..95d532e18092 --- /dev/null +++ b/arch/powerpc/include/asm/nohash/32/slice.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_POWERPC_NOHASH_32_SLICE_H +#define _ASM_POWERPC_NOHASH_32_SLICE_H + +#ifdef CONFIG_PPC_MM_SLICES + +#define SLICE_LOW_SHIFT 28 +#define SLICE_LOW_TOP (0x100000000ull) +#define SLICE_NUM_LOW (SLICE_LOW_TOP >> SLICE_LOW_SHIFT) +#define GET_LOW_SLICE_INDEX(addr) ((addr) >> SLICE_LOW_SHIFT) + +#define SLICE_HIGH_SHIFT 0 +#define SLICE_NUM_HIGH 0ul +#define GET_HIGH_SLICE_INDEX(addr) (addr & 0) + +#endif /* CONFIG_PPC_MM_SLICES */ + +#endif /* _ASM_POWERPC_NOHASH_32_SLICE_H */ diff --git a/arch/powerpc/include/asm/slice.h b/arch/powerpc/include/asm/slice.h index 17c5a5d8c418..172711fadb1c 100644 --- a/arch/powerpc/include/asm/slice.h +++ b/arch/powerpc/include/asm/slice.h @@ -4,8 +4,10 @@ #ifdef CONFIG_PPC_BOOK3S_64 #include -#else +#elif defined(CONFIG_PPC64) #include +#elif defined(CONFIG_PPC_MMU_NOHASH) +#include #endif #ifdef CONFIG_PPC_MM_SLICES diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c index 98b53d48968f..0beca1ba2282 100644 --- a/arch/powerpc/mm/slice.c +++ b/arch/powerpc/mm/slice.c @@ -73,10 +73,12 @@ static void slice_range_to_mask(unsigned long start, unsigned long len, unsigned long end = start + len - 1; ret->low_slices = 0; - bitmap_zero(ret->high_slices, SLICE_NUM_HIGH); + if (SLICE_NUM_HIGH) + bitmap_zero(ret->high_slices, SLICE_NUM_HIGH); if (start < SLICE_LOW_TOP) { - unsigned long mend = min(end, (SLICE_LOW_TOP - 1)); + unsigned long mend = min(end, + (unsigned long)(SLICE_LOW_TOP - 1)); ret->low_slices = (1u << (GET_LOW_SLICE_INDEX(mend) + 1)) - (1u << GET_LOW_SLICE_INDEX(start)); @@ -113,11 +115,13 @@ static int slice_high_has_vma(struct mm_struct *mm, unsigned long slice) unsigned long start = slice << SLICE_HIGH_SHIFT; unsigned long end = start + (1ul << SLICE_HIGH_SHIFT); +#ifdef CONFIG_PPC64 /* Hack, so that each addresses is controlled by exactly one * of the high or low area bitmaps, the first high area starts * at 4GB, not 0 */ if (start == 0) start = SLICE_LOW_TOP; +#endif return !slice_area_is_free(mm, start, end - start); } @@ -128,7 +132,8 @@ static void slice_mask_for_free(struct mm_struct *mm, struct slice_mask *ret, unsigned long i; ret->low_slices = 0; - bitmap_zero(ret->high_slices, SLICE_NUM_HIGH); + if (SLICE_NUM_HIGH) + bitmap_zero(ret->high_slices, SLICE_NUM_HIGH); for (i = 0; i < SLICE_NUM_LOW; i++) if (!slice_low_has_vma(mm, i)) @@ -151,7 +156,8 @@ static void slice_mask_for_size(struct mm_struct *mm, int psize, struct slice_ma u64 lpsizes; ret->low_slices = 0; - bitmap_zero(ret->high_slices, SLICE_NUM_HIGH); + if (SLICE_NUM_HIGH) + bitmap_zero(ret->high_slices, SLICE_NUM_HIGH); lpsizes = mm->context.low_slices_psize; for (i = 0; i < SLICE_NUM_LOW; i++) @@ -180,6 +186,10 @@ static int slice_check_fit(struct mm_struct *mm, */ unsigned long slice_count = GET_HIGH_SLICE_INDEX(mm->context.slb_addr_limit); + if (!SLICE_NUM_HIGH) + return (mask.low_slices & available.low_slices) == + mask.low_slices; + bitmap_and(result, mask.high_slices, available.high_slices, slice_count); @@ -189,6 +199,7 @@ static int slice_check_fit(struct mm_struct *mm, static void slice_flush_segments(void *parm) { +#ifdef CONFIG_PPC64 struct mm_struct *mm = parm; unsigned long flags; @@ -200,6 +211,7 @@ static void slice_flush_segments(void *parm) local_irq_save(flags); slb_flush_and_rebolt(); local_irq_restore(flags); +#endif } static void slice_convert(struct mm_struct *mm, struct slice_mask mask, int psize) @@ -389,6 +401,8 @@ static unsigned long slice_find_area(struct mm_struct *mm, unsigned long len, static inline void slice_or_mask(struct slice_mask *dst, struct slice_mask *src) { dst->low_slices |= src->low_slices; + if (!SLICE_NUM_HIGH) + return; bitmap_or(dst->high_slices, dst->high_slices, src->high_slices, SLICE_NUM_HIGH); } @@ -397,6 +411,8 @@ static inline void slice_andnot_mask(struct slice_mask *dst, struct slice_mask * { dst->low_slices &= ~src->low_slices; + if (!SLICE_NUM_HIGH) + return; bitmap_andnot(dst->high_slices, dst->high_slices, src->high_slices, SLICE_NUM_HIGH); } @@ -446,14 +462,17 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len, * init different masks */ mask.low_slices = 0; - bitmap_zero(mask.high_slices, SLICE_NUM_HIGH); /* silence stupid warning */; potential_mask.low_slices = 0; - bitmap_zero(potential_mask.high_slices, SLICE_NUM_HIGH); compat_mask.low_slices = 0; - bitmap_zero(compat_mask.high_slices, SLICE_NUM_HIGH); + + if (SLICE_NUM_HIGH) { + bitmap_zero(mask.high_slices, SLICE_NUM_HIGH); + bitmap_zero(potential_mask.high_slices, SLICE_NUM_HIGH); + bitmap_zero(compat_mask.high_slices, SLICE_NUM_HIGH); + } /* Sanity checks */ BUG_ON(mm->task_size == 0); @@ -591,7 +610,9 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len, convert: slice_andnot_mask(&mask, &good_mask); slice_andnot_mask(&mask, &compat_mask); - if (mask.low_slices || !bitmap_empty(mask.high_slices, SLICE_NUM_HIGH)) { + if (mask.low_slices || + (SLICE_NUM_HIGH && + !bitmap_empty(mask.high_slices, SLICE_NUM_HIGH))) { slice_convert(mm, mask, psize); if (psize > MMU_PAGE_BASE) on_each_cpu(slice_flush_segments, mm, 1); -- 2.13.3