From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754405AbbIKWrc (ORCPT ); Fri, 11 Sep 2015 18:47:32 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:53430 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753944AbbIKWrb (ORCPT ); Fri, 11 Sep 2015 18:47:31 -0400 Date: Fri, 11 Sep 2015 15:47:30 -0700 From: Andrew Morton To: Xishi Qiu Cc: Andrey Konovalov , Rusty Russell , Michal Marek , "long.wanglong" , Linux MM , LKML , Andrey Ryabinin Subject: Re: [PATCH] kasan: use IS_ALIGNED in memory_is_poisoned_8() Message-Id: <20150911154730.3a2151a0b111fed01acdaaa1@linux-foundation.org> In-Reply-To: <55F23635.1010109@huawei.com> References: <55F23635.1010109@huawei.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 11 Sep 2015 10:02:29 +0800 Xishi Qiu wrote: > Use IS_ALIGNED() to determine whether the shadow span two bytes. > It generates less code and more readable. > Please cc Andrey Ryabinin on kasan patches. > --- a/mm/kasan/kasan.c > +++ b/mm/kasan/kasan.c > @@ -120,7 +120,7 @@ static __always_inline bool memory_is_poisoned_8(unsigned long addr) > if (memory_is_poisoned_1(addr + 7)) > return true; > > - if (likely(((addr + 7) & KASAN_SHADOW_MASK) >= 7)) > + if (likely(IS_ALIGNED(addr, 8))) > return false; Wouldn't IS_ALIGNED(addr, KASAN_SHADOW_SCALE_SIZE) be more appropriate? But I'm not really sure what the original code is trying to do. if ((addr + 7) & 7) >= 7) can only evaluate true if ((addr + 7) & 7) equals 7, so the ">=" could be "==". I think. The code looks a bit weird. A code comment would help. And how come memory_is_poisoned_16() does IS_ALIGNED(addr, 8)? Should it be 16? From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qg0-f47.google.com (mail-qg0-f47.google.com [209.85.192.47]) by kanga.kvack.org (Postfix) with ESMTP id 0153D6B0038 for ; Fri, 11 Sep 2015 18:47:33 -0400 (EDT) Received: by qgt47 with SMTP id 47so75029147qgt.2 for ; Fri, 11 Sep 2015 15:47:32 -0700 (PDT) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org. [140.211.169.12]) by mx.google.com with ESMTPS id g77si2201120qhc.64.2015.09.11.15.47.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Sep 2015 15:47:32 -0700 (PDT) Date: Fri, 11 Sep 2015 15:47:30 -0700 From: Andrew Morton Subject: Re: [PATCH] kasan: use IS_ALIGNED in memory_is_poisoned_8() Message-Id: <20150911154730.3a2151a0b111fed01acdaaa1@linux-foundation.org> In-Reply-To: <55F23635.1010109@huawei.com> References: <55F23635.1010109@huawei.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Xishi Qiu Cc: Andrey Konovalov , Rusty Russell , Michal Marek , "long.wanglong" , Linux MM , LKML , Andrey Ryabinin On Fri, 11 Sep 2015 10:02:29 +0800 Xishi Qiu wrote: > Use IS_ALIGNED() to determine whether the shadow span two bytes. > It generates less code and more readable. > Please cc Andrey Ryabinin on kasan patches. > --- a/mm/kasan/kasan.c > +++ b/mm/kasan/kasan.c > @@ -120,7 +120,7 @@ static __always_inline bool memory_is_poisoned_8(unsigned long addr) > if (memory_is_poisoned_1(addr + 7)) > return true; > > - if (likely(((addr + 7) & KASAN_SHADOW_MASK) >= 7)) > + if (likely(IS_ALIGNED(addr, 8))) > return false; Wouldn't IS_ALIGNED(addr, KASAN_SHADOW_SCALE_SIZE) be more appropriate? But I'm not really sure what the original code is trying to do. if ((addr + 7) & 7) >= 7) can only evaluate true if ((addr + 7) & 7) equals 7, so the ">=" could be "==". I think. The code looks a bit weird. A code comment would help. And how come memory_is_poisoned_16() does IS_ALIGNED(addr, 8)? Should it be 16? -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org