Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp205749pxb; Fri, 15 Jan 2021 00:43:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJx2VLqEdznMmG7dc901b+OqXsdbR30JNJvfNc+JHwfjfDkJWfJ/DXrwzYCVyl1sj7dHfz+u X-Received: by 2002:a05:6402:2288:: with SMTP id cw8mr3994356edb.161.1610700218934; Fri, 15 Jan 2021 00:43:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610700218; cv=none; d=google.com; s=arc-20160816; b=r0mekgC5bwCHqlr2bcRFCFn02MMR3rsGMU97Aa2UgSRKaIoF2MlHd+O9ai21yeiEpN XcbLm4asRAyBmI9agqQrTnpwIeShwFYl9DYHFTDYydS9vzo1zQ2tLuivvIRZYEJFwU/q y1SfdwzbmtVFHJNXFyL4EPLX5/yqtDFSbUY01tCc2F2IvN39NNpmENMD1SRoH1KI2Vr2 uZUgzck1ib2qWxMfeVnp/GFDyQJ0qUdUJVAa5rl3XLYNBJo+zO4OtJGp0XG+CQWrxuok 8qszR3dqOZ8cMAw+9V84JNp6SgVBjrne8XBNINxV66pDWKaaJf8+eheN31x0aL8r5eId Y+pQ== 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=whTBbbuwzuSuP44Iueajqp/PtjcefDAsRVDPTDd0OnA=; b=d3pFFrOaC76fhRcwEHxL/uRsmhjSKCKZq8PqOE7b6pX+YO9NASITDdKisTBgDRrtdv MVs+apmExed/cV24aYJEBT2/eQQQeCFx9JROz2+uJj2HG5yBRHtiG6x3W9k8TEB+uJ2l zXyRTnpvymaA15gFSIke4KsX3BTwLeEsTz1Z9Wqmnomg5GKsX28ot1J+5YJFRVk2G7f+ ORide4tvylMwxGMXo2jQOcbn/Mq3Ht3JFz6iHCjMbC0qv25weSPi4/8anUnruQEYXsS2 Lf4Ah4XUqZr0S/1ADStwxp86d7Pj/W9TwBzaLlnIfkLAgwA5JtcSUk9f1ivuhqsw0l1E OWDA== 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 a10si3811675edq.184.2021.01.15.00.43.14; Fri, 15 Jan 2021 00:43:38 -0800 (PST) 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 S1732136AbhAOH75 (ORCPT + 99 others); Fri, 15 Jan 2021 02:59:57 -0500 Received: from mail-oi1-f173.google.com ([209.85.167.173]:45847 "EHLO mail-oi1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732129AbhAOH75 (ORCPT ); Fri, 15 Jan 2021 02:59:57 -0500 Received: by mail-oi1-f173.google.com with SMTP id f132so8681206oib.12 for ; Thu, 14 Jan 2021 23:59:41 -0800 (PST) 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=whTBbbuwzuSuP44Iueajqp/PtjcefDAsRVDPTDd0OnA=; b=OqDlHDR3t0S05tEFb7N52iGzHHM5yB6IoeGl36/WuTmP5f5Li7kAemTUWi6o9cDMlY tc7u3G6pbgw7SS6dqooqBOTD6Eo2rqlqrF4vYyxVh68OVMbW0a8PaSGyHfyWycyHygsb Pm57ByVTQlyjAYE4BSw2cXvYbaUgnQMobWPjj4qpvR8omZ+fMQGG1tIm2Y0uoJh/CXCk TKV0hxx5UTUoGON2yz/ytc7UY77Fl/VmIS1JGYY8y/k4SvNtruF1znwT9EJ+O+Bfr6rt hQJKzfSsh0tvwjuGYG+L4YjoS4U/cyrcjm9Ihu5o4xbyVgqre3llPuRP8Kl2ovYGPihb U/nQ== X-Gm-Message-State: AOAM532vnXZfLYE0+sK7V4uVTs+ovmT8KX2qYRXReg9MH/XGKxdgE/JF IRyWEGcIo2K0e+VWMluBSAqD+F2oIWtYSE7gXcw= X-Received: by 2002:aca:ec09:: with SMTP id k9mr4937946oih.153.1610697555949; Thu, 14 Jan 2021 23:59:15 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Geert Uytterhoeven Date: Fri, 15 Jan 2021 08:59:04 +0100 Message-ID: Subject: Re: [PATCH 3/4] RISC-V: Fix L1_CACHE_BYTES for RV32 To: Atish Patra Cc: Palmer Dabbelt , Atish Patra , Albert Ou , Anup Patel , "linux-kernel@vger.kernel.org List" , linux-riscv , Paul Walmsley , Nick Kossifidis , Andrew Morton , Ard Biesheuvel , Mike Rapoport Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Atish, On Thu, Jan 14, 2021 at 10:11 PM Atish Patra wrote: > On Thu, Jan 14, 2021 at 11:46 AM Palmer Dabbelt wrote: > > On Thu, 14 Jan 2021 10:33:01 PST (-0800), atishp@atishpatra.org wrote: > > > On Wed, Jan 13, 2021 at 9:10 PM Palmer Dabbelt wrote: > > >> > > >> On Thu, 07 Jan 2021 01:26:51 PST (-0800), Atish Patra wrote: > > >> > SMP_CACHE_BYTES/L1_CACHE_BYTES should be defined as 32 instead of > > >> > 64 for RV32. Otherwise, there will be hole of 32 bytes with each memblock > > >> > allocation if it is requested to be aligned with SMP_CACHE_BYTES. > > >> > > > >> > Signed-off-by: Atish Patra > > >> > --- > > >> > arch/riscv/include/asm/cache.h | 4 ++++ > > >> > 1 file changed, 4 insertions(+) > > >> > > > >> > diff --git a/arch/riscv/include/asm/cache.h b/arch/riscv/include/asm/cache.h > > >> > index 9b58b104559e..c9c669ea2fe6 100644 > > >> > --- a/arch/riscv/include/asm/cache.h > > >> > +++ b/arch/riscv/include/asm/cache.h > > >> > @@ -7,7 +7,11 @@ > > >> > #ifndef _ASM_RISCV_CACHE_H > > >> > #define _ASM_RISCV_CACHE_H > > >> > > > >> > +#ifdef CONFIG_64BIT > > >> > #define L1_CACHE_SHIFT 6 > > >> > +#else > > >> > +#define L1_CACHE_SHIFT 5 > > >> > +#endif > > >> > > > >> > #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) > > >> > > >> Should we not instead just > > >> > > >> #define SMP_CACHE_BYTES L1_CACHE_BYTES > > >> > > >> like a handful of architectures do? > > >> > > > > > > The generic code already defines it that way in include/linux/cache.h > > > > > >> The cache size is sort of fake here, as we don't have any non-coherent > > >> mechanisms, but IIRC we wrote somewhere that it's recommended to have 64-byte > > >> cache lines in RISC-V implementations as software may assume that for > > >> performance reasons. Not really a strong reason, but I'd prefer to just make > > >> these match. > > >> > > > > > > If it is documented somewhere in the kernel, we should update that. I > > > think SMP_CACHE_BYTES being 64 > > > actually degrades the performance as there will be a fragmented memory > > > blocks with 32 bit bytes gap wherever > > > SMP_CACHE_BYTES is used as an alignment requirement. > > > > I don't buy that: if you're trying to align to the cache size then the gaps are > > the whole point. IIUC the 64-byte cache lines come from DDR, not XLEN, so > > there's really no reason for these to be different between the base ISAs. > > > > Got your point. I noticed this when fixing the resource tree issue > where the SMP_CACHE_BYTES > alignment was not intentional but causing the issue. The real issue > was solved via another patch in this series though. > > Just to clarify, if the allocation function intends to allocate > consecutive memory, it should use 32 instead of SMP_CACHE_BYTES. > This will lead to a #ifdef macro in the code. > > > > In addition to that, Geert Uytterhoeven mentioned some panic on vex32 > > > without this patch. > > > I didn't see anything in Qemu though. > > > > Something like that is probably only going to show up on real hardware, QEMU > > doesn't really do anything with the cache line size. That said, as there's > > nothing in our kernel now related to non-coherent memory there really should > > only be performance issue (at least until we have non-coherent systems). > > > > I'd bet that the change is just masking some other bug, either in the software > > or the hardware. I'd prefer to root cause this rather than just working around > > it, as it'll probably come back later and in a more difficult way to find. > > > > Agreed. @Geert Uytterhoeven Can you do a further analysis of the panic > you were saying ? > We may need to change an alignment requirement to 32 for RV32 manually > at some place in code. My findings were in https://lore.kernel.org/linux-riscv/CAMuHMdWf6K-5y02+WJ6Khu1cD6P0n5x1wYQikrECkuNtAA1pgg@mail.gmail.com/ Note that when the memblock.reserved list kept increasing, it kept on adding the same entry to the list. But that was fixed by "[PATCH 1/4] RISC-V: Do not allocate memblock while iterating reserved memblocks". After that, only the (reproducible) "Unable to handle kernel paging request at virtual address 61636473" was left, always at the same place. No idea where the actual corruption happened. 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