Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp158577pxk; Wed, 9 Sep 2020 01:42:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwMIynkxfJ/hCBe1Iprg+MXNmTbliE2S3TUkopwMaM0J50v3h8RZ/5BXZ8uaidcItq6jss X-Received: by 2002:aa7:ce15:: with SMTP id d21mr3012688edv.284.1599640926081; Wed, 09 Sep 2020 01:42:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599640926; cv=none; d=google.com; s=arc-20160816; b=vuVCNrwJVX3NpLrVkwFIdi9fd8LkjGB+432hJw3uf0NqQeSIR9cQ0FeocJUqmO+sJb IYa0y4Xa0Ph+LZ1VlsjSHZl+niUFTNzHdbyvtTuTql7PqDwZVqKT4ZDv+Kla43v386f2 xyzJupAgKjDGwirsTdMdbh9plA5x4+CtJLsKqCNnxotwZMf3H4OI/6Eb7o8nqwfCMG2D OehLPwKFwd7fu1ufWtzh/GgEv1yXLiqFzb4Aa88/t6ebInqF7qJ4YHemVNOypAeQReVB 6C4ZtxPpMia6lkRB5ig/fwoNgrYs6ekYZEco+noOmVmSNB3uAYfgH8LYHkMSTGWicplv NlQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:organization:references:in-reply-to:cc:to:from :subject; bh=MHyJIcYpx1mm1RLU0qfkp0yG7DL6YywByFGmWzq8Tbc=; b=dZOnNJBCxsbRSat6fGBuqWcvrcqdqIecPABVYpDU1lR9+qn+9Jsv74fQcooAe1GBTJ XGEehR0ZIXD/6AjBw4JZjdXYPef/YLChs76Q58n2DSvD2HEOOAZPNjhHyv6UcReN9PUD uZ9slPL78yIzh4hNalWfiR0b5QU+miF2ygFWH02DiUrKi8BDr+U6NYlZqLElAS/SqaZm XRjOqZHShVXO0hjBJ1kq2zi8pKYZ3V9329aoGhMlGBzrQLTDq315pGwrd3tbefalL+3r 1tDSErhgQ0NZcxWNi+MXKeD7UfGEs+bKlXowiGsMYLNwzMR54JHMNFrQTLboxuoaqy9k iI/w== 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 p2si1028866ejw.176.2020.09.09.01.41.43; Wed, 09 Sep 2020 01:42:06 -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 S1728647AbgIIIi6 (ORCPT + 99 others); Wed, 9 Sep 2020 04:38:58 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:13756 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725826AbgIIIio (ORCPT ); Wed, 9 Sep 2020 04:38:44 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4Bmb5S0y0Yz9v0ZM; Wed, 9 Sep 2020 10:38:36 +0200 (CEST) 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 AVJJBZqZz_Lj; Wed, 9 Sep 2020 10:38:36 +0200 (CEST) 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 4Bmb5R6sd6z9v0ZL; Wed, 9 Sep 2020 10:38:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 1B5318B7DC; Wed, 9 Sep 2020 10:38:37 +0200 (CEST) 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 c2KpwQPUfYWM; Wed, 9 Sep 2020 10:38:36 +0200 (CEST) Received: from [10.0.2.15] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 5593A8B7D4; Wed, 9 Sep 2020 10:38:35 +0200 (CEST) Subject: Re: [RFC PATCH v2 2/3] mm: make pXd_addr_end() functions page-table entry aware From: Christophe Leroy To: Alexander Gordeev Cc: Michael Ellerman , Gerald Schaefer , Jason Gunthorpe , John Hubbard , Peter Zijlstra , Dave Hansen , linux-mm , Paul Mackerras , linux-sparc , Claudio Imbrenda , Will Deacon , linux-arch , linux-s390 , Vasily Gorbik , Richard Weinberger , linux-x86 , Russell King , Christian Borntraeger , Ingo Molnar , Catalin Marinas , Andrey Ryabinin , Heiko Carstens , Arnd Bergmann , Jeff Dike , linux-um , Borislav Petkov , Andy Lutomirski , Thomas Gleixner , linux-arm , linux-power , LKML , Andrew Morton , Linus Torvalds , Mike Rapoport In-Reply-To: <20200908141554.GA20558@oc3871087118.ibm.com> References: <20200907180058.64880-1-gerald.schaefer@linux.ibm.com> <20200907180058.64880-3-gerald.schaefer@linux.ibm.com> <31dfb3ed-a0cc-3024-d389-ab9bd19e881f@csgroup.eu> <20200908074638.GA19099@oc3871087118.ibm.com> <5d4f5546-afd0-0b8f-664d-700ae346b9ec@csgroup.eu> <20200908141554.GA20558@oc3871087118.ibm.com> Content-Type: text/plain; charset="UTF-8" Organization: CS Group France Date: Wed, 09 Sep 2020 08:38:31 +0000 Message-ID: <1599640711.14692.1.camel@po17688vm.idsi0.si.c-s.fr> Mime-Version: 1.0 X-Mailer: Evolution 2.32.3 (2.32.3-37.el6) Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2020-09-08 at 16:15 +0200, Alexander Gordeev wrote: > On Tue, Sep 08, 2020 at 10:16:49AM +0200, Christophe Leroy wrote: > > >Yes, and also two more sources :/ > > > arch/powerpc/mm/kasan/8xx.c > > > arch/powerpc/mm/kasan/kasan_init_32.c > > > > > >But these two are not quite obvious wrt pgd_addr_end() used > > >while traversing pmds. Could you please clarify a bit? > > > > > > > > >diff --git a/arch/powerpc/mm/kasan/8xx.c b/arch/powerpc/mm/kasan/8xx.c > > >index 2784224..89c5053 100644 > > >--- a/arch/powerpc/mm/kasan/8xx.c > > >+++ b/arch/powerpc/mm/kasan/8xx.c > > >@@ -15,8 +15,8 @@ > > > for (k_cur = k_start; k_cur != k_end; k_cur = k_next, pmd += 2, block += SZ_8M) { > > > pte_basic_t *new; > > >- k_next = pgd_addr_end(k_cur, k_end); > > >- k_next = pgd_addr_end(k_next, k_end); > > >+ k_next = pmd_addr_end(k_cur, k_end); > > >+ k_next = pmd_addr_end(k_next, k_end); > > > > No, I don't think so. > > On powerpc32 we have only two levels, so pgd and pmd are more or > > less the same. > > But pmd_addr_end() as defined in include/asm-generic/pgtable-nopmd.h > > is a no-op, so I don't think it will work. > > > > It is likely that this function should iterate on pgd, then you get > > pmd = pmd_offset(pud_offset(p4d_offset(pgd))); > > It looks like the code iterates over single pmd table while using > pgd_addr_end() only to skip all the middle levels and bail out > from the loop. > > I would be wary for switching from pmds to pgds, since we are > trying to minimize impact (especially functional) and the > rework does not seem that obvious. > I've just tested the following change, it works and should fix the oddity: diff --git a/arch/powerpc/mm/kasan/8xx.c b/arch/powerpc/mm/kasan/8xx.c index 2784224054f8..8e53ddf57b84 100644 --- a/arch/powerpc/mm/kasan/8xx.c +++ b/arch/powerpc/mm/kasan/8xx.c @@ -9,11 +9,12 @@ static int __init kasan_init_shadow_8M(unsigned long k_start, unsigned long k_end, void *block) { - pmd_t *pmd = pmd_off_k(k_start); + pgd_t *pgd = pgd_offset_k(k_start); unsigned long k_cur, k_next; - for (k_cur = k_start; k_cur != k_end; k_cur = k_next, pmd += 2, block += SZ_8M) { + for (k_cur = k_start; k_cur != k_end; k_cur = k_next, pgd += 2, block += SZ_8M) { pte_basic_t *new; + pmd_t *pmd = pmd_offset(pud_offset(p4d_offset(pgd, k_cur), k_cur), k_cur); k_next = pgd_addr_end(k_cur, k_end); k_next = pgd_addr_end(k_next, k_end); diff --git a/arch/powerpc/mm/kasan/kasan_init_32.c b/arch/powerpc/mm/kasan/kasan_init_32.c index fb294046e00e..e5f524fa71a7 100644 --- a/arch/powerpc/mm/kasan/kasan_init_32.c +++ b/arch/powerpc/mm/kasan/kasan_init_32.c @@ -30,13 +30,12 @@ static void __init kasan_populate_pte(pte_t *ptep, pgprot_t prot) int __init kasan_init_shadow_page_tables(unsigned long k_start, unsigned long k_end) { - pmd_t *pmd; + pgd_t *pgd = pgd_offset_k(k_start); unsigned long k_cur, k_next; - pmd = pmd_off_k(k_start); - - for (k_cur = k_start; k_cur != k_end; k_cur = k_next, pmd++) { + for (k_cur = k_start; k_cur != k_end; k_cur = k_next, pgd++) { pte_t *new; + pmd_t *pmd = pmd_offset(pud_offset(p4d_offset(pgd, k_cur), k_cur), k_cur); k_next = pgd_addr_end(k_cur, k_end); if ((void *)pmd_page_vaddr(*pmd) != kasan_early_shadow_pte) @@ -189,16 +188,18 @@ void __init kasan_early_init(void) unsigned long addr = KASAN_SHADOW_START; unsigned long end = KASAN_SHADOW_END; unsigned long next; - pmd_t *pmd = pmd_off_k(addr); + pgd_t *pgd = pgd_offset_k(addr); BUILD_BUG_ON(KASAN_SHADOW_START & ~PGDIR_MASK); kasan_populate_pte(kasan_early_shadow_pte, PAGE_KERNEL); do { + pmd_t *pmd = pmd_offset(pud_offset(p4d_offset(pgd, addr), addr), addr); + next = pgd_addr_end(addr, end); pmd_populate_kernel(&init_mm, pmd, kasan_early_shadow_pte); - } while (pmd++, addr = next, addr != end); + } while (pgd++, addr = next, addr != end); if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) kasan_early_hash_table(); --- Christophe