From patchwork Tue Feb 27 00:34:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13573019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 269CCC48BF6 for ; Tue, 27 Feb 2024 00:36:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iMtk5sve19558JMPjxP8LcJBblEF3+WBFbTeEH7O2w8=; b=whCBRGIOvP65Ac /EfLrvbr3f44Gdy28nYts+GyyraQJqcu+dVIKA67N0bLlbSSUsVcbLSDV8dWJiwMsou3PDZXWzhuu 5jd1MPFajrcCjN8UVG6ncDcJ93oATJtgyyxctHBh2nlyh9RvrY+vQW9g+ffPsjTe5P1xTSWMc1VQQ xrFtHEkDPA0Q98xhySq+q+GOdSiNHxhoOmb+uVFwhLlOfVG+b7gtY0I2g/O2C1xUrvrzHX2ZB7ylI DQCX020dqDjK/bkULmaQLtVNF62sNw3WI1KLS9RE34nzUfC1K30C6gi3f4jBCFo2RvU+uSOb7CyjO pnQRBd/KQ4J+Df/030ig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1relSZ-000000036yz-0Y4s; Tue, 27 Feb 2024 00:36:39 +0000 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1relSV-000000036x5-2JhE for linux-riscv@lists.infradead.org; Tue, 27 Feb 2024 00:36:36 +0000 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-6e49518f375so1040327a34.1 for ; Mon, 26 Feb 2024 16:36:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1708994194; x=1709598994; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7lRQpFKqbWbNQreMqz6Xcr3vDFL47RlEenB0ubeR/xU=; b=J54WuJWOOGvE4z7qNFmYbGKe0VRuQYes9pvY+KoQhF1pmJCbI74XjrB5ilr70Ctqcp nzuRAuMSNeA0epsDukpihYXyw94conFQzN4lpHirujxwq1EHwqqpx7u6dp6n5ZlY8bDf YuYECBw5u1ki4aNMuCkyxJUoEYX8yLhTwJLe471ucdbW4G/vlJ9QxEkHP0fLW+AZCBBG IkgDNIa1bOEzkxDryHMovydBhkiTxhxt+580BQgelbZCTs0iZkJTDV8Xv351vz9MuCK+ mmrdigFtREzzbLiKRYMmit6dv/MesH9UBmyF21cYXr7vbYuYVqSbxISWBvD84Y/6Mkom wbTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708994194; x=1709598994; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7lRQpFKqbWbNQreMqz6Xcr3vDFL47RlEenB0ubeR/xU=; b=X+n20SdGtmXdyq9HHHrwGLWSkRC6aXVRboso4q9lmt7/IZG/X3MRFVLXKcpqvEECs7 Np/YcKdGzrM+MgZmPvjFNxh6BsZzsCQJhK9zpikY7AGmH9jQHFLyyrD0Bza7RQX23y+7 0nNQEclbqKdur55hF9dEJGSbI1V7s3YZYDOCLpgznPLpQ0xaVn1Ea2s6wFem7Cm6GiN3 6BvtxKpyoh5UUDIzGyXLvKLvDSWuvOXwOpZ76++C6+qC4CBWT6kndbBGngd8pVcelv3q uw2FJkWpH+sJLVOXlXF6k5HrLUpNypO00Y2BlT8zN3gU6SMMM9rmBgOQcBluJo6XQpJc UkuQ== X-Forwarded-Encrypted: i=1; AJvYcCWmaK0+dO2mbvmHUFOhkHjUTYEarJG6dMfEerB3gMHfvr0qKQKxyPhjrzVnRGgr9avdVuiJD7g1Z2DUW9cgXcQKZJ0NG9p3uV9Y8ClpaMyW X-Gm-Message-State: AOJu0Yy0wtNk+QqV4gpEK47+63uIRweGd+JNj/9kKyuGIfX7s9eztVVu h0T32qvHusBdljwT/vrI7AAGimHbuc2A/GX0+iYPJLDFOKOjCDTatHwFVDMu3no= X-Google-Smtp-Source: AGHT+IETqa/FMi7iqDX9bT4O6ZZw50Wgo3XrJ3ohDt+qe+AARTjahlEi4fDnuqyU8dRL02wMEtDtwA== X-Received: by 2002:a9d:7845:0:b0:6e4:85d3:3e65 with SMTP id c5-20020a9d7845000000b006e485d33e65mr9808993otm.8.1708994194200; Mon, 26 Feb 2024 16:36:34 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id z25-20020a631919000000b005dc85821c80sm4504117pgl.12.2024.02.26.16.36.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 16:36:33 -0800 (PST) From: Samuel Holland To: Palmer Dabbelt , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Samuel Holland Subject: [PATCH 1/4] riscv: Fix TASK_SIZE on 64-bit NOMMU Date: Mon, 26 Feb 2024 16:34:46 -0800 Message-ID: <20240227003630.3634533-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227003630.3634533-1-samuel.holland@sifive.com> References: <20240227003630.3634533-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_163635_680380_F974D99E X-CRM114-Status: GOOD ( 11.28 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On NOMMU, userspace memory can come from anywhere in physical RAM. The current definition of TASK_SIZE is wrong if any RAM exists above 4G, causing spurious failures in the userspace access routines. Fixes: 6bd33e1ece52 ("riscv: add nommu support") Fixes: c3f896dcf1e4 ("mm: switch the test_vmalloc module to use __vmalloc_node") Signed-off-by: Samuel Holland Reviewed-by: Jisheng Zhang Reviewed-by: Bo Gan --- arch/riscv/include/asm/pgtable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 0c94260b5d0c..a564a39e5676 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -882,7 +882,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) #define PAGE_SHARED __pgprot(0) #define PAGE_KERNEL __pgprot(0) #define swapper_pg_dir NULL -#define TASK_SIZE 0xffffffffUL +#define TASK_SIZE _AC(-1, UL) #define VMALLOC_START _AC(0, UL) #define VMALLOC_END TASK_SIZE From patchwork Tue Feb 27 00:34:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13573020 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CE02DC54E41 for ; Tue, 27 Feb 2024 00:36:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Fze7OEoRtfkX6EfeOn31upiiCf5As2LdNkKsgPfdgyg=; b=IEEKxaaFnKBcmP V5gQzFYSn9mnzu1slFSzSACg83mvIIhjU9kZLHMlBMdHHgcqkKaFq9W4nU3Dy6g1kXUYMh1GHhClZ e8pMBNyGZyLQ2+VPxT1s0CbOcepa+DTKWvbsqNOYxY79mX762BVFL+UYPEHrLwoCEX0EVDhDF2MkT K2dXfDTwu8pAllS27wMoYIaqSRiaGuCSlh/I1hysHg66Ivej8Ef6Ssqi/Lev52FGBzUQV84taIxhA FYqev6qHOME1tAAxeCJd55j8dxfoflO8/qzaeIk7oQzOpX7WGg0LTVXLoavfqsIR9JPFUIsB5GqAF kqcag+y11AkELJeZEnoQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1relSd-0000000370S-3Xij; Tue, 27 Feb 2024 00:36:43 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1relSW-000000036xd-1lMy for linux-riscv@lists.infradead.org; Tue, 27 Feb 2024 00:36:38 +0000 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6e0f803d9dfso2532587b3a.0 for ; Mon, 26 Feb 2024 16:36:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1708994195; x=1709598995; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xj3OP08z+QmSADpUch3bINy+udg5hxpgq6aJUETENlU=; b=ZcTRf0HFxsZbXWCp8OvncgveRrr9ne0/LSVYbOnryCGzflwG3WkLYzA1QncOReIpeR OHAfYBV4m1Izy5VuBg+5XhLmdPKnc44yL5jl2o/DvAPDrBV6Q+MISAHtAsP3HoEny4Sj RDZcdPjgLpcCWBYnvTtojpwYC7qYDjajNjUkM7GyhmjHRcOpi33lGrD2hVVdz2zL89nN CMvJ9cs/RXzn7DiYjqv9N+JXMPEjuHTfJo7g+40Ibs5+X0E231tJrjN7sfjQ7W7HXUZ7 2doCtmFUz31sfJ0AuV2Ya7l7CikC4h2Hm5x6vgQEkTqGdaIaFCWaqcmHSA6mO6bYoDxq OtYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708994195; x=1709598995; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xj3OP08z+QmSADpUch3bINy+udg5hxpgq6aJUETENlU=; b=jvxFGGnMnGmEGuH8sZjX5buOo4AOsrJT3qJtXIYetDewo4WMoyo/e/Zdmne/aWnw/n OfG32s533qTM5RxOMzYKpUbmtploo+fVDNObm6uNPJ7WKhDRUvv7zXpPPw5yf+slxlXH DHjerjsU19KZsPXuZHB+NaCeMuI42R7vxWOLyyv0/o+OjcviKeC+5X0mh+A9WfcF4b23 fZGIiposFbPWD3UhNWaLQgARuAkHQSwbaYjTVb9WEfB6ESgvH9ExWqyyysYkPOQcUuXC j+ViVNkLu+v6z4+ui72tCjz9jg4N+Un6soz1iPO+Ku46RNjlau/r7O2zyKs3bhz8q/Jg SVZQ== X-Forwarded-Encrypted: i=1; AJvYcCVGJ/x6Wey6RiTtg0XHmyhQA2/Jsu/Aogig+nW88de698/pIZRsWWyKdoPDQDGPbvZlcXZtdOQX2q8ApDbbFA+H7ncv09UL1mjFQxpMSi1I X-Gm-Message-State: AOJu0Yxm28AlX3t+zUgLloP491Z1Qhs+msFmOuqewsYJmZzSpzl1ILOp xxLd2ziJCLzI6YmcBT4OzFUlB5F6yWBnIenK0YMjROTbOM1mLgglLA1m7kx1fdg= X-Google-Smtp-Source: AGHT+IFgPx9lY7vngIVEaxgfVmEppG2EU25f61Y7UcVq+5kUQ65nzj4A2GDggdH2jKZXiIDb84Cgkg== X-Received: by 2002:a05:6a21:910c:b0:1a1:fb:7586 with SMTP id tn12-20020a056a21910c00b001a100fb7586mr944213pzb.57.1708994195402; Mon, 26 Feb 2024 16:36:35 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id z25-20020a631919000000b005dc85821c80sm4504117pgl.12.2024.02.26.16.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 16:36:35 -0800 (PST) From: Samuel Holland To: Palmer Dabbelt , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Samuel Holland Subject: [PATCH 2/4] riscv: Fix loading 64-bit NOMMU kernels past the start of RAM Date: Mon, 26 Feb 2024 16:34:47 -0800 Message-ID: <20240227003630.3634533-3-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227003630.3634533-1-samuel.holland@sifive.com> References: <20240227003630.3634533-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_163636_479937_221CA5B5 X-CRM114-Status: GOOD ( 14.95 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org commit 3335068f8721 ("riscv: Use PUD/P4D/PGD pages for the linear mapping") added logic to allow using RAM below the kernel load address. However, this does not work for NOMMU, where PAGE_OFFSET is fixed to the kernel load address. Since that range of memory corresponds to PFNs below ARCH_PFN_OFFSET, mm initialization runs off the beginning of mem_map and corrupts adjacent kernel memory. Fix this by restoring the previous behavior for NOMMU kernels. Fixes: 3335068f8721 ("riscv: Use PUD/P4D/PGD pages for the linear mapping") Signed-off-by: Samuel Holland --- arch/riscv/include/asm/page.h | 2 +- arch/riscv/mm/init.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index 57e887bfa34c..94b3d6930fc3 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -89,7 +89,7 @@ typedef struct page *pgtable_t; #define PTE_FMT "%08lx" #endif -#ifdef CONFIG_64BIT +#if defined(CONFIG_64BIT) && defined(CONFIG_MMU) /* * We override this value as its generic definition uses __pa too early in * the boot process (before kernel_map.va_pa_offset is set). diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index fa34cf55037b..0c00efc75643 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -232,7 +232,7 @@ static void __init setup_bootmem(void) * In 64-bit, any use of __va/__pa before this point is wrong as we * did not know the start of DRAM before. */ - if (IS_ENABLED(CONFIG_64BIT)) + if (IS_ENABLED(CONFIG_64BIT) && IS_ENABLED(CONFIG_MMU)) kernel_map.va_pa_offset = PAGE_OFFSET - phys_ram_base; /* From patchwork Tue Feb 27 00:34:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13573022 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 73C36C54E55 for ; Tue, 27 Feb 2024 00:36:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=AGcAYD78BnsYOQtIcH5dpFm0P9WnsbgNEsPMB9mDHT0=; b=yY9LjIFqy52ram JCkaaSWkohQeiQUVxTteUnyI2rmjfF8FEMX2v9Q90hFqXN5LOKynAPvTyuPqoH8JbDPnRPJtpS2GR dTGH6XbIskCB+ijlaxjBqFxq9+G9af+t/D26XmzUqoTC8VlNdU6XzVtA2Ts5S0v4T5nLM13rKtcTh 7iML2gezqI4R7IlgMQ0+M0GVbWl1ghbVfEmAMJ2icHdmdFXTxbkazhU2jDVcSFxSgGxnouWnisk1W +IwiV7sR+1yjzuDzM4hTWeOtCNQHf/acOgtKKt4xobNCsYR66d46waEG/0tVjqIgCAt1ByVVFQe/8 vc+rXLI2VTfC/bAvVO5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1relSe-0000000370k-2QDG; Tue, 27 Feb 2024 00:36:44 +0000 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1relSX-000000036yB-2ch5 for linux-riscv@lists.infradead.org; Tue, 27 Feb 2024 00:36:38 +0000 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-5d8b887bb0cso2867125a12.2 for ; Mon, 26 Feb 2024 16:36:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1708994196; x=1709598996; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0DgT08L+OHu5JWWVgI2Bop+R/swEzoI3UepBE4dcuzQ=; b=JYk6113O/rpXaB2MxzfzcCNV+yWYmLYpztUL7LCfy8P2owjL9hZ6BLjb9y8+C6ru7C O1pjofTx64qI+fHF6/WaRQGvNyOE1UyKUHhZRtGDTKjuBW27aY8LSj4JwqSsPSLVDq13 11NYrZID5pUCvKqREyeCN+HLDl/3+ehrDgXok0ACl9vVSx3K42JS66JPdoflA7kl00xm ExUCwdO4QoyFOdmYvwqXBBRIQz8dqrexHvyWjFLOcChyUzz/SR+leMZuZsvgdxTQVaaI /Q3tNuO86LQmm3jTZq2Ohf5Jgq8pjs3TZVs1b73LfSOUS+fyn8u3bBbpMUBc9gww4W7Y yJCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708994196; x=1709598996; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0DgT08L+OHu5JWWVgI2Bop+R/swEzoI3UepBE4dcuzQ=; b=cdGkKra7bowq+PAdY5N+beaI+/un28kqzkZ4uJVhH6yIidsT4qhpFj74jaLe54dhOC ZCVNzm3JmGoYy4MTBqXUtRI6uldltsB6qYM11mKKHk+k25OBKf7+OW4pp0do0uAiD2jX scfnbqbJsGps8HWkyzwIp5kVsSVira0se3a4ifcQ3dD7+QItw9qL2cMLbUcIrmbDramy ggDrHokKDXygk4KMtiBfmrhnusvNTXTABnX8Nlh6Bdpz3RwDwvTaAV0NMHpLpMfMMjwg RLCkUwhJffqqzunQL4qjZYpawLKBU2asifpORdyHEviAWdujOWBolL9QhaW/+aLwxMNT YHSw== X-Forwarded-Encrypted: i=1; AJvYcCUI4HrG02Q5L7pZ0r9NAuY3vPbK3nk9OUbFDdrsfZJLYPEtSE/c5yYQ/EUFregNPyNwV2DbWIqL8AmZo1JOWzWTMBhF3VQg3FvVVrCxyX08 X-Gm-Message-State: AOJu0Yw6cSVr9/XZmV8oX/lARkda1h/MJuZ1bqJcceoqoxNhp66nAQ01 j/bSbtzPxuVK86SIcxWHp/YxFODSHyqzzHYbrUVOMP/IImGE/vz7mx53w1EBd1E= X-Google-Smtp-Source: AGHT+IHpBABr/kwuIBit9b2KbLax70vI2KtrkrHOQQ7ijJ8O9ipFow5FWGR8xS5tvdhxrGR/HHYC6Q== X-Received: by 2002:a05:6a20:6f01:b0:1a0:c3e6:3135 with SMTP id gt1-20020a056a206f0100b001a0c3e63135mr907151pzb.28.1708994196622; Mon, 26 Feb 2024 16:36:36 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id z25-20020a631919000000b005dc85821c80sm4504117pgl.12.2024.02.26.16.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 16:36:36 -0800 (PST) From: Samuel Holland To: Palmer Dabbelt , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Samuel Holland Subject: [PATCH 3/4] riscv: Remove MMU dependency from Zbb and Zicboz Date: Mon, 26 Feb 2024 16:34:48 -0800 Message-ID: <20240227003630.3634533-4-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227003630.3634533-1-samuel.holland@sifive.com> References: <20240227003630.3634533-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_163637_684490_C9DBECEA X-CRM114-Status: UNSURE ( 7.97 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The Zbb and Zicboz ISA extensions have no dependency on an MMU and are equally useful on NOMMU kernels. Signed-off-by: Samuel Holland Reviewed-by: Conor Dooley --- arch/riscv/Kconfig | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index bffbd869a068..ef53c00470d6 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -581,7 +581,6 @@ config TOOLCHAIN_HAS_ZBB config RISCV_ISA_ZBB bool "Zbb extension support for bit manipulation instructions" depends on TOOLCHAIN_HAS_ZBB - depends on MMU depends on RISCV_ALTERNATIVE default y help @@ -613,7 +612,6 @@ config RISCV_ISA_ZICBOM config RISCV_ISA_ZICBOZ bool "Zicboz extension support for faster zeroing of memory" - depends on MMU depends on RISCV_ALTERNATIVE default y help From patchwork Tue Feb 27 00:34:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13573021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 243E4C54E51 for ; Tue, 27 Feb 2024 00:36:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ciH6ZJIJG6CJx/wLO1sMtE+eKFORd1LkrNV++H/HnYo=; b=ETKLA65GDKEN7f titStwyHoAEtn67iz5L8dxL41JvDHyWk+zTILYfeOzrOsclVDfY3KAbngZX/r8D8rdLb8OGDxdRre u/7tzZXVKBHLKBAj8Diw7Z4D/8rj5H2TzmjG3ruTVxOOVoEw3bhwB0hJxgJgj0/z6J3gLClYmkI/Y tWyd/ZMIbxg9LOrM5uJKcw1B4j95TkgKqaGrJ54n7NSOp8UmypJMG0xsWrjwyrZ8uszYAFAtBx/nw MsVc/im/Xg5HCU/Pv5SXYRA8FFvl77ySejWOP4ZH/BIQ/rS1uYgfaTM6m53UCTUMWyXH5N6njI5lT H2wQHLWklZoeHazTKxGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1relSf-0000000371A-1d9V; Tue, 27 Feb 2024 00:36:45 +0000 Received: from mail-oa1-x2d.google.com ([2001:4860:4864:20::2d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1relSZ-000000036yl-0R1K for linux-riscv@lists.infradead.org; Tue, 27 Feb 2024 00:36:40 +0000 Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-214def5da12so1998933fac.2 for ; Mon, 26 Feb 2024 16:36:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1708994198; x=1709598998; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9IhytZLl3RHTt2r80xPYLkB9iZxHThEoH75QMIzrbQ8=; b=D7hTcVkXs2tvZ+DZHCwdXrBEIz9UCfbUIBx6iPRof0WAY5vCIH5BSNuTHbxBAMRgml ErZRoUHSHSWx4vQc9RktBZ6hV74nFnZ6MKYnpdg4cLRhIfip9EF/ts3h1Ic0z5GiK6By kQUeMVFeAyzfWm8xHKaS3FCw++7y42tUhg6KioONVu99gAbIQJTxHoel2tJW/n3Awcfa RPtnYG5vUs4fID0xIKlq7YI+FnklIoipL+uRvZBoHmBccXBMqqFRUe7F0ufxC9n51hnz 8KWedAUPdYSgND6QiF07O5asUUuboyVihoQqiqXglRtBdUYBl2APMVNiKzH2GKFbqKjr lWKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708994198; x=1709598998; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9IhytZLl3RHTt2r80xPYLkB9iZxHThEoH75QMIzrbQ8=; b=aShx5vblIZWajKZ2JtRifzuZntu3BuByiOoZQF4hgSKGYx8pBCDNUKJyiIo14sUJgZ ov4Dg2PdtRDm8lIUCsFLS9xZyeO9NC27bDLJwK+UPNCwONoY3meOm1IY7OfRYNGEh6GW vKb+05rdKNFiZ7qYj5CuvIpEp+TAF0mq5czWlN9P+WxsrPR5N2HI9MFCQX5HO/cprAmg oRHohYcuF92tXZgisIz6hnG/Wr4vEIerLZE3m+Z6XOsRsXAlVB9xttk45+NQhSLgixka YP/biJSwTZcutDjW5PxhUV4UQjgqallOC4cbHcwBkImcmom/fDXDDxYmFq83mgNc+C7U C65A== X-Forwarded-Encrypted: i=1; AJvYcCX7kqvsCSj9UL9k2pvRCg0n2f+fXrnyk/iHyWVL6QcAreqEFMzxc9Eae+eet7XoHbyyVxUGX51IQvO1sKMPRuov+HhS2hcWWEr1k8wX1EtN X-Gm-Message-State: AOJu0YxQDTLs+4IpWesWoX8dyRgRGR15f8SuOUNTNr+UaFqD4aQ6BXML cvDpEz9dNtcGvU1TmcRlgWhSBiLLQYRyFZZMe9Z88hWXpCGCPeTp0PY4XPoUueRjeRFrhSC47Yl N X-Google-Smtp-Source: AGHT+IHuBZg/S/3Di/VYl17m/qNJYD118ohwXH+f7ieMrzQ9VNxL/lys1ubJ/2vm2l8Q2yXGwE0xZw== X-Received: by 2002:a05:6871:230f:b0:21f:a4ce:d532 with SMTP id sf15-20020a056871230f00b0021fa4ced532mr9485542oab.31.1708994197885; Mon, 26 Feb 2024 16:36:37 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id z25-20020a631919000000b005dc85821c80sm4504117pgl.12.2024.02.26.16.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 16:36:37 -0800 (PST) From: Samuel Holland To: Palmer Dabbelt , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Samuel Holland Subject: [PATCH 4/4] riscv: Allow NOMMU kernels to run in S-mode Date: Mon, 26 Feb 2024 16:34:49 -0800 Message-ID: <20240227003630.3634533-5-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227003630.3634533-1-samuel.holland@sifive.com> References: <20240227003630.3634533-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_163639_220958_F7DBCB58 X-CRM114-Status: GOOD ( 10.46 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org For ease of testing, it is convenient to run NOMMU kernels in supervisor mode. The only required change is to offset the kernel load address, since the beginning of RAM is usually reserved for M-mode firmware. Signed-off-by: Samuel Holland Reviewed-by: Conor Dooley --- arch/riscv/Kconfig | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index ef53c00470d6..0dc09b2ac2f6 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -64,7 +64,7 @@ config RISCV select ARCH_WANTS_THP_SWAP if HAVE_ARCH_TRANSPARENT_HUGEPAGE select BINFMT_FLAT_NO_DATA_START_OFFSET if !MMU select BUILDTIME_TABLE_SORT if MMU - select CLINT_TIMER if !MMU + select CLINT_TIMER if RISCV_M_MODE select CLONE_BACKWARDS select COMMON_CLK select CPU_PM if CPU_IDLE || HIBERNATION || SUSPEND @@ -220,8 +220,12 @@ config ARCH_MMAP_RND_COMPAT_BITS_MAX # set if we run in machine mode, cleared if we run in supervisor mode config RISCV_M_MODE - bool - default !MMU + bool "Build a kernel that runs in machine mode" + depends on !MMU + default y + help + Select this option if you want to run the kernel in M-mode, + without the assistance of any other firmware. # set if we are running in S-mode and can use SBI calls config RISCV_SBI @@ -238,8 +242,9 @@ config MMU config PAGE_OFFSET hex - default 0xC0000000 if 32BIT && MMU - default 0x80000000 if !MMU + default 0x80000000 if !MMU && RISCV_M_MODE + default 0x80200000 if !MMU + default 0xc0000000 if 32BIT default 0xff60000000000000 if 64BIT config KASAN_SHADOW_OFFSET