Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755950AbdDQPUu (ORCPT ); Mon, 17 Apr 2017 11:20:50 -0400 Received: from resqmta-ch2-11v.sys.comcast.net ([69.252.207.43]:52038 "EHLO resqmta-ch2-11v.sys.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755830AbdDQPUq (ORCPT ); Mon, 17 Apr 2017 11:20:46 -0400 Date: Mon, 17 Apr 2017 10:20:42 -0500 (CDT) From: Christoph Lameter X-X-Sender: cl@east.gentwo.org To: Sergey Senozhatsky cc: Minchan Kim , Joonsoo Kim , Andrew Morton , Michal Hocko , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@lge.com, Sergey Senozhatsky Subject: Re: copy_page() on a kmalloc-ed page with DEBUG_SLAB enabled (was "zram: do not use copy_page with non-page alinged address") In-Reply-To: <20170417014803.GC518@jagdpanzerIV.localdomain> Message-ID: References: <20170417014803.GC518@jagdpanzerIV.localdomain> Content-Type: text/plain; charset=US-ASCII X-CMAE-Envelope: MS4wfJlowCWxvqLk0cZgYDGUB6uXSZuf0xxTgAwnsDwp8l5znHiFW8OtLIgFpYu0cgFYBTTkhI7mCe3GHOroR+rcFMFTkjewoINhkNw98ICV8LheH2NoKQtD s3CW6vetxIuHqalpqtZWo87iWoq2uK5MF1t/x60p7L7e3gppN3cLJnUHlWiiM8CwQaV3KTl1I7iaptbe7EiyY5LJLCfHHNUrW63xA0ts49sBXda+UIChHoZr go+qatJfztbuuWVFIJxvX9xiWq0h3jqs0GbCY46gfS+yHjLGh0A6gJEeOboLpx6WUIEEvWd6sYxlKza+m/wq3GhslOHLioUyzjZPTwf57nqciwvpWRyXoutD RvtNl16KF4A7yjMZho/OsbfGeig3l6fp/lk7zx9IW6BLlU4iGXDurW5oAM7hua5mPAsl14C1AsQiT56H8Kt0S8laPMf7/FHCG4Sc9ym9rYkkacIvRvi4m0Ch HEokxIf8pRPM+miR Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1094 Lines: 23 On Mon, 17 Apr 2017, Sergey Senozhatsky wrote: > Minchan reported that doing copy_page() on a kmalloc(PAGE_SIZE) page > with DEBUG_SLAB enabled can cause a memory corruption (See below or > lkml.kernel.org/r/1492042622-12074-2-git-send-email-minchan@kernel.org ) Yes the alignment guarantees do not require alignment on a page boundary. The alignment for kmalloc allocations is controlled by KMALLOC_MIN_ALIGN. Usually this is either double word aligned or cache line aligned. > that's an interesting problem. arm64 copy_page(), for instance, wants src > and dst to be page aligned, which is reasonable, while generic copy_page(), > on the contrary, simply does memcpy(). there are, probably, other callpaths > that do copy_page() on kmalloc-ed pages and I'm wondering if there is some > sort of a generic fix to the problem. Simple solution is to not allocate pages via the slab allocator but use the page allocator for this. The page allocator provides proper alignment. There is a reason it is called the page allocator because if you want a page you use the proper allocator for it.