Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp609578pxb; Mon, 16 Aug 2021 12:58:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpzmkxBa7WI/4xWPlysU4iVdkixqotfPPpI2UAjV1TYrtIbYtT/fPiF5d60tZLsod0w5qb X-Received: by 2002:aa7:cc83:: with SMTP id p3mr274159edt.365.1629143906113; Mon, 16 Aug 2021 12:58:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629143906; cv=none; d=google.com; s=arc-20160816; b=yPH3I//vFqesjiMIYo7FSVqEF6kwuQ68+OU2pwtFUGgHAgXC5mPIFTIpLX3k9123TS LvMWiiiTLo6uUVYzaQSLD6tdQObkllhcFaeOvJZodvtjb77q9ZCHqMfNxdqOXMhRpBGT 2f0UpCSHuTM7AU989vRii6Cam113AvL8/zgCCyyB5s9/47HtLKKh8oQsrf2B2Lgx7sh/ RFCkt5girtN54dV+fpUa05v/riOVouF7mWTrGYLfp0YZMW+LLcwcL+iRZRe9rN95ZDOU hU44NqBRLWUXfZbqPsQoZekYKjyvsMrRKySROkwUEOlYn397ul6Zlm6LPrg4kp2+8K6e vpJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=adh0r0eEnspvTGOWN25lrn837yH6NsSzeDxP3GULMas=; b=WYD9afGcuJbOvT1xofW25AAUaGG+dT8tNrW3r3uk23FhKLxTzZ4d9yDnkxv+nf1IhZ UAXeQOSNn8uBLUeODiuYq+qQlr21tzyTJ6m4cF6QaeCCuEnI/VgBSBc23J71/tOKt4q8 DOc2hSBuDYtxN1pbJ5QELE5ve+qEuyozKtNUkZBTi4gGDNGa2s6AMzaFtn6vwc+SYNkP vZLjtkyaCqTcLTp4UpEWOWdp+n4BkNTMo1UZ9UXAPn3EKVI7rEwEj4U9bpA+SamkXhI+ qM3pJz4sZlPmst3WwrT+TMnsCpeWe4sKbIAd+BQaJWSBUc17uXGQZfg+adfuRygk4kLS UdUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AZxIiheB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ar11si174949ejc.701.2021.08.16.12.58.02; Mon, 16 Aug 2021 12:58:26 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AZxIiheB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231526AbhHPTyU (ORCPT + 99 others); Mon, 16 Aug 2021 15:54:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:45378 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231545AbhHPTyT (ORCPT ); Mon, 16 Aug 2021 15:54:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8F2C860F55; Mon, 16 Aug 2021 19:53:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629143627; bh=r/p8syA5J+lSSVbewqqUp6dVC6KJ6TIpFGwK1o5LI48=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=AZxIiheBnZDugN1zxIu3qLt1vTjNx7hnQj6R+FXnTzkLHPw66PqdHDHoTCV3HIuCo C/oQpj71tqTU47TQ6kUITmC6trdnzCfSGShLHrDRKoqTasNLw8zj3w/sedPxZ5BRka wlYO7S2CYh9N5hgw7t5WODMcgM2tzX3QpTbwiZ7LPXDw+68YzeI4Pnf9G4OprdaQMW UUtuHL0QPtrw3vt4Ytlx4cVZBDsLDGFt9aGezBk+sT48GvXFTbpsF3LMoTNbvMbp8z /Pal4tynsZbCVeYFR76NIgx9d8GvkoQ8ZGTsWCakLeGuFaKLNpSvV2oJMgkKnuVkVY UvZCIzGEb32vw== Subject: Re: [PATCH v2 16/19] ARC: mm: support 3 levels of page tables To: Mike Rapoport , Vineet Gupta Cc: linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Anshuman Khandual References: <20210812233753.104217-1-vgupta@kernel.org> <20210812233753.104217-17-vgupta@kernel.org> From: Vineet Gupta Message-ID: <3878c8da-cba0-d4f5-90a7-f4024054872d@kernel.org> Date: Mon, 16 Aug 2021 12:53:46 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/15/21 2:27 AM, Mike Rapoport wrote: > On Thu, Aug 12, 2021 at 04:37:50PM -0700, Vineet Gupta wrote: >> ARCv2 MMU is software walked and Linux implements 2 levels of paging: pgd/pte. >> Forthcoming hw will have multiple levels, so this change preps mm code >> for same. It is also fun to try multi levels even on soft-walked code to >> ensure generic mm code is robust to handle. >> >> overview >> ________ >> >> 2 levels {pgd, pte} : pmd is folded but pmd_* macros are valid and operate on pgd >> 3 levels {pgd, pmd, pte}: >> - pud is folded and pud_* macros point to pgd >> - pmd_* macros operate on actual pmd >> >> code changes >> ____________ >> >> 1. #include >> >> 2. Define CONFIG_PGTABLE_LEVELS 3 >> >> 3a. Define PMD_SHIFT, PMD_SIZE, PMD_MASK, pmd_t >> 3b. Define pmd_val() which actually deals with pmd >> (pmd_offset(), pmd_index() are provided by generic code) >> 3c. pmd_alloc_one()/pmd_free() also provided by generic code >> (pmd_populate/pmd_free already exist) >> >> 4. Define pud_none(), pud_bad() macros based on generic pud_val() which >> internally pertains to pgd now. >> 4b. define pud_populate() to just setup pgd >> >> Signed-off-by: Vineet Gupta >> --- > ... > >> diff --git a/arch/arc/include/asm/pgtable-levels.h b/arch/arc/include/asm/pgtable-levels.h >> index 8ece75335bb5..1c2f022d4ad0 100644 >> --- a/arch/arc/include/asm/pgtable-levels.h >> +++ b/arch/arc/include/asm/pgtable-levels.h >> @@ -10,6 +10,8 @@ >> #ifndef _ASM_ARC_PGTABLE_LEVELS_H >> #define _ASM_ARC_PGTABLE_LEVELS_H >> >> +#if CONFIG_PGTABLE_LEVELS == 2 >> + >> /* >> * 2 level paging setup for software walked MMUv3 (ARC700) and MMUv4 (HS) >> * >> @@ -37,16 +39,38 @@ >> #define PGDIR_SHIFT 21 >> #endif >> >> -#define PGDIR_SIZE BIT(PGDIR_SHIFT) /* vaddr span, not PDG sz */ >> -#define PGDIR_MASK (~(PGDIR_SIZE - 1)) >> +#else > Adding /* CONFIG_PGTABLE_LEVELS == 2 */ would make the whole thing a bit > more readable, I think. You meant +#else /* CONFIG_PGTABLE_LEVELS != 2 > >> + >> +/* >> + * A default 3 level paging testing setup in software walked MMU >> + * MMUv4 (8K page): <4> : <7> : <8> : <13> >> + */ >> +#define PGDIR_SHIFT 28 >> +#if CONFIG_PGTABLE_LEVELS > 2 >> +#define PMD_SHIFT 21 >> +#endif >> + >> +#endif > and here as well. I added following to indicate conditional coding for levels related code +#endif /* CONFIG_PGTABLE_LEVELS */ > >> +#define PGDIR_SIZE BIT(PGDIR_SHIFT) >> +#define PGDIR_MASK (~(PGDIR_SIZE - 1)) >> #define PTRS_PER_PGD BIT(32 - PGDIR_SHIFT) >> >> -#define PTRS_PER_PTE BIT(PGDIR_SHIFT - PAGE_SHIFT) >> +#if CONFIG_PGTABLE_LEVELS > 2 >> +#define PMD_SIZE BIT(PMD_SHIFT) >> +#define PMD_MASK (~(PMD_SIZE - 1)) >> +#define PTRS_PER_PMD BIT(PGDIR_SHIFT - PMD_SHIFT) >> +#endif >> + >> +#define PTRS_PER_PTE BIT(PMD_SHIFT - PAGE_SHIFT) >>