Message ID | 20240131055159.2506-1-yan.y.zhao@intel.com |
---|---|
Headers |
Return-Path: <linux-kernel+bounces-45821-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1703553dyb; Tue, 30 Jan 2024 22:28:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IEp6J2TFk4joQ1u4wvTjtdB+wHX9f2QnwA7xkbyqxWYQI9S7ZaDuKEfHHIouEn6Qjq2HVES X-Received: by 2002:a17:902:e80b:b0:1d9:1fdf:232b with SMTP id u11-20020a170902e80b00b001d91fdf232bmr826747plg.4.1706682482213; Tue, 30 Jan 2024 22:28:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706682482; cv=pass; d=google.com; s=arc-20160816; b=a2H2l1mvPu5e740xiosy+8TflBqpsKlkaa2JPB2lkmrSezLtfpYMMFlbENeKccgpcx 4Wi4uXp9JPT2Sjs5KrGHUhI8ttG0PaSreqVoeoEvMRntAL89sEKGfiTdWcuTluFm65ny eDTNZcSPlxPq4soXJ3721UoHEDCqCihleI4AKob/kDN+KnZn/2vL2vatptazqepB7SuJ +exrjuLos1BowsTbnQPHSfsrr5kb39Wh3lVbTgCGVTN0aL/CKehPrH7wkWaH98KDHVXN dqkO2lOcjf0vqgEPL/Rh6scoQ4sUGFy/hYSsc5Ch4NRBP3zar76gMygjV0RXrl81MkNf H8IQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:cc:to:from:dkim-signature; bh=HrDdXXOAqsDD9LKf8FQWq7Zo9jLg+BleANk9L6c8CgE=; fh=UE+JvUfmiVnQi0vP8YQMij5fIRt806nPpvFR/03WE4A=; b=TMKvbsXBTLd/5WcNPXMDS6oDTeCr2qUGE9U9ZNE2skGhX7KDC4gd2R3JZ/102v/xSy M6d1l6j/YX9smQR8VwwhEAMTCFeGJtgQWfyKEV//UyCORFDVhc1QtfE+PvHYljbmHJ6g 6OdlfKux78EeETDmaVyCyax/fhYVqByvhkVg4/QUhKvruK0t8V6fD+SF4eAmOp2Fg5RD W+lTw9ZBQ5Gs+XvM6fjd50UEuopa3obgWNho0dU4Oh42Hu2zu9Xz9ZGbAyZJC/2dqAXf PHkG8mngoJdWehjg5Or1gIn5m9b3Yeaby5JKYlYFYF1O12Bff++oisJNHHJiFSpenzBO gPSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eAHplHh2; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-45821-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45821-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCWCVPCorDlx1Idn51E0m6jlCXoP/cqPWghXlV4mvRpyQkbHV3s5f5pcu6Upn5nJ3z9Yuq28SGX6gvmUyBlorSRi/nzO5Q== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id u8-20020a17090341c800b001d6ee361679si1122831ple.489.2024.01.30.22.28.01 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 22:28:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45821-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eAHplHh2; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-45821-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45821-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 09188B26721 for <ouuuleilei@gmail.com>; Wed, 31 Jan 2024 06:26:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A15D63F8E6; Wed, 31 Jan 2024 06:25:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="eAHplHh2" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 B390C3EA7A; Wed, 31 Jan 2024 06:25:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706682355; cv=none; b=fg+R+MdYbyl/E6UpHrGvPrH92kBU3oXuxWns8pV5kjr9xOkSND+T7B4Nt0JoRfwYA5mKAnf5uBVBHZp+IU7uZBOjq8FWvld8HVHF3WSwZIaAuz0o0h3r8W1SLm7HbHMB534vaaEnim58T82zLk8CQ5LeLGsMGSPtwW+pWjOE1Ro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706682355; c=relaxed/simple; bh=Dz+rEBJ1wZtGL4hQOfZUqa80XN/mQMePbBMimQSo/DE=; h=From:To:Cc:Subject:Date:Message-Id; b=I0cFyrxwB6CUjqhI5SpUDhovsFHQIqC5p+/pJU4IEqrPpVxsEzqW8DZe7ful/FQgKuPfcqY0guf8oFyyIOLM/i+dWAfcZQftqtWwmwQgDhs4WSvgXMxkfM3Ub88IyoFs6JNjvTG/OoZdaQ9yOBX9pHllMc/b6gEqgpKNbVlTRRA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=eAHplHh2; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706682353; x=1738218353; h=from:to:cc:subject:date:message-id; bh=Dz+rEBJ1wZtGL4hQOfZUqa80XN/mQMePbBMimQSo/DE=; b=eAHplHh2S9pdRDzjgvzFHshNkiSArFrKroXo7QoWq/B812hZ6r8Z/UwD sabFCxTq56v5R+WcUv2ELz6qFPZf7sxg0eB+f066YRfU0IdP7mHIu57yy Mc1U3emt7Mo/Rk/kbsq9hBaM7ZcMRVcr6JVLNL8zaKW3+6KI6sCF6JimX 7fy5sWQwrIHjcSvWf3gIsHEi1pT9Mc7Izmj3Usuoh33qoWYC2+zxNHoG+ vLu8yFUWT8a05EKxed4Aq4Zislw0nUV2WtNDJkc5+W11qifFIaCHgrkVu xk6sCzv6YdEKUzaPWVId1Vxj70GBMsQcPrznm3JoRUiacWEHobr+jEQM0 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="16888137" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="16888137" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 22:25:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="3939842" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 22:25:50 -0800 From: Yan Zhao <yan.y.zhao@intel.com> To: arnd@arndb.de, linus.walleij@linaro.org, guoren@kernel.org, bcain@quicinc.com, jonas@southpole.se, stefan.kristiansson@saunalahti.fi, shorne@gmail.com Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-openrisc@vger.kernel.org, Yan Zhao <yan.y.zhao@intel.com> Subject: [PATCH 0/4] apply page shift to PFN instead of VA in pfn_to_virt Date: Wed, 31 Jan 2024 13:51:59 +0800 Message-Id: <20240131055159.2506-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789586290830330514 X-GMAIL-MSGID: 1789586290830330514 |
Series |
apply page shift to PFN instead of VA in pfn_to_virt
|
|
Message
Yan Zhao
Jan. 31, 2024, 5:51 a.m. UTC
This is a tiny fix to pfn_to_virt() for some platforms. The original implementaion of pfn_to_virt() takes PFN instead of PA as the input to macro __va, with PAGE_SHIFT applying to the converted VA, which is not right under most conditions, especially when there's an offset in __va. Yan Zhao (4): asm-generic/page.h: apply page shift to PFN instead of VA in pfn_to_virt csky: apply page shift to PFN instead of VA in pfn_to_virt Hexagon: apply page shift to PFN instead of VA in pfn_to_virt openrisc: apply page shift to PFN instead of VA in pfn_to_virt arch/csky/include/asm/page.h | 2 +- arch/hexagon/include/asm/page.h | 2 +- arch/openrisc/include/asm/page.h | 2 +- include/asm-generic/page.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) base-commit: 41bccc98fb7931d63d03f326a746ac4d429c1dd3
Comments
On Wed, Jan 31, 2024 at 7:25 AM Yan Zhao <yan.y.zhao@intel.com> wrote: > This is a tiny fix to pfn_to_virt() for some platforms. > > The original implementaion of pfn_to_virt() takes PFN instead of PA as the > input to macro __va, with PAGE_SHIFT applying to the converted VA, which > is not right under most conditions, especially when there's an offset in > __va. Ooops that's right, I wonder why I got it wrong. Arithmetic made it not regress :/ Thank you so much for fixing this Yan! Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Arnd: I think you can take most of them through the arch tree. Yours, Linus Walleij
On Wed, Jan 31, 2024, at 06:51, Yan Zhao wrote: > This is a tiny fix to pfn_to_virt() for some platforms. > > The original implementaion of pfn_to_virt() takes PFN instead of PA as the > input to macro __va, with PAGE_SHIFT applying to the converted VA, which > is not right under most conditions, especially when there's an offset in > __va. > > > Yan Zhao (4): > asm-generic/page.h: apply page shift to PFN instead of VA in > pfn_to_virt > csky: apply page shift to PFN instead of VA in pfn_to_virt > Hexagon: apply page shift to PFN instead of VA in pfn_to_virt > openrisc: apply page shift to PFN instead of VA in pfn_to_virt Nice catch, this is clearly a correct fix, and I can take the series through the asm-generic tree if we want to take this approach. I made a couple of interesting observations looking at this patch though: - this function is only used in architecture specific code on m68k, riscv and s390, though a couple of other architectures have the same definition. - There is another function that does the same thing called pfn_to_kaddr(), which is defined on arm, arm64, csky, loongarch, mips, nios2, powerpc, s390, sh, sparc and x86, as well as yet another pfn_va() on parisc. - the asm-generic/page.h file used to be included by h8300, c6x and blackfin, all of which are now gone. It has no users left and can just as well get removed, unless we find a new use for it. Since it looks like the four broken functions you fix don't have a single caller, maybe it would be better to just remove them all? How exactly did you notice the function being wrong, did you try to add a user somewhere, or just read through the code? Arnd
On Wed, Jan 31, 2024 at 12:48:38PM +0100, Arnd Bergmann wrote: > On Wed, Jan 31, 2024, at 06:51, Yan Zhao wrote: > > This is a tiny fix to pfn_to_virt() for some platforms. > > > > The original implementaion of pfn_to_virt() takes PFN instead of PA as the > > input to macro __va, with PAGE_SHIFT applying to the converted VA, which > > is not right under most conditions, especially when there's an offset in > > __va. > > > > > > Yan Zhao (4): > > asm-generic/page.h: apply page shift to PFN instead of VA in > > pfn_to_virt > > csky: apply page shift to PFN instead of VA in pfn_to_virt > > Hexagon: apply page shift to PFN instead of VA in pfn_to_virt > > openrisc: apply page shift to PFN instead of VA in pfn_to_virt > > Nice catch, this is clearly a correct fix, and I can take > the series through the asm-generic tree if we want to take > this approach. > > I made a couple of interesting observations looking at this patch > though: > > - this function is only used in architecture specific code on > m68k, riscv and s390, though a couple of other architectures > have the same definition. > > - There is another function that does the same thing called > pfn_to_kaddr(), which is defined on arm, arm64, csky, > loongarch, mips, nios2, powerpc, s390, sh, sparc and x86, > as well as yet another pfn_va() on parisc. > > - the asm-generic/page.h file used to be included by h8300, c6x > and blackfin, all of which are now gone. It has no users left > and can just as well get removed, unless we find a new use > for it. > > Since it looks like the four broken functions you fix > don't have a single caller, maybe it would be better to > just remove them all? > > How exactly did you notice the function being wrong, > did you try to add a user somewhere, or just read through > the code? I came across them when I was debugging an unexpected kernel page fault on x86, and I was not sure whether page_to_virt() was compiled in asm-generic/page.h or linux/mm.h. Though finally, it turned out that the one in linux/mm.h was used, which yielded the right result and the unexpected kernel page fault in my case was not related to page_to_virt(), it did lead me to noticing that the pfn_to_virt() in asm-generic/page.h and other 3 archs did not look right. Yes, unlike virt_to_pfn() which still has a caller in openrisc (among csky, Hexagon, openrisc), pfn_to_virt() now does not have a caller in the 3 archs. Though both virt_to_pfn() and pfn_to_virt() are referenced in asm-generic/page.h, I also not sure if we need to remove the asm-generic/page.h which may serve as a template to future archs ? So, either way looks good to me :)
On Thu, Feb 1, 2024, at 01:01, Yan Zhao wrote: > On Wed, Jan 31, 2024 at 12:48:38PM +0100, Arnd Bergmann wrote: >> On Wed, Jan 31, 2024, at 06:51, Yan Zhao wrote: >> >> How exactly did you notice the function being wrong, >> did you try to add a user somewhere, or just read through >> the code? > I came across them when I was debugging an unexpected kernel page fault > on x86, and I was not sure whether page_to_virt() was compiled in > asm-generic/page.h or linux/mm.h. > Though finally, it turned out that the one in linux/mm.h was used, which > yielded the right result and the unexpected kernel page fault in my case > was not related to page_to_virt(), it did lead me to noticing that the > pfn_to_virt() in asm-generic/page.h and other 3 archs did not look right. > > Yes, unlike virt_to_pfn() which still has a caller in openrisc (among > csky, Hexagon, openrisc), pfn_to_virt() now does not have a caller in > the 3 archs. Though both virt_to_pfn() and pfn_to_virt() are referenced > in asm-generic/page.h, I also not sure if we need to remove the > asm-generic/page.h which may serve as a template to future archs ? > > So, either way looks good to me :) I think it's fair to assume we won't need asm-generic/page.h any more, as we likely won't be adding new NOMMU architectures. I can have a look myself at removing any such unused headers in include/asm-generic/, it's probably not the only one. Can you just send a patch to remove the unused pfn_to_virt() functions? Arnd
Hi Arnd, On Thu, Feb 1, 2024 at 11:11 AM Arnd Bergmann <arnd@arndb.de> wrote: > I think it's fair to assume we won't need asm-generic/page.h any > more, as we likely won't be adding new NOMMU architectures. So you think riscv-nommu (k210) was the last one we will ever see? Gr{oetje,eeting}s, Geert
On Thu, Feb 01, 2024 at 06:46:46AM +0100, Arnd Bergmann wrote: > On Thu, Feb 1, 2024, at 01:01, Yan Zhao wrote: > > On Wed, Jan 31, 2024 at 12:48:38PM +0100, Arnd Bergmann wrote: > >> On Wed, Jan 31, 2024, at 06:51, Yan Zhao wrote: > >> > >> How exactly did you notice the function being wrong, > >> did you try to add a user somewhere, or just read through > >> the code? > > I came across them when I was debugging an unexpected kernel page fault > > on x86, and I was not sure whether page_to_virt() was compiled in > > asm-generic/page.h or linux/mm.h. > > Though finally, it turned out that the one in linux/mm.h was used, which > > yielded the right result and the unexpected kernel page fault in my case > > was not related to page_to_virt(), it did lead me to noticing that the > > pfn_to_virt() in asm-generic/page.h and other 3 archs did not look right. > > > > Yes, unlike virt_to_pfn() which still has a caller in openrisc (among > > csky, Hexagon, openrisc), pfn_to_virt() now does not have a caller in > > the 3 archs. Though both virt_to_pfn() and pfn_to_virt() are referenced > > in asm-generic/page.h, I also not sure if we need to remove the > > asm-generic/page.h which may serve as a template to future archs ? > > > > So, either way looks good to me :) > > I think it's fair to assume we won't need asm-generic/page.h any > more, as we likely won't be adding new NOMMU architectures. > I can have a look myself at removing any such unused headers in > include/asm-generic/, it's probably not the only one. > > Can you just send a patch to remove the unused pfn_to_virt() > functions? Ok. I'll do it! BTW: do you think it's also good to keep this fixing series though we'll remove the unused function later? So if people want to revert the removal some day, they can get right one. Or maybe I'm just paranoid, and explanation about the fix in the commit message of patch for function removal is enough. What's your preference? :)
On Fri, Feb 2, 2024, at 02:02, Yan Zhao wrote: > On Thu, Feb 01, 2024 at 06:46:46AM +0100, Arnd Bergmann wrote: >> >> I think it's fair to assume we won't need asm-generic/page.h any >> more, as we likely won't be adding new NOMMU architectures. >> I can have a look myself at removing any such unused headers in >> include/asm-generic/, it's probably not the only one. >> >> Can you just send a patch to remove the unused pfn_to_virt() >> functions? > Ok. I'll do it! > BTW: do you think it's also good to keep this fixing series though we'll > remove the unused function later? > So if people want to revert the removal some day, they can get right one. > > Or maybe I'm just paranoid, and explanation about the fix in the commit > message of patch for function removal is enough. > > What's your preference? :) I would just remove it, there is no point in having both pfn_to_kaddr() and pfn_to_virt() when they do the exact same thing aside from this bug. Just do a single patch for all architectures, no need to have three or four identical ones when I'm going to merge them all through the same tree anyway. Just make sure you explain in the changelog what the bug was and how you noticed it, in case anyone is ever tempted to bring the function back. Arnd
On Thu, Feb 1, 2024, at 11:46, Geert Uytterhoeven wrote: > Hi Arnd, > > On Thu, Feb 1, 2024 at 11:11 AM Arnd Bergmann <arnd@arndb.de> wrote: >> I think it's fair to assume we won't need asm-generic/page.h any >> more, as we likely won't be adding new NOMMU architectures. > > So you think riscv-nommu (k210) was the last one we will ever see? Yes. We've already removed half of the nommu architectures (blackfin, avr32, h8300, m32r, microblaze-nommu) over the past couple of years, and the remaining ones are pretty much only there to support existing users. The only platform one that I see getting real work is esp32 [1], but that is not a new architecture. Arnd [1] https://github.com/jcmvbkbc/linux-xtensa/tree/xtensa-6.8-rc2-esp32
On Fri, Feb 02, 2024 at 08:04:34AM +0100, Arnd Bergmann wrote: > On Fri, Feb 2, 2024, at 02:02, Yan Zhao wrote: > > On Thu, Feb 01, 2024 at 06:46:46AM +0100, Arnd Bergmann wrote: > >> > >> I think it's fair to assume we won't need asm-generic/page.h any > >> more, as we likely won't be adding new NOMMU architectures. > >> I can have a look myself at removing any such unused headers in > >> include/asm-generic/, it's probably not the only one. > >> > >> Can you just send a patch to remove the unused pfn_to_virt() > >> functions? > > Ok. I'll do it! > > BTW: do you think it's also good to keep this fixing series though we'll > > remove the unused function later? > > So if people want to revert the removal some day, they can get right one. > > > > Or maybe I'm just paranoid, and explanation about the fix in the commit > > message of patch for function removal is enough. > > > > What's your preference? :) > > I would just remove it, there is no point in having both > pfn_to_kaddr() and pfn_to_virt() when they do the exact > same thing aside from this bug. > > Just do a single patch for all architectures, no need to > have three or four identical ones when I'm going to merge > them all through the same tree anyway. > > Just make sure you explain in the changelog what the bug was > and how you noticed it, in case anyone is ever tempted to > bring the function back. Done. https://lore.kernel.org/all/20240202140550.9886-1-yan.y.zhao@intel.com Thanks for you guidance :)