From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 167D33AA4F1 for ; Fri, 17 Jul 2026 07:55:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784274951; cv=none; b=XO8RDzq0zLC/KcbwiFnSyV1aRc7teo+MuvQTtmhyPW3MWvACoEVoWFdJH3AnJfTQbtITEBJBGbjLAxIbCeKDbw86Va8gPwTWu2IPPa+cGd+zMqCkP5ID9D8vz6/v67fPw7qe7OqOf79BKSI7KXiMu43RHBzJ591F/4Uxm/MktZU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784274951; c=relaxed/simple; bh=VCEVOs29qy41aLYqLsGVMHFWJos3BWY8pBqqujyqSaI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XXXGwRAyOJi6Z6fZGwSEReO96Nlb/2g4dLoSmo+KcFydPcO36+A+p6d07Xq32zjo9GnY/z4JgXLn1b1spyAwx4RfMxT1QwJ7jijmcQiJvVqdLQwF/cm8BnvI5LConEK63delyYFdGlJYenTjil/BrT/YSWrjzlDQTJ4ENkqW7ok= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=DU+ugemJ; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="DU+ugemJ" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E66881477; Fri, 17 Jul 2026 00:55:43 -0700 (PDT) Received: from e129823.arm.com (e129823.arm.com [10.2.213.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AAAC53F7B4; Fri, 17 Jul 2026 00:55:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1784274948; bh=VCEVOs29qy41aLYqLsGVMHFWJos3BWY8pBqqujyqSaI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DU+ugemJvHBveBuL7dk8dm1kcBJotHvCGONmuQ5C4OeV57RJUzo7ZQjdR10jl5Jx7 5L9Qh62wclbS5bjS5wPcNYuj7MV0SVESp9mh+ohyQWIHooRsWMeuoL7g/xSUEC0PGr Xt2Bp1YeFZMziIbvkg6+QSc6bbWvC8xsO7Wptwks= Date: Fri, 17 Jul 2026 08:55:34 +0100 From: Yeoreum Yun To: Arnd Bergmann Cc: Yeoreum Yun , Pedro Falcato , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, Linux-Arch , kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, "linux-csky@vger.kernel.org" , linux-m68k@lists.linux-m68k.org, "linux-openrisc@vger.kernel.org" , "David Hildenbrand (Red Hat)" , Russell King , Andrew Morton , Ankur Arora , Mike Rapoport , Magnus Lindholm , Christophe Leroy , Klara Modin , Huacai Chen , WANG Xuerui , "Kirill A. Shutemov" , zhangtianyang@loongson.cn, wangyuli@aosc.io, Thomas Bogendoerfer , Lorenzo Stoakes , Jason Gunthorpe , Catalin Marinas , Will Deacon , Ryan Roberts , Pasha Tatashin , Rohan McLure , Baolin Wang , Tejun Heo , Kevin Brodsky , Anup Patel , atish.patra@linux.dev, Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Johannes Weiner , Michal Hocko , qi.zheng@linux.dev, Shakeel Butt , Kairui Song , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Anshuman Khandual , Yang Shi , chaitanyas.prakash@arm.com, Ard Biesheuvel , guoren , yang.li85200@gmail.com, Alexander Viro , Dinh Nguyen , "schuster.simon@siemens-energy.com" , Vivian Wang , junhui.liu@pigmoral.tech, Muchun Song , "Vishal Moola (Oracle)" , Nam Cao , Pavel Machek , djbw@kernel.org, yu-cheng.yu@intel.com, Baolu Lu , Jonathan Cameron , Coiby Xu , Andreas Larsson , "Liam R. Howlett" , "Vlastimil Babka (SUSE)" , Suren Baghdasaryan , Michal Hocko , Geert Uytterhoeven , Stafford Horne , Jonas Bonn , Stefan Kristiansson Subject: Re: [RFC PATCH 02/34] ARM: mm: make 2-level pgd_t a scalar Message-ID: References: <20260713135614.1618183-1-yeoreum.yun@arm.com> <20260713135614.1618183-3-yeoreum.yun@arm.com> <4c3067df-20f0-43e8-8e62-354888afac04@app.fastmail.com> Precedence: bulk X-Mailing-List: linux-m68k@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4c3067df-20f0-43e8-8e62-354888afac04@app.fastmail.com> On Fri, Jul 17, 2026 at 08:16:55AM +0200, Arnd Bergmann wrote: > On Thu, Jul 16, 2026, at 21:04, Yeoreum Yun wrote: > >> > >> > Ugh. This isn't correct C code. It only works because the kernel passes > >> > -fno-strict-aliasing. > >> > >> I think the bigger problem is the code dereferencing the pgd > >> pointer in the first place: Since the pgd pair is written in > >> 32-bit units in __pmd_populate(), anything reading it would > >> technically have to operate on both entries. > >> > >> As the kernel relies on -fno-strict-aliasing, the type mismatch > >> is less of a problem than actually doing the potentially wrong > >> thing. > >> > >> As far as I can tell, we are however saved by pgd_val() > >> only ever being used for debug prints, where printing > >> the first entry is likely all that is needed to analyse > >> the real bug. > >> > >> > I would recommend either forcing a struct here, or > >> > using a u64 with bitmasks/shifts. > >> > >> That would require extra complexity for the big-endian > >> case though. > > > > Agree. And since the users of pgd_val() mostly uses with > > pmd_pfn(), pmd_page() and etc. I think it doesn't matter to return > > lower pmdval_t or higher one. > > > > Therefore, without considering endianess, it's enough with downcast > > like: > > > > #define pgd_val(x) ((pmdval_t)x) > > > > Could we apply this in next version? > > I would just leave the original version here, at least it > keeps the current behavior for something that is easy to > get wrong. Taking the second entry on big-endian sounds > counterintuitive, especially when you have a hugetlb > mapping where the two don't just point to the same page. Thanks. Even my simple tests with GCC versions 8.5.0 through 16.1.0 in [0], did not spill to the stack. So keeping David's original implementation seems reasonable. Link: [0] https://www.kernel.org/pub/tools/crosstool/ -- Sincerely, Yeoreum Yun From mboxrd@z Thu Jan 1 00:00:00 1970 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 61E3DC44507 for ; Fri, 17 Jul 2026 07:56:16 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PcfwoNjL+zX97MHTJT5wiXm5HxTsH9prMghn52wo0iw=; b=ujIVxFk3jIfJ/s x+tGXGjlu9ajanbieAdxEGGJ/UCTMS7WUT8xxowXmCFdH6fGLQYurM2o1r72P8+y+xmIH/FuJBjs+ fmJ+z0dauy29hCNyqjVQpri5gbGgG3ZrcRQ+h7VzmKl0mS0SKDGl5fJA8nlL4eoJOnZ8gg8ujR4Gf jmAwvFeW1XuEUokRnkWAk9e6rYuC5zS2R5plhB23cw6fgCSxexsdodIRVqo1a7Pjd/nnlFe37R3OG t++dBI+HMJKQZyRoMn+q29Siyrys/rrDRWHQx1we7Q/uap12anjvGC/TKe4hFK+AnNElweJBkPzY2 QmgrrkAIHktbkxclS68g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wkdQJ-00000001WMB-15qj; Fri, 17 Jul 2026 07:55:55 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wkdQF-00000001WLC-0TqO; Fri, 17 Jul 2026 07:55:53 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E66881477; Fri, 17 Jul 2026 00:55:43 -0700 (PDT) Received: from e129823.arm.com (e129823.arm.com [10.2.213.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AAAC53F7B4; Fri, 17 Jul 2026 00:55:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1784274948; bh=VCEVOs29qy41aLYqLsGVMHFWJos3BWY8pBqqujyqSaI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DU+ugemJvHBveBuL7dk8dm1kcBJotHvCGONmuQ5C4OeV57RJUzo7ZQjdR10jl5Jx7 5L9Qh62wclbS5bjS5wPcNYuj7MV0SVESp9mh+ohyQWIHooRsWMeuoL7g/xSUEC0PGr Xt2Bp1YeFZMziIbvkg6+QSc6bbWvC8xsO7Wptwks= Date: Fri, 17 Jul 2026 08:55:34 +0100 From: Yeoreum Yun To: Arnd Bergmann Cc: Yeoreum Yun , Pedro Falcato , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, Linux-Arch , kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, "linux-csky@vger.kernel.org" , linux-m68k@lists.linux-m68k.org, "linux-openrisc@vger.kernel.org" , "David Hildenbrand (Red Hat)" , Russell King , Andrew Morton , Ankur Arora , Mike Rapoport , Magnus Lindholm , Christophe Leroy , Klara Modin , Huacai Chen , WANG Xuerui , "Kirill A. Shutemov" , zhangtianyang@loongson.cn, wangyuli@aosc.io, Thomas Bogendoerfer , Lorenzo Stoakes , Jason Gunthorpe , Catalin Marinas , Will Deacon , Ryan Roberts , Pasha Tatashin , Rohan McLure , Baolin Wang , Tejun Heo , Kevin Brodsky , Anup Patel , atish.patra@linux.dev, Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Johannes Weiner , Michal Hocko , qi.zheng@linux.dev, Shakeel Butt , Kairui Song , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Anshuman Khandual , Yang Shi , chaitanyas.prakash@arm.com, Ard Biesheuvel , guoren , yang.li85200@gmail.com, Alexander Viro , Dinh Nguyen , "schuster.simon@siemens-energy.com" , Vivian Wang , junhui.liu@pigmoral.tech, Muchun Song , "Vishal Moola (Oracle)" , Nam Cao , Pavel Machek , djbw@kernel.org, yu-cheng.yu@intel.com, Baolu Lu , Jonathan Cameron , Coiby Xu , Andreas Larsson , "Liam R. Howlett" , "Vlastimil Babka (SUSE)" , Suren Baghdasaryan , Michal Hocko , Geert Uytterhoeven , Stafford Horne , Jonas Bonn , Stefan Kristiansson Subject: Re: [RFC PATCH 02/34] ARM: mm: make 2-level pgd_t a scalar Message-ID: References: <20260713135614.1618183-1-yeoreum.yun@arm.com> <20260713135614.1618183-3-yeoreum.yun@arm.com> <4c3067df-20f0-43e8-8e62-354888afac04@app.fastmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4c3067df-20f0-43e8-8e62-354888afac04@app.fastmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260717_005551_344237_B2D842AD X-CRM114-Status: GOOD ( 26.11 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Fri, Jul 17, 2026 at 08:16:55AM +0200, Arnd Bergmann wrote: > On Thu, Jul 16, 2026, at 21:04, Yeoreum Yun wrote: > >> > >> > Ugh. This isn't correct C code. It only works because the kernel passes > >> > -fno-strict-aliasing. > >> > >> I think the bigger problem is the code dereferencing the pgd > >> pointer in the first place: Since the pgd pair is written in > >> 32-bit units in __pmd_populate(), anything reading it would > >> technically have to operate on both entries. > >> > >> As the kernel relies on -fno-strict-aliasing, the type mismatch > >> is less of a problem than actually doing the potentially wrong > >> thing. > >> > >> As far as I can tell, we are however saved by pgd_val() > >> only ever being used for debug prints, where printing > >> the first entry is likely all that is needed to analyse > >> the real bug. > >> > >> > I would recommend either forcing a struct here, or > >> > using a u64 with bitmasks/shifts. > >> > >> That would require extra complexity for the big-endian > >> case though. > > > > Agree. And since the users of pgd_val() mostly uses with > > pmd_pfn(), pmd_page() and etc. I think it doesn't matter to return > > lower pmdval_t or higher one. > > > > Therefore, without considering endianess, it's enough with downcast > > like: > > > > #define pgd_val(x) ((pmdval_t)x) > > > > Could we apply this in next version? > > I would just leave the original version here, at least it > keeps the current behavior for something that is easy to > get wrong. Taking the second entry on big-endian sounds > counterintuitive, especially when you have a hugetlb > mapping where the two don't just point to the same page. Thanks. Even my simple tests with GCC versions 8.5.0 through 16.1.0 in [0], did not spill to the stack. So keeping David's original implementation seems reasonable. Link: [0] https://www.kernel.org/pub/tools/crosstool/ -- Sincerely, Yeoreum Yun _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 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 8CE50C44514 for ; Fri, 17 Jul 2026 07:55:54 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=v/QVHqVoKYWjmnZG0d2T7TmtWXE8yB3rRtl5LZ/kYc4=; b=yAncCrGIyd9ZuP pxAxqCBgz+OF7MfIjsGsnUQGRGY8YriDDCqrUdfWjTtvSocn2DTTl6FucwRzkTG8SOhIPtPsXO0+g p9umtshy5fXobbzV//GNQnMjtTzKL+udVwfvBrIPTufFP5ogcb3+0Jcte05lm9ozgqpOdmrWf9I1g cmIzdrZpLXz0Ws+v6FfZAibqZtGQf9xjgmNYFrR9LAYAm/yC5PcGMEwlLn3gzOohEvNeruO1NjxXQ ft9wZl9gEBgFXJCz5Qj+4B5INueFWO0o1AL9HwO12s0WqOb8qfJIv2jPiJnFsKRbsS1Zu5hthin8N zQf42HldnQ0DHngqbo+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wkdQI-00000001WLt-0sdq; Fri, 17 Jul 2026 07:55:54 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wkdQF-00000001WLC-0TqO; Fri, 17 Jul 2026 07:55:53 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E66881477; Fri, 17 Jul 2026 00:55:43 -0700 (PDT) Received: from e129823.arm.com (e129823.arm.com [10.2.213.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AAAC53F7B4; Fri, 17 Jul 2026 00:55:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1784274948; bh=VCEVOs29qy41aLYqLsGVMHFWJos3BWY8pBqqujyqSaI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DU+ugemJvHBveBuL7dk8dm1kcBJotHvCGONmuQ5C4OeV57RJUzo7ZQjdR10jl5Jx7 5L9Qh62wclbS5bjS5wPcNYuj7MV0SVESp9mh+ohyQWIHooRsWMeuoL7g/xSUEC0PGr Xt2Bp1YeFZMziIbvkg6+QSc6bbWvC8xsO7Wptwks= Date: Fri, 17 Jul 2026 08:55:34 +0100 From: Yeoreum Yun To: Arnd Bergmann Cc: Yeoreum Yun , Pedro Falcato , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, Linux-Arch , kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, "linux-csky@vger.kernel.org" , linux-m68k@lists.linux-m68k.org, "linux-openrisc@vger.kernel.org" , "David Hildenbrand (Red Hat)" , Russell King , Andrew Morton , Ankur Arora , Mike Rapoport , Magnus Lindholm , Christophe Leroy , Klara Modin , Huacai Chen , WANG Xuerui , "Kirill A. Shutemov" , zhangtianyang@loongson.cn, wangyuli@aosc.io, Thomas Bogendoerfer , Lorenzo Stoakes , Jason Gunthorpe , Catalin Marinas , Will Deacon , Ryan Roberts , Pasha Tatashin , Rohan McLure , Baolin Wang , Tejun Heo , Kevin Brodsky , Anup Patel , atish.patra@linux.dev, Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Johannes Weiner , Michal Hocko , qi.zheng@linux.dev, Shakeel Butt , Kairui Song , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Anshuman Khandual , Yang Shi , chaitanyas.prakash@arm.com, Ard Biesheuvel , guoren , yang.li85200@gmail.com, Alexander Viro , Dinh Nguyen , "schuster.simon@siemens-energy.com" , Vivian Wang , junhui.liu@pigmoral.tech, Muchun Song , "Vishal Moola (Oracle)" , Nam Cao , Pavel Machek , djbw@kernel.org, yu-cheng.yu@intel.com, Baolu Lu , Jonathan Cameron , Coiby Xu , Andreas Larsson , "Liam R. Howlett" , "Vlastimil Babka (SUSE)" , Suren Baghdasaryan , Michal Hocko , Geert Uytterhoeven , Stafford Horne , Jonas Bonn , Stefan Kristiansson Subject: Re: [RFC PATCH 02/34] ARM: mm: make 2-level pgd_t a scalar Message-ID: References: <20260713135614.1618183-1-yeoreum.yun@arm.com> <20260713135614.1618183-3-yeoreum.yun@arm.com> <4c3067df-20f0-43e8-8e62-354888afac04@app.fastmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4c3067df-20f0-43e8-8e62-354888afac04@app.fastmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260717_005551_344237_B2D842AD X-CRM114-Status: GOOD ( 26.11 ) X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+kvm-riscv=archiver.kernel.org@lists.infradead.org On Fri, Jul 17, 2026 at 08:16:55AM +0200, Arnd Bergmann wrote: > On Thu, Jul 16, 2026, at 21:04, Yeoreum Yun wrote: > >> > >> > Ugh. This isn't correct C code. It only works because the kernel passes > >> > -fno-strict-aliasing. > >> > >> I think the bigger problem is the code dereferencing the pgd > >> pointer in the first place: Since the pgd pair is written in > >> 32-bit units in __pmd_populate(), anything reading it would > >> technically have to operate on both entries. > >> > >> As the kernel relies on -fno-strict-aliasing, the type mismatch > >> is less of a problem than actually doing the potentially wrong > >> thing. > >> > >> As far as I can tell, we are however saved by pgd_val() > >> only ever being used for debug prints, where printing > >> the first entry is likely all that is needed to analyse > >> the real bug. > >> > >> > I would recommend either forcing a struct here, or > >> > using a u64 with bitmasks/shifts. > >> > >> That would require extra complexity for the big-endian > >> case though. > > > > Agree. And since the users of pgd_val() mostly uses with > > pmd_pfn(), pmd_page() and etc. I think it doesn't matter to return > > lower pmdval_t or higher one. > > > > Therefore, without considering endianess, it's enough with downcast > > like: > > > > #define pgd_val(x) ((pmdval_t)x) > > > > Could we apply this in next version? > > I would just leave the original version here, at least it > keeps the current behavior for something that is easy to > get wrong. Taking the second entry on big-endian sounds > counterintuitive, especially when you have a hugetlb > mapping where the two don't just point to the same page. Thanks. Even my simple tests with GCC versions 8.5.0 through 16.1.0 in [0], did not spill to the stack. So keeping David's original implementation seems reasonable. Link: [0] https://www.kernel.org/pub/tools/crosstool/ -- Sincerely, Yeoreum Yun -- kvm-riscv mailing list kvm-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kvm-riscv