From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A540EC11F65 for ; Wed, 30 Jun 2021 14:02:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DF936144C for ; Wed, 30 Jun 2021 14:02:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236531AbhF3OEz (ORCPT ); Wed, 30 Jun 2021 10:04:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236458AbhF3OEc (ORCPT ); Wed, 30 Jun 2021 10:04:32 -0400 Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 721D6C09B099 for ; Wed, 30 Jun 2021 06:53:24 -0700 (PDT) Received: by mail-wm1-x34a.google.com with SMTP id t82-20020a1cc3550000b02901ee1ed24f94so2859598wmf.9 for ; Wed, 30 Jun 2021 06:53:24 -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=+15b98OXWiOrEiKCGfnfeWun+23tJxDlHH/wqzYj+20=; b=WXi9U1Vip4zaz3uBNoqN8a2omyzEGIgwOHLP1ooDckRXK/3CMYy03EQAgTTOXhOVsW jmdHZZ/yF5Ox7Fm9TusoCFGZ0KQvVrQD8c0rnGTiyFQ5kYC/sOYOD8RhHBbipYvQbkua hbATd9xyZ/oofzWhQ8fJ7n2GYJpKXKgTNuIMJvXeJKLcEiWZqt4oH73eDwErt19gObFj ePK7x/B/Ih4lHpv4jC71OibbjGzGJnOtWFBhjgCiOsYOdkloQyCxlTiyVmI87HqAC84k 5hnGD95dAdkRHC2aMiJXl0S33hgVvZJ0D7hXugZAczLXqj4T1Pd3i6XgmT6Mspy8gKv5 hxBg== 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=+15b98OXWiOrEiKCGfnfeWun+23tJxDlHH/wqzYj+20=; b=smlsmFsYeLB856lQBBN/TLpvPVvlwEaQHjNvM9UbbhXcjruCBs+gg7Qx5opXEDfBb2 hnHY8jSZTIIb7NIWp4P9iXAzasL1Odxho93q6dAtUM5C4ta3wqFX2/VmP2E7l4VC1Mrz fBtHV24nUizia1LvcaIs44gELIN8uY6DW05SbLk/wd5dG2hKN7StqpIcm9XbBrN505qf g/R0sd0v+NAulBiuLyUN25DHYRNkfrlI6Jh9kTXPRtRG+BFJ2sT0bNFkvYaJWvFnZf8C wBjtRDqV7ff1p7vq39r9MZNyg8lirYqvTEq2TjMoX3eVxfxLNIBdmXElRZquX09N6gZg CQDQ== X-Gm-Message-State: AOAM530OKRoflSGkVVxvsH7anFK7d07nXxHnfNn6/49I/CELUi5Qq8lS JddWXdKoqrgF1WqRPzmnYTE4w13jg7Y= X-Google-Smtp-Source: ABdhPJwZS4PQ4Qo0dgN0XnUOHZBFG5LDZXGSPSb4r9wuy4xppmcnGhAYbCV0/Tahu7HBzZ78p13B8Ltwwjo= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:a3fc:e8:8089:1013]) (user=glider job=sendgmr) by 2002:a05:600c:3504:: with SMTP id h4mr4860507wmq.118.1625061203035; Wed, 30 Jun 2021 06:53:23 -0700 (PDT) Date: Wed, 30 Jun 2021 15:53:13 +0200 In-Reply-To: <20210630135313.1072577-1-glider@google.com> Message-Id: <20210630135313.1072577-2-glider@google.com> Mime-Version: 1.0 References: <20210630135313.1072577-1-glider@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v3 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 DNA) 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 --- 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 --- mm/kfence/core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/kfence/core.c b/mm/kfence/core.c index 33bb20d91bf6a..d51f77329fd3c 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -740,6 +740,14 @@ 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