From patchwork Thu Aug 9 08:52:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 10561091 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1293713BB for ; Thu, 9 Aug 2018 08:53:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4D682AA2B for ; Thu, 9 Aug 2018 08:53:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6DB22A9FE; Thu, 9 Aug 2018 08:53:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 222C42A9FE for ; Thu, 9 Aug 2018 08:53:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 08A4C6B0005; Thu, 9 Aug 2018 04:53:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 03D5B6B0006; Thu, 9 Aug 2018 04:53:25 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6D126B0007; Thu, 9 Aug 2018 04:53:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 828EB6B0005 for ; Thu, 9 Aug 2018 04:53:25 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id z5-v6so1866509edr.19 for ; Thu, 09 Aug 2018 01:53:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=Ei0lvBklNeBcA3iJSo6cLynyFI8rfGmKmdXph+EMm8s=; b=HYO2syTsN2ubAGbQeP9B6pK4J9IjKkV/yItnVFp4Ksuro/OkJxrnQGYtKEJ9+1qE+w 8G+WBhfFwghWXZ8wvs8pdhowxqHcr8vDB+3uaIZGqPZwrYeI7RTS9Xl4sECaQQP818wr 6tXGaFtJKfkQKR9sVzY4x0zjNyZy8LXy8zKZLebrA1SKXHiZgmxMGMVPF9EhO6jYT2Dv dHpoSPmzrJD+SYh32zBxq7P9WLu1IKNrfKvk58KwAkevSoMyZa5P8QyMQHj0jrHLF3yj YwGQPZgz5H1KI4YLJJzA6D6rDQRKO2iDxJiwIscIDu4fCoPtjRk1sRvQUPS6VKvc0E3F lBpA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Gm-Message-State: AOUpUlEA/gPNnaLO54T1sQ79hQDYDd/9K4bi4fnYPL05zne0+1X4DUGE qfq5QZ+x8+uqt5/dZHiPFpLd11DjNAo5kV4FLFn5rPKZcBY+Xejh1AYqjwO10eFZLtBIXnoOYur U1+J91Fln3cF7ID6mBqnw09i06qT/aqSNoHWeqf7H8tyJy1O+RvUjV7Vygj8S4lSJzw== X-Received: by 2002:a50:8978:: with SMTP id f53-v6mr2076098edf.166.1533804804943; Thu, 09 Aug 2018 01:53:24 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwPnS0nJOYkbmSLuxfqMk9yJpjhpWql4oIo/9FUc20fj7e8yZtSVbUkMEjTGgWIi263nnQs X-Received: by 2002:a50:8978:: with SMTP id f53-v6mr2076041edf.166.1533804804004; Thu, 09 Aug 2018 01:53:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533804803; cv=none; d=google.com; s=arc-20160816; b=oYLOiuln2+0jM10xT0nUDy5sqCdeYiWSBXiK/cwEyar+5T0KnhR8peS/vBPuBBHjB1 mCtPsO8+0seJecGJf2ZMut5GwaKdHqd97mVr8pr7Axe8EtOScl70Hfz/vbPi6sDIt/Hm hHBrXcvvLe44bahXcUVzIVZ0BO05BgG2/KrgHswDePua4oyUWT69gkWIkvwnO8JLH1eX kDPwgVb6Qa5qJ+rfJDyuuiBYCoK/4qLdZLAiPp9A/KBX4RrW7szEgFP6I3x8+nPJ37Jj x8E1/w+9gJlcv530GFsEvqkZ+sL6iwGqSUMrsTR0ddJPtncxebjQaFwEpchfliQs0wVg LaDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Ei0lvBklNeBcA3iJSo6cLynyFI8rfGmKmdXph+EMm8s=; b=RkZsdE8Bd4Jw5CaVKaKrhKOyQRfBwmbsPK3DGuiJcfUlAXSR4cYPTn3ExjeiRQeK/S OZDWkQqMWGDy0gzEevfYY2Dkcnha9G6RTSaZ3J0nAHnl84qOfYe+57TRMLdwrIjTD9QU Gttyt7x8jySDmEtogh1A3U+b2moPpDbbsrkeexz3MqEfWytq1yP0RwtiBNrw18ZOJVTq Xrl+adEUji0WW1otIml977iTKtpFAI0iGUZLgcPgL7Ty3dchV+qrMXUWlN5dLe3gzsOn VmqDG0nLMzdCUPs4NzGom5jAWwcjHDsYfX8FZFr4PVl+q3BhaOZH+iIDqr1SqIKFZvyV 5wpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id n38-v6si7379828edn.443.2018.08.09.01.53.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 01:53:23 -0700 (PDT) Received-SPF: pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1AE7CAEBD; Thu, 9 Aug 2018 08:53:23 +0000 (UTC) From: Vlastimil Babka To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Paul Menzel , Alex Deucher , Vlastimil Babka , Kees Cook , Daniel Micay , Eric Dumazet , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim Subject: [PATCH] mm, slub: restore the original intention of prefetch_freepointer() Date: Thu, 9 Aug 2018 10:52:45 +0200 Message-Id: <20180809085245.22448-1-vbabka@suse.cz> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP In SLUB, prefetch_freepointer() is used when allocating an object from cache's freelist, to make sure the next object in the list is cache-hot, since it's probable it will be allocated soon. Commit 2482ddec670f ("mm: add SLUB free list pointer obfuscation") has unintentionally changed the prefetch in a way where the prefetch is turned to a real fetch, and only the next->next pointer is prefetched. In case there is not a stream of allocations that would benefit from prefetching, the extra real fetch might add a useless cache miss to the allocation. Restore the previous behavior. Signed-off-by: Vlastimil Babka Cc: Kees Cook Cc: Daniel Micay Cc: Eric Dumazet Cc: Christoph Lameter Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Acked-by: Kees Cook --- While I don't expect this to be causing the bug at hand, it's worth fixing. For the bug it might mean that the page fault moves elsewhere. mm/slub.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 51258eff4178..ce2b9e5cea77 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -271,8 +271,7 @@ static inline void *get_freepointer(struct kmem_cache *s, void *object) static void prefetch_freepointer(const struct kmem_cache *s, void *object) { - if (object) - prefetch(freelist_dereference(s, object + s->offset)); + prefetch(object + s->offset); } static inline void *get_freepointer_safe(struct kmem_cache *s, void *object)