Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp722244lqo; Wed, 8 May 2024 12:43:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVa2QK8UXnXddlWtR3jFvAfvDB9kD2vfy5aBBZpDqHRMTFu9wv0PSEuzTveeNru+qVb23dih7oGBNg34N0wQ8MTVFJm8swkScUMWfeacg== X-Google-Smtp-Source: AGHT+IHnrTsDvmmii7R9ElCE5Lq0xmTL3Ac0RD3X3UVf1c8bV1mJ87znGMqT0ElCORuq9xlgFZOn X-Received: by 2002:a50:9f44:0:b0:56e:7751:ae4e with SMTP id 4fb4d7f45d1cf-5731da64035mr2511773a12.33.1715197404996; Wed, 08 May 2024 12:43:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715197404; cv=pass; d=google.com; s=arc-20160816; b=s54kgqA+73HDOlU2o23SYAzAkIFbQ3Et9qtDA+unW8QQG46UYqqGmJpSO/6CG+khYV qxgyv4IjXRFu8ah5T0RwfBnsR8AIAm5F7wi3ho1p/jWHPPIDk4jQmtv8z7ZfrvfNZMUH niEZd6EC2NqAg2T+WEXg/AM0ER9lsKVLmPi1ME8AhJN7R01Bnol/N3T4PclNdFUM9LR2 SjbFhfXSf7Wb1lc5hA4E+tGaFM/+uClldeDllZhwp7z87wmRRh7wJhjd9J7RJIeCGWGz Acj/6QkUE5oJ65wGsW0Ic2PMu5aFicOWNiBT10yeDmCa1vPE+w3AALm+VEw++aF0NecQ /mbQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=RmsAagdCJULDxBLEuJ49YLWe0SmVC2PXABLCkKy6svI=; fh=cY2M5pyFT4bUObSFz+Z/7SeN8zpECSJo3kJpEdw3e4k=; b=SEaGOrF6WoZ3Seseo3FSyp3Xo79s/sg5sI1yPgPiIxnZTKrGR1IiXgOr3ShOWJJGPs EjI1RlbWwBpcOJemDBbICFL6w1QixO+MaBIA0RUnoPtj7DkikOc6Qb+pSdTv+TJ2yE3w K0Nzmz0wcbItGDraLPUYHMmgEJZcY7qPQXzXBJfKxYj5ze6+AkqsjE+1Y6J94koCn2Gg PW5X40SCshXXW2IX3e7ZhZwhVLueVJnkK0c461YzOIe+17ehemULgFP9ooremu3KVXwq rhc3qjD5D4XUaIi8cXStg+M11Au+poUk+TL8nJDlqgZ4NNopzzSHwb3fbSH7M2ZqS/oU vvUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=ghiti.fr); spf=pass (google.com: domain of linux-kernel+bounces-173775-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173775-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d4-20020aa7c1c4000000b00572a808c7b9si7350763edp.375.2024.05.08.12.43.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 12:43:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-173775-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=ghiti.fr); spf=pass (google.com: domain of linux-kernel+bounces-173775-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173775-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B7DAC1F2187E for ; Wed, 8 May 2024 19:43:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 58C3412BF23; Wed, 8 May 2024 19:43:18 +0000 (UTC) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B52BB39AD6 for ; Wed, 8 May 2024 19:43:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715197397; cv=none; b=F2CHc5nMyiQF66JaTpKCIIGabXwT5vO88dh/75Di4dXlnmNShnVFzaqopcHjTkFtRUFuFWz2EmS2x67c2Syji1klKISRFMW8OwgRfXP5yXO7t7fqVoywcbme3v8f6XiJ48jBeXzyoRkOBNAbPRr6a0WmgeSSviU2lckQbPgmecI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715197397; c=relaxed/simple; bh=ghYZ1xj0MjCSVqlIaq8fQKUVO36T7/5GUKecLsvIyvc=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=EL9NdcKKTxbrEZQhlSzX5U1MuaawrWbKYhTCGsw902noMKyyJbo3FfWPm2QmKcvk2aegHUzgHmAhpBPR/go6yuxE9o3iGbjg7XtCbwx7lWgu1K9czR0IpwcQKBg8GiGl+AaOaMvt0i80EGHa0tgesLL1Cf+9CUvjiHysad6ud+0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr; spf=pass smtp.mailfrom=ghiti.fr; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ghiti.fr Received: by mail.gandi.net (Postfix) with ESMTPSA id 30CAC40002; Wed, 8 May 2024 19:43:11 +0000 (UTC) Message-ID: Date: Wed, 8 May 2024 21:43:11 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] riscv: change XIP's kernel_map.size to be size of the entire kernel Content-Language: en-US To: Nam Cao , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org References: <20240508191917.2892064-1-namcao@linutronix.de> From: Alexandre Ghiti In-Reply-To: <20240508191917.2892064-1-namcao@linutronix.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Flag: yes X-Spam-Level: ************************** X-GND-Spam-Score: 400 X-GND-Status: SPAM X-GND-Sasl: alex@ghiti.fr Hi Nam, On 08/05/2024 21:19, Nam Cao wrote: > With XIP kernel, kernel_map.size is set to be only the size of data part of > the kernel. This is inconsistent with "normal" kernel, who sets it to be > the size of the entire kernel. > > More importantly, XIP kernel fails to boot if CONFIG_DEBUG_VIRTUAL is > enabled, because there are checks on virtual addresses with the assumption > that kernel_map.size is the size of the entire kernel (these checks are in > arch/riscv/mm/physaddr.c). > > Change XIP's kernel_map.size to be the size of the entire kernel. > > Signed-off-by: Nam Cao > Cc: # v6.1+ > --- > I wouldn't consider this inconsistency to be a bug. It only became a > a problem after kernel_map.size is used to check virtual addresses in > 5f763b3b5960 ("riscv: Fix DEBUG_VIRTUAL false warnings"). So I will only > backport this to stable versions that contain this commit: v6.1+ > > arch/riscv/mm/init.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c > index c081e7d349b1..0c0562839899 100644 > --- a/arch/riscv/mm/init.c > +++ b/arch/riscv/mm/init.c > @@ -903,7 +903,7 @@ static void __init create_kernel_page_table(pgd_t *pgdir, > PMD_SIZE, PAGE_KERNEL_EXEC); > > /* Map the data in RAM */ > - end_va = kernel_map.virt_addr + XIP_OFFSET + kernel_map.size; > + end_va = kernel_map.virt_addr + kernel_map.size; > for (va = kernel_map.virt_addr + XIP_OFFSET; va < end_va; va += PMD_SIZE) > create_pgd_mapping(pgdir, va, > kernel_map.phys_addr + (va - (kernel_map.virt_addr + XIP_OFFSET)), > @@ -1072,7 +1072,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) > > phys_ram_base = CONFIG_PHYS_RAM_BASE; > kernel_map.phys_addr = (uintptr_t)CONFIG_PHYS_RAM_BASE; > - kernel_map.size = (uintptr_t)(&_end) - (uintptr_t)(&_sdata); > + kernel_map.size = (uintptr_t)(&_end) - (uintptr_t)(&_start); > > kernel_map.va_kernel_xip_pa_offset = kernel_map.virt_addr - kernel_map.xiprom; > #else You can add: Reviewed-by: Alexandre Ghiti Thanks, Alex