Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757771AbcK3OWN convert rfc822-to-8bit (ORCPT ); Wed, 30 Nov 2016 09:22:13 -0500 Received: from smtprelay.synopsys.com ([198.182.60.111]:47372 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757392AbcK3OV7 (ORCPT ); Wed, 30 Nov 2016 09:21:59 -0500 From: Yuriy Kolerov To: Michal Hocko , Yuriy Kolerov CC: "linux-snps-arc@lists.infradead.org" , "Vineet.Gupta1@synopsys.com" , "Alexey.Brodkin@synopsys.com" , "linux-kernel@vger.kernel.org" Subject: RE: [RFC] ARC: mm: Restrict definition of pfn_valid() macro for CONFIG_FLATMEM Thread-Topic: [RFC] ARC: mm: Restrict definition of pfn_valid() macro for CONFIG_FLATMEM Thread-Index: AQHSSlVciXsIgGSP5UaFoLeFGnMOvaDxL3mAgABjQVA= Date: Wed, 30 Nov 2016 14:21:55 +0000 Message-ID: <3ABF60118B9B784CA5BF7C841D2F00EC01025AC2@de02wembxa.internal.synopsys.com> References: <1480433346-18054-1-git-send-email-yuriy.kolerov@synopsys.com> <20161130091637.GC18437@dhcp22.suse.cz> In-Reply-To: <20161130091637.GC18437@dhcp22.suse.cz> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.121.8.63] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1995 Lines: 49 > -----Original Message----- > From: Michal Hocko [mailto:mhocko@kernel.org] > Sent: Wednesday, November 30, 2016 12:17 PM > To: Yuriy Kolerov > Cc: linux-snps-arc@lists.infradead.org; Vineet.Gupta1@synopsys.com; > Alexey.Brodkin@synopsys.com; linux-kernel@vger.kernel.org > Subject: Re: [RFC] ARC: mm: Restrict definition of pfn_valid() macro for > CONFIG_FLATMEM > > On Tue 29-11-16 18:29:06, Yuriy Kolerov wrote: > > Despite the fact that subtraction of unsigned integers is a defined > > behaviour however such operations can lead to unexpected results. Thus > > it is better to check both left and right boundaries to avoid > > potential bugs as it done in the generic page.h. > > Why and which code would use an out of range pfn? Why other arches do > not need to care? Actually some arches do care about checking of both left and right boundaries (e.g. avr32, sparc, etc). The problem is that a value of pfn may be calculated incorrectly in some places of the kernel. E.g. not long ago I sent a patch which fixes truncation of the most significant byte in pfn/pte in some cases (in the kernel with PAE40, however it is not a FLATMEM case). So such situations can happens in the most unexpected places. > > > > Signed-off-by: Yuriy Kolerov > > --- > > arch/arc/include/asm/page.h | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/arch/arc/include/asm/page.h b/arch/arc/include/asm/page.h > > index 296c342..81cfc6c7 100644 > > --- a/arch/arc/include/asm/page.h > > +++ b/arch/arc/include/asm/page.h > > @@ -88,7 +88,7 @@ typedef pte_t * pgtable_t; > > #define ARCH_PFN_OFFSET > virt_to_pfn(CONFIG_LINUX_LINK_BASE) > > > > #ifdef CONFIG_FLATMEM > > -#define pfn_valid(pfn) (((pfn) - ARCH_PFN_OFFSET) < > max_mapnr) > > +#define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && > ((pfn) - ARCH_PFN_OFFSET) < max_mapnr) > > #endif > > > > /* > > -- > > 2.7.4 > > > > -- > Michal Hocko > SUSE Labs