Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp399791pxv; Wed, 30 Jun 2021 08:07:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5bzj2M5Y/lZCZrJ0o1030lqXKGoC4cLuwd7lw3MKxkMdI+oGJrcsS1YCzm688ZxgZmM3l X-Received: by 2002:a17:906:15c2:: with SMTP id l2mr35794996ejd.348.1625065627114; Wed, 30 Jun 2021 08:07:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625065627; cv=none; d=google.com; s=arc-20160816; b=PIEDYqvqG8KUFOaHHGhuo879iSSsNjN1+Rt4rNX0Kjqu/A0d9dL2H4SaZoN3PUodir jehan4G8ju5yN/TKv9ysEdPZzmpb269cJa9bcs6Z8agxs0A7elPfh+/5yoAh91si3iqy cUFIwm6X3dCiujSCy6p0jmfD4adDWTRjqPZYkJL2T5ex2/JB4kuw9B4/YAR1+uACjcfW cY1wxo9tNq0gVle/bUCMKGG9ue3L83EEUmPjW4dkzSCaku2fS66fMKIDeqdAl1dFLTfP 5mE8FXlJMpapdtE8RmsDBrYPbJHTtFUgczj+TT7B1LxUhOnuo2L7xPb1zRprpGskUF3/ qgWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=NsJPxv+Yi9Y0Cxl+/SZ8/0DfgNfKjUrGLSr4GOlizVE=; b=0apMhJslp6V6CYI/yqzGGh/ZAh71AnwC/gB8oTDTfNjhIk4uJcnp6P8+xc2zpBcN3l vnaTW6eeSEppAxljfOVk6STLx32wAEgxBR41QlMrM6Ef2l5b1z1f0Ps1TyzdVZXjeWYq c7y6sNwYj643iTFyiRyOdpEJpfb/FA2xFJ7nXWvNvEj0hf0ngIXlxRZhBNSBg9qccnXU cIxS1Gf6WjV0qTLw8uRGCk1B6nT2NMYqy2b+n6RHVfMv+qzA1foNWlwHvGaugI8Ud3gh Pt17guALO3UYegM3yWrnn+F9/ArkUrsjwHKDBbkCJx6aNRAMc+NM9ntqybmnPQmD7qlc 8yfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZSFYc1N7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ba11si20155625edb.131.2021.06.30.08.06.43; Wed, 30 Jun 2021 08:07:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZSFYc1N7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235819AbhF3PFN (ORCPT + 99 others); Wed, 30 Jun 2021 11:05:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235817AbhF3PFL (ORCPT ); Wed, 30 Jun 2021 11:05:11 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41152C061756 for ; Wed, 30 Jun 2021 08:02:41 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id eb2-20020ad44e420000b029025a58adfc6bso1582768qvb.9 for ; Wed, 30 Jun 2021 08:02:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=NsJPxv+Yi9Y0Cxl+/SZ8/0DfgNfKjUrGLSr4GOlizVE=; b=ZSFYc1N7Bh9wv2errbcoilHdQgrtZa4Egl/x1q8DWx087ZrALCwjG7d45PprJ7nOV+ 8ybg4z8OgnOrqDzpnDFp+d256wUotxawgE/vD2sBzRB+i9B08DGeCdhjXrw3GFVws+AS syJ+SBqSs9SGklX7ualr3e0kyhIbqSZqAXs5MsS0ReBBnE3YswrsTgZ4xk6ur3Q3qwkh mlkpUkSm1Y3v1Fgz/jYzX7caVUQz7AWqahH08YA04wZxzv4uDmF8A7Zo8QN3KPPw2DYy wtL6FSIyBrpaFv5c37rI/H2FcsggCqbNJLo/kQWTBPugSIKS0T8xVMd4H67528gI2oDi 6H2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=NsJPxv+Yi9Y0Cxl+/SZ8/0DfgNfKjUrGLSr4GOlizVE=; b=swduT26uVAXMG5H9wJOnSskRuYNJ2MLZ40er+XCqANRjrWGqZTAlx0vDzQ0CQCsomZ J4YFdBLQ/nl7b9pyiyk6ndfihgzo8DtmNdovRgUxwp7WEKBylEfg710opLfpaK8nbTo3 y0W5axNlbQxoh2UQYC+XIaJ2AWRENBkqU18q6RPM9gm+W5HyIqEsuYCBno8tzS0Df/zv RbObG19dtTHOV/F+DR5JRnLwHMBiYKhMt39qctKCU0kgBMn0KseHYICUBMRoZprJ5SNb /5a/sn+iAlL141KwoCe9Udw8Q8reo+FbkzqIQoETsZHHQ8U8xQuaDxhlkfqfGkq9J1XB iLHQ== X-Gm-Message-State: AOAM530O2Ogrud+LCy68bwB53cQzEtEsIgodqL+t4MG9aGH70Weuo3Ph J0Z1iUuagezbkTpY7kmi+ooNoN/7NNo= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:a3fc:e8:8089:1013]) (user=glider job=sendgmr) by 2002:a05:6214:966:: with SMTP id do6mr37584817qvb.57.1625065360398; Wed, 30 Jun 2021 08:02:40 -0700 (PDT) Date: Wed, 30 Jun 2021 17:02:34 +0200 In-Reply-To: <20210630150234.1109496-1-glider@google.com> Message-Id: <20210630150234.1109496-2-glider@google.com> Mime-Version: 1.0 References: <20210630150234.1109496-1-glider@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v4 2/2] kfence: skip all GFP_ZONEMASK allocations From: Alexander Potapenko To: akpm@linux-foundation.org Cc: dvyukov@google.com, elver@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org, gregkh@linuxfoundation.org, jrdr.linux@gmail.com, Alexander Potapenko Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allocation requests outside ZONE_NORMAL (MOVABLE, HIGHMEM or DMA) cannot be fulfilled by KFENCE, because KFENCE memory pool is located in a zone different from the requested one. Because callers of kmem_cache_alloc() may actually rely on the allocation to reside in the requested zone (e.g. memory allocations done with __GFP_DMA must be DMAable), skip all allocations done with GFP_ZONEMASK and/or respective SLAB flags (SLAB_CACHE_DMA and SLAB_CACHE_DMA32). Fixes: 0ce20dd84089 ("mm: add Kernel Electric-Fence infrastructure") Cc: Andrew Morton Cc: Dmitry Vyukov Cc: Marco Elver Cc: Greg Kroah-Hartman Cc: Souptick Joarder Cc: stable@vger.kernel.org # 5.12+ Signed-off-by: Alexander Potapenko Reviewed-by: Marco Elver --- v2: - added parentheses around the GFP clause, as requested by Marco v3: - ignore GFP_ZONEMASK, which also covers __GFP_HIGHMEM and __GFP_MOVABLE - move the flag check at the beginning of the function, as requested by Souptick Joarder v4: - minor fixes to description and comment formatting --- mm/kfence/core.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/kfence/core.c b/mm/kfence/core.c index 33bb20d91bf6a..1cbdb62e6d0fb 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -740,6 +740,15 @@ void *__kfence_alloc(struct kmem_cache *s, size_t size, gfp_t flags) if (size > PAGE_SIZE) return NULL; + /* + * Skip allocations from non-default zones, including DMA. We cannot + * guarantee that pages in the KFENCE pool will have the requested + * properties (e.g. reside in DMAable memory). + */ + if ((flags & GFP_ZONEMASK) || + (s->flags & (SLAB_CACHE_DMA | SLAB_CACHE_DMA32))) + return NULL; + /* * allocation_gate only needs to become non-zero, so it doesn't make * sense to continue writing to it and pay the associated contention -- 2.32.0.93.g670b81a890-goog