From patchwork Tue Jun 29 16:17:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12350391 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, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham 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 B47D7C11F67 for ; Tue, 29 Jun 2021 16:17:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4B0DD61DC8 for ; Tue, 29 Jun 2021 16:17:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4B0DD61DC8 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8EB0C8D0156; Tue, 29 Jun 2021 12:17:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C1DD8D00F0; Tue, 29 Jun 2021 12:17:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 789FE8D0156; Tue, 29 Jun 2021 12:17:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0060.hostedemail.com [216.40.44.60]) by kanga.kvack.org (Postfix) with ESMTP id 4FF5E8D00F0 for ; Tue, 29 Jun 2021 12:17:47 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id CDF5322BFF for ; Tue, 29 Jun 2021 16:17:45 +0000 (UTC) X-FDA: 78307267290.10.C206428 Received: from mail-qv1-f73.google.com (mail-qv1-f73.google.com [209.85.219.73]) by imf13.hostedemail.com (Postfix) with ESMTP id CB96E100009A for ; Tue, 29 Jun 2021 16:17:44 +0000 (UTC) Received: by mail-qv1-f73.google.com with SMTP id ke6-20020a0562143006b029028b8546bb01so6975944qvb.20 for ; Tue, 29 Jun 2021 09:17:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=0F7hMZHCIK+7v4XQf0d2VY6BLy6L3ZoxZU11ibykN9g=; b=B7xyVqn1vrbzkQJ6kBNJL7fDADQ/1pWXqIy1hGlkPun62lYL9b3Y3oczyOZtu3/N3W O+gYGvyqL70jMCAOQhJ51MPhsqJduW0z0m4q9118ZzRPxUlZ+HmyzDjz9kkrqUkaoTxO jePjiVM6SizeP2G0SnOwLsTNKbNJGJSiX9uU2iqCaa6+q75SEJOBHcNiHJTzE7InP8d0 EiAISPOa6pv8LEhXJ6HnZmqbVVlO787ozJ1X2DVJp/8n7rfD1zmZvwNS+GsXj6bV81V3 4xua1fSjMGaN+Co8+70OXxk7WHtAX4+O+CgMEvQn8OwAOgjvkZFRy3Y/ThEwS+Dg/UFn wKwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=0F7hMZHCIK+7v4XQf0d2VY6BLy6L3ZoxZU11ibykN9g=; b=RNHjeAwkDW9dd0sknkTTQxzWLNrUmOQEvhjnqYkM1xF9LcNXhb4M9xxorG1ETYZYkB Vgx6S6LEL/XGKj9Lc7mArvsz3rJ+q/H4jwvKj/DO1jTYI2RLDQCChSUI9Rc/9Bvlh+LM FuxuWeQ861ILsIG9CyZH7iflJ5nWWt+jtFyhonkfA6ztSqHQYXhtdIHwlUutTyHj7RtM fSkN1vsD3A2+vNLJVaBVTnkia9fJcFy0lUkKHG9C82taJInFCNAlrKPw7Rk+l/h4z+HA NipNWQztu3vKDLZdV0WigqLqHZFkr59D1YiHZDRR9GXVypT2CsGmSSXsRnDhPgaYm34w BMvQ== X-Gm-Message-State: AOAM533Bc1bKldLFGgJSXjTRy5VNLiwECsZi0hfURJKOajUaTy9l9bVW 0WgYVJ4TdQRmnGoTHDctDHz6Yg1rBVM= X-Google-Smtp-Source: ABdhPJwuv+f1T/wt98yyV150j1MTUMjtZxdEp86M+9xIWeVtiNpwXJghmBwm5VThdjvcChZFgXs7V4K55zc= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:b4f8:c933:870a:c31d]) (user=glider job=sendgmr) by 2002:a05:6214:9c6:: with SMTP id dp6mr32184504qvb.30.1624983464121; Tue, 29 Jun 2021 09:17:44 -0700 (PDT) Date: Tue, 29 Jun 2021 18:17:38 +0200 Message-Id: <20210629161738.936790-1-glider@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v2] kfence: skip DMA 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, Alexander Potapenko Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=B7xyVqn1; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of 3qEfbYAYKCLEXcZUViXffXcV.TfdcZelo-ddbmRTb.fiX@flex--glider.bounces.google.com designates 209.85.219.73 as permitted sender) smtp.mailfrom=3qEfbYAYKCLEXcZUViXffXcV.TfdcZelo-ddbmRTb.fiX@flex--glider.bounces.google.com X-Rspamd-Server: rspam02 X-Stat-Signature: q3fgjz64d8f48t1kph1i7yfotr646qgh X-Rspamd-Queue-Id: CB96E100009A X-HE-Tag: 1624983464-356309 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: Allocation requests with __GFP_DMA/__GFP_DMA32 or SLAB_CACHE_DMA/SLAB_CACHE_DMA32 cannot be fulfilled by KFENCE, because they must reside in low memory, whereas KFENCE memory pool is located in high memory. Skip such allocations to avoid crashes where DMAable memory is expected. Fixes: 0ce20dd84089 ("mm: add Kernel Electric-Fence infrastructure") Cc: Andrew Morton Cc: Dmitry Vyukov Cc: Marco Elver Cc: Greg Kroah-Hartman 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 --- mm/kfence/core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/kfence/core.c b/mm/kfence/core.c index 4d21ac44d5d35..f7ce3d876bc9e 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -760,6 +760,14 @@ void *__kfence_alloc(struct kmem_cache *s, size_t size, gfp_t flags) if (size > PAGE_SIZE) return NULL; + /* + * Skip DMA allocations. These must reside in the low memory, which we + * cannot guarantee. + */ + if ((flags & (__GFP_DMA | __GFP_DMA32)) || + (s->flags & (SLAB_CACHE_DMA | SLAB_CACHE_DMA32))) + return NULL; + return kfence_guarded_alloc(s, size, flags); }