Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp3046026ybj; Mon, 23 Sep 2019 13:51:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqzfUqHokjKYzsDmOmE+n0SDyUBiLfkQSqTKXRqg8ZhwpWCtoZEKajxGIIa6aCnHyrgyyaqa X-Received: by 2002:a50:aa86:: with SMTP id q6mr2197313edc.288.1569271881475; Mon, 23 Sep 2019 13:51:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569271881; cv=none; d=google.com; s=arc-20160816; b=py2Tla0HVWl9NMUGAio5W9GxR+QYyvQsWGRg2fIONG0pSPXq/H0tlBPgfe67MmRYrk 7sU3sc/PlFY2+TKe4w42xhN6w6LnWmCuL7iyYPUSkB32pobseUo+Dwn2YlaG1GvtK7mm Jxru3MYFbRY87EKavGm7qoXPKzYq8Dr8qDPNUdPv1nwBzNgbrbrSPFUtaDfxn1TYu0O8 iguw0RYe+uDnjpxmMiANNeS2SROgSsuaCegblBEJiUkdn6o97S5sL7jMK38lenkS9C2I BAOp8FI0drS1TWFK1IFBIUHjynvRmS6SZog33gpLAPOX4ei6fsfpATh+BHlUbhJdDSoL XA6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :references:in-reply-to:date:cc:to:from:subject:message-id; bh=2yopHsWehasdsBCUmbgMpVwhdn4FvAy6KT6g+ar3iVg=; b=RBDtGSnthwp5lGmazphzOdxF/FdzO2vh4lcj49CEFKLpBirTcMZc8NOqgwe4VIHpJZ szxnkNd5ajOCtWtIiEpK5lpEH+QI2ujYuhtvAlU1ZvIbCsK8fSsd68RE5ZoGLyRO2YKJ VEqiuQjG7eJclCStExYomrjDwHrOpLfxxLifPtByNCdduDuNUY+JKLLI42iTpSUEyWiO GCuIzj3FQhI+YZBuOvN1r2XCaI94b9hebTHG/bq5mleXyYPiLRWVqvka6k54bkPtbfgH xg0CLHohMCO3c0ocORD01JWCqJlX0gtlS+72xkz7Z2oRKcIkWekqIv7NQ2IfvxJ3eC5Y XvDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s19si5498677ejd.277.2019.09.23.13.50.57; Mon, 23 Sep 2019 13:51:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387617AbfIVQGJ (ORCPT + 99 others); Sun, 22 Sep 2019 12:06:09 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:56934 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2387471AbfIVQGJ (ORCPT ); Sun, 22 Sep 2019 12:06:09 -0400 X-UUID: ac37638948e847a1bde229f1f10bc205-20190923 X-UUID: ac37638948e847a1bde229f1f10bc205-20190923 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1850422418; Mon, 23 Sep 2019 00:06:02 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 23 Sep 2019 00:05:56 +0800 Received: from [172.21.77.33] (172.21.77.33) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 23 Sep 2019 00:05:56 +0800 Message-ID: <1569168360.9436.17.camel@mtkswgap22> Subject: Re: [PATCH] mm: slub: print_hex_dump() with DUMP_PREFIX_OFFSET From: Miles Chen To: David Rientjes CC: Christoph Lameter , Pekka Enberg , Joonsoo Kim , Andrew Morton , , , , Date: Mon, 23 Sep 2019 00:06:00 +0800 In-Reply-To: References: <20190920104849.32504-1-miles.chen@mediatek.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 2019-09-21 at 02:08 -0700, David Rientjes wrote: > On Fri, 20 Sep 2019, Miles Chen wrote: > > > Since commit ad67b74d2469d9b8 ("printk: hash addresses printed with %p"), > > The use DUMP_PREFIX_OFFSET instead of DUMP_PREFIX_ADDRESS with > > print_hex_dump() can generate more useful messages. > > > > In the following example, it's easier get the offset of incorrect poison > > value with DUMP_PREFIX_OFFSET. > > > > Before: > > Object 00000000e817b73b: 00 00 00 00 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b > > Object 00000000816f4601: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b > > Object 00000000169d2bb8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b > > Object 00000000f4c38716: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b > > Object 00000000917e3491: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b > > Object 00000000c0e33738: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b > > Object 000000001755ddd1: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b > > > > After: > > Object 00000000: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b > > Object 00000010: 63 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b > > Object 00000020: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b > > Object 00000030: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b a5 > > > > I think it might be worth to convert all DUMP_PREFIX_ADDRESS to > > DUMP_PREFIX_OFFSET for the whole Linux kernel. > > > > I agree it looks nicer for poisoning, I'm not sure that every caller of > print_section() is the same, however. For example trace() seems better > off as DUMP_PREFIX_ADDRESS since it already specifies the address of the > object being allocated or freed and offset here wouldn't really be useful, > no? Thanks for the reply. I agree not all caller of print_section() is the same case. Converting all of them is not a good idea. For mm/slub.c, let me explain with the following example. The offset is useful for use-after-free debugging. I often trace the "free track" and find the data structure used and compare the data structure with the offset of the incorrect poison value and see if the incorrect poison value matches some member of that data structure. Assume we have a data structure "something" and it has a member called "m", offset = 780. struct something *p; // sizeof(struct something) is 1024 p = kmalloc(sizeof(struct something), GFP_KERNEL); kfree(p); (p->m) = 'c'; // assume p->member is at offset=780 When we see the log: (using DUMP_PREFIX_ADDRESS) We have to "count" the offset. INFO: Slab 0x(____ptrval____) objects=21 used=21 fp=0x(____ptrval____) flags=0x10200 INFO: Object 0x(____ptrval____) @offset=7808 fp=0x(____ptrval____) Redzone ____ptrval____: bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ Redzone ____ptrval____: bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ Redzone ____ptrval____: bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ Redzone ____ptrval____: bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ Redzone ____ptrval____: bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ Redzone ____ptrval____: bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ Redzone ____ptrval____: bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ Redzone ____ptrval____: bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk ... Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 63 6b 6b 6b kkkkkkkkkkkkckkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ____ptrval____: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk The log of using DUMP_PREFIX_OFFSET: We still have to "count", but it is easier. INFO: Slab 0x(____ptrval____) objects=21 used=21 fp=0x(____ptrval____) flags=0x10200 INFO: Object 0x(____ptrval____) @offset=7808 fp=0x(____ptrval____) Redzone 00000000: bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ Redzone 00000010: bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ Redzone 00000020: bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ Redzone 00000030: bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ Redzone 00000040: bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ Redzone 00000050: bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ Redzone 00000060: bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ Redzone 00000070: bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ Object 00000000: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 00000010: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 00000020: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 00000030: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 00000040: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 00000050: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 00000060: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk ... Object 00000270: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 00000280: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 00000290: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 000002a0: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 000002b0: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 000002c0: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 000002d0: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 000002e0: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 000002f0: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 00000300: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 63 6b 6b 6b kkkkkkkkkkkkckkk Object 00000310: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 00000320: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 00000330: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 00000340: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 00000350: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 00000360: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 00000370: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object 00000380: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk cheers, Miles