Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4237904pxf; Tue, 30 Mar 2021 02:51:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCz0pMrXoorFGkwIK8cWfYAdqNYYaeJGorMr33dAZM2b80d1fF8p6WVWeHBb7NQ67yLdS5 X-Received: by 2002:a17:906:1352:: with SMTP id x18mr31911338ejb.545.1617097915186; Tue, 30 Mar 2021 02:51:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617097915; cv=none; d=google.com; s=arc-20160816; b=ni8YA6ynn6wemllpjkVrX/i1eq4xPVw5IJm9vKPOK4JKSnd4I8pJnAkwYOL49XdPEk CeQq1n7CSXyydyO4NiWsjgODQOt93v7YpCLH9kz4JVw7bI2RUopN9RLlDHBaoUyOEkod NkWEzJlCAArdAMmfjbhtnELmwHe5ZGdkmttm6II2d951UHMRM8gd9cqqadbMnyTUhh61 A5NyZvmfKRlk0zXtVZ1OTPtOGWlwB4oZSPNdthE8sSyf1lxj4GznRZh0YsvpUtZf+UHZ xQcfRb2t434b/3D7t2QJ7K8pd86RGfNGwcdaD74tfCYOZZtPYkDv5h5thR2r8XRF2RKh vKjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=8y7oZIw1YMOjEvsLWyQcxtUBXg+Hq4822w/iibJY5oM=; b=qIRhqmwRaNzK2Z61Z80Rtea9eDK/ZHWMsBJYBGPLtGyu2xgvkpXOkc8tgnp/g4EfqQ jrUVWhXUEkMB6PvxIRzlSMetfCqqXqkFG0xOICZrfpKCZPI4eszVk/WISagGY0KwKsgv bSNT1DX+PjOYt3GNDE4QkqTfwrSLCdfmFmxY9K0kIZTc/pYOzEcAnTncY+7+g7FWHN0B Q/NOB53JOKGUy3IH1ApV0PBxveg8pJh4ZLsHLuvyWAzgKO4ORTm3AXRdlkn89Qh+07Dm r0BjSUf1yk8G+2wWl3L2FdE2ipKY0YnWPYond6OLq4OHf0Y5dYDXjhIMUuMVXNTX94yG T3Cw== 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 a18si14248624ejk.339.2021.03.30.02.51.31; Tue, 30 Mar 2021 02:51:55 -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 S231638AbhC3JsF (ORCPT + 99 others); Tue, 30 Mar 2021 05:48:05 -0400 Received: from mail-ua1-f53.google.com ([209.85.222.53]:40870 "EHLO mail-ua1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231269AbhC3Jrm (ORCPT ); Tue, 30 Mar 2021 05:47:42 -0400 Received: by mail-ua1-f53.google.com with SMTP id 97so4849984uav.7 for ; Tue, 30 Mar 2021 02:47:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8y7oZIw1YMOjEvsLWyQcxtUBXg+Hq4822w/iibJY5oM=; b=s+9dja1FC5zWNvQH/0jnWYwVnQjAIGwpymBv28qiEbSbihnqg6TGH0zMyYmwgpfnKk dt+z9FWS6KK2SYEfyVmPy0NiZmO9DhL7DwpqOdxuH6XR0j0OJnPobwaEHXR3ELduLIUS yRuTMgP9kBWjF3WQkm0Qo15RWL7ovZE0l5xv3JLJ6LoCv7Y0VLl5mO22D6ZthazhiA2J pabof9+vtJVBBU5hj3x3X6V7sIoGmvqN6igmWcV1apBz9la//CH79qLOHEr9+NI7DwYa tp3quQB07FraNa2WjoB/tznhkLOrSd+01gZ7esKQ00qTT9K4N+d84d3wm8txJoo0scl1 DYew== X-Gm-Message-State: AOAM530qj7va1FgwFY348Sw8VXHgRG3fwvfFvvCJ1GJlWV//kM7QTA9f E6d+mvM+jvqm5o32pnSA9QhikKA3hbgVxowU+0E= X-Received: by 2002:ab0:3393:: with SMTP id y19mr16748273uap.2.1617097661466; Tue, 30 Mar 2021 02:47:41 -0700 (PDT) MIME-Version: 1.0 References: <20210313084505.16132-3-alex@ghiti.fr> In-Reply-To: From: Geert Uytterhoeven Date: Tue, 30 Mar 2021 11:47:30 +0200 Message-ID: Subject: Re: [PATCH v3 2/2] riscv: Cleanup KASAN_VMALLOC support To: Palmer Dabbelt Cc: alex@ghiti.fr, Paul Walmsley , Albert Ou , nylon7@andestech.com, Nick Hu , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , linux-riscv , Linux Kernel Mailing List , kasan-dev@googlegroups.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Palmer, On Tue, Mar 30, 2021 at 7:08 AM Palmer Dabbelt wrote: > On Sat, 13 Mar 2021 00:45:05 PST (-0800), alex@ghiti.fr wrote: > > When KASAN vmalloc region is populated, there is no userspace process and > > the page table in use is swapper_pg_dir, so there is no need to read > > SATP. Then we can use the same scheme used by kasan_populate_p*d > > functions to go through the page table, which harmonizes the code. > > > > In addition, make use of set_pgd that goes through all unused page table > > levels, contrary to p*d_populate functions, which makes this function work > > whatever the number of page table levels. > > > > Signed-off-by: Alexandre Ghiti > > Reviewed-by: Palmer Dabbelt > > --- > > arch/riscv/mm/kasan_init.c | 59 ++++++++++++-------------------------- > > 1 file changed, 18 insertions(+), 41 deletions(-) > > > > diff --git a/arch/riscv/mm/kasan_init.c b/arch/riscv/mm/kasan_init.c > > index 57bf4ae09361..c16178918239 100644 > > --- a/arch/riscv/mm/kasan_init.c > > +++ b/arch/riscv/mm/kasan_init.c > > @@ -11,18 +11,6 @@ > > #include > > #include > > > > -static __init void *early_alloc(size_t size, int node) > > -{ > > - void *ptr = memblock_alloc_try_nid(size, size, > > - __pa(MAX_DMA_ADDRESS), MEMBLOCK_ALLOC_ACCESSIBLE, node); > > - > > - if (!ptr) > > - panic("%pS: Failed to allocate %zu bytes align=%zx nid=%d from=%llx\n", > > - __func__, size, size, node, (u64)__pa(MAX_DMA_ADDRESS)); > > - > > - return ptr; > > -} > > - > > extern pgd_t early_pg_dir[PTRS_PER_PGD]; > > asmlinkage void __init kasan_early_init(void) > > { > > @@ -155,38 +143,27 @@ static void __init kasan_populate(void *start, void *end) > > memset(start, KASAN_SHADOW_INIT, end - start); > > } > > > > -void __init kasan_shallow_populate(void *start, void *end) > > +static void __init kasan_shallow_populate_pgd(unsigned long vaddr, unsigned long end) > > { > > - unsigned long vaddr = (unsigned long)start & PAGE_MASK; > > - unsigned long vend = PAGE_ALIGN((unsigned long)end); > > - unsigned long pfn; > > - int index; > > + unsigned long next; > > void *p; > > - pud_t *pud_dir, *pud_k; > > - pgd_t *pgd_dir, *pgd_k; > > - p4d_t *p4d_dir, *p4d_k; > > - > > - while (vaddr < vend) { > > - index = pgd_index(vaddr); > > - pfn = csr_read(CSR_SATP) & SATP_PPN; > > - pgd_dir = (pgd_t *)pfn_to_virt(pfn) + index; > > - pgd_k = init_mm.pgd + index; > > - pgd_dir = pgd_offset_k(vaddr); > > - set_pgd(pgd_dir, *pgd_k); > > - > > - p4d_dir = p4d_offset(pgd_dir, vaddr); > > - p4d_k = p4d_offset(pgd_k, vaddr); > > - > > - vaddr = (vaddr + PUD_SIZE) & PUD_MASK; > > - pud_dir = pud_offset(p4d_dir, vaddr); > > - pud_k = pud_offset(p4d_k, vaddr); > > - > > - if (pud_present(*pud_dir)) { > > - p = early_alloc(PAGE_SIZE, NUMA_NO_NODE); > > - pud_populate(&init_mm, pud_dir, p); > > + pgd_t *pgd_k = pgd_offset_k(vaddr); > > + > > + do { > > + next = pgd_addr_end(vaddr, end); > > + if (pgd_page_vaddr(*pgd_k) == (unsigned long)lm_alias(kasan_early_shadow_pmd)) { > > + p = memblock_alloc(PAGE_SIZE, PAGE_SIZE); > > + set_pgd(pgd_k, pfn_pgd(PFN_DOWN(__pa(p)), PAGE_TABLE)); > > } > > - vaddr += PAGE_SIZE; > > - } > > + } while (pgd_k++, vaddr = next, vaddr != end); > > +} > > + > > +static void __init kasan_shallow_populate(void *start, void *end) > > +{ > > + unsigned long vaddr = (unsigned long)start & PAGE_MASK; > > + unsigned long vend = PAGE_ALIGN((unsigned long)end); > > + > > + kasan_shallow_populate_pgd(vaddr, vend); > > > > local_flush_tlb_all(); > > } > > Thanks, this is on for-next. Your for-next does not include your fixes branch, hence they now conflict, and for-next lacks the local_flush_tlb_all(). Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds