From patchwork Mon Jan 21 09:56:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu CASTET X-Patchwork-Id: 2009811 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 9EDE23FDD2 for ; Mon, 21 Jan 2013 10:00:48 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TxE93-0000Dj-Vv; Mon, 21 Jan 2013 09:58:25 +0000 Received: from mail-bk0-f52.google.com ([209.85.214.52]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TxE8w-00009O-Dk for linux-arm-kernel@lists.infradead.org; Mon, 21 Jan 2013 09:58:23 +0000 Received: by mail-bk0-f52.google.com with SMTP id y7so147286bkt.25 for ; Mon, 21 Jan 2013 01:57:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer; bh=H3na9740MemmJDInkOGLQzkhvHx+T3falBISSmE+USE=; b=GuAV2rxKgoCBTVS+FEtBvjfcMNgUIJx1J46HCeHRjsxDwiK05xGApzbAh2NvgpzeuQ mHVMNXpAame6d2vV7rGcErfFdGgwd7fpZcT72FXZlhmeul2gqhQlVpoDBPPP2bkCgB9I /7nVvWqR0i3uxZiRKjWsKDjFQihL7LB/afmQtwMCTP5TKY9glxnLj8HaCh4VjHXdGQll P3lrkPJYVPcp88jJoTM6fGeyJdM5s3jHdGeAGvt15UuXbH3RduyppqFLHwwn3RsY2Kh2 /trNWwVj7yH2QEN2TuFPFBG12IY6DH7ZlBXNOFJv9a06BUzRa6EX/Id4zQFXD9XX25nl xRuw== X-Received: by 10.204.156.81 with SMTP id v17mr4585448bkw.18.1358762230882; Mon, 21 Jan 2013 01:57:10 -0800 (PST) Received: from perruche.Parrot.Biz ([46.218.109.82]) by mx.google.com with ESMTPS id f24sm7783757bkv.7.2013.01.21.01.57.08 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Jan 2013 01:57:09 -0800 (PST) From: Matthieu CASTET To: linux-kernel@vger.kernel.org Subject: [PATCH] slab : allow SLAB_RED_ZONE and SLAB_STORE_USER to work on arm Date: Mon, 21 Jan 2013 10:56:31 +0100 Message-Id: <1358762191-13839-1-git-send-email-matthieu.castet@parrot.com> X-Mailer: git-send-email 1.7.10.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130121_045818_585144_0A268878 X-CRM114-Status: GOOD ( 15.23 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (matthieu.castet[at]gmail.com) -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.214.52 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Matthieu CASTET , Pekka Enberg , rmk@arm.linux.org.uk, rientjes@google.com, akpm@linux-foundation.org, cl@linux.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The current slab code only allow to put redzone( and user store) info if "buffer alignment(ralign) <= __alignof__(unsigned long long)". This was done because we want to keep the buffer aligned for user even after adding redzone at the beginning of the buffer (the user store is stored after user buffer) [1] But instead of disabling this feature when "ralign > __alignof__(unsigned long long)", we can force the alignment by allocating ralign before user buffer. This is done by setting ralign in obj_offset when "ralign > __alignof__(unsigned long long)" and keeping the old behavior when "ralign <= __alignof__(unsigned long long)" (we set sizeof(unsigned long long)). The 5c5e3b33b7cb959a401f823707bee006caadd76e commit wasn't handling "ralign <= __alignof__(unsigned long long)", that's why it broked some configuration. This was tested on omap3 (ralign is 64 and __alignof__(unsigned long long) is 8) [1] /* * memory layout of objects: * 0 : objp * 0 .. cachep->obj_offset - BYTES_PER_WORD - 1: padding. This ensures that * the end of an object is aligned with the end of the real * allocation. Catches writes behind the end of the allocation. * cachep->obj_offset - BYTES_PER_WORD .. cachep->obj_offset - 1: * redzone word. * cachep->obj_offset: The real object. * cachep->buffer_size - 2* BYTES_PER_WORD: redzone word [BYTES_PER_WORD long] * cachep->buffer_size - 1* BYTES_PER_WORD: last caller address * [BYTES_PER_WORD long] */ Signed-off-by: Matthieu Castet CC: Russell King CC: Pekka Enberg --- mm/slab.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index e7667a3..d2380d9 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -2392,9 +2392,6 @@ __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags) if (ralign < cachep->align) { ralign = cachep->align; } - /* disable debug if necessary */ - if (ralign > __alignof__(unsigned long long)) - flags &= ~(SLAB_RED_ZONE | SLAB_STORE_USER); /* * 4) Store it. */ @@ -2414,8 +2411,9 @@ __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags) */ if (flags & SLAB_RED_ZONE) { /* add space for red zone words */ - cachep->obj_offset += sizeof(unsigned long long); - size += 2 * sizeof(unsigned long long); + int offset = max(ralign, sizeof(unsigned long long)); + cachep->obj_offset += offset; + size += offset + sizeof(unsigned long long); } if (flags & SLAB_STORE_USER) { /* user store requires one word storage behind the end of