From patchwork Tue Jun 29 13:00:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12349835 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 C8B62C11F67 for ; Tue, 29 Jun 2021 13:00:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6D4D061DBF for ; Tue, 29 Jun 2021 13:00:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6D4D061DBF 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 C30456B0093; Tue, 29 Jun 2021 09:00:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE09C8D00F0; Tue, 29 Jun 2021 09:00:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A80EE6B009A; Tue, 29 Jun 2021 09:00:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0121.hostedemail.com [216.40.44.121]) by kanga.kvack.org (Postfix) with ESMTP id 869E46B0093 for ; Tue, 29 Jun 2021 09:00:56 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 75AB1204C8 for ; Tue, 29 Jun 2021 13:00:56 +0000 (UTC) X-FDA: 78306771312.20.46C91B7 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf08.hostedemail.com (Postfix) with ESMTP id 66B583000095 for ; Tue, 29 Jun 2021 13:00:54 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id u7-20020a5d46870000b029012786ba1bc9so901013wrq.21 for ; Tue, 29 Jun 2021 06:00:54 -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=0IVNVT0H+De0puoAJBu62LSXzyrEpBUiY4mqrAvY4dE=; b=UYCFZfkFY9abM3KQrsH/NI0o1Ot3LsTG0Alt/uBHrMwW9XZaYMXjL/HUH7hO2HbO1L qg+OSb4RiO6lq4aA7qZFKoAqp1IzHX9TE6Bvxhmqd9rNCAC3E/aU34t4JL8aCP47dv7J XwbVI45J1OeA/hV8SvQWgpt7sJbhUGdIakxdJAc9U6NJfyWxEkW8iCdhPyTQgQOOIM6t NEyNPy1WY9k0yHMmQsmkkrMM29+1XBNly+M+aiNIDBowcE5a6bM4JWmVIwg5aXrU3Puo xZQUGNoom0f4SkkU3f5IBLcyMOcYaMWzauTcJydg6GpuVXZHJ6H/GNO3GFIDh5lgdDrV lZOQ== 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=0IVNVT0H+De0puoAJBu62LSXzyrEpBUiY4mqrAvY4dE=; b=Yf1eGYcMgAxftD0gp4GWOwPiWw0ZUhpoF2mKqi6h1cM7nwwIeETCp9Hod1c1fiTElV djQV45ad3FdI3GGcFvD7LWZblpe0T1+J58R1cQVCUIAjU/5dpjKPQWjeQHa0L3pjOwVs k8TVDCWThn4Rc8ntjanBEIHnUanHRhAkWDXH02n+GVsBp8B750bC+uhwBja7gJJHoxgM UjUSksFOKvcyvMq+qra+LnlqeWHOqgeby1IlLMK/jwt6Lc7HkVvxfmTleXMa5dzQj4k6 I//tjgntXq4DD+xOO+72RiyRzNEMlRKNKzwYd402e7OctMpzH1lZIrVpJmMLAJa53OFS k0Og== X-Gm-Message-State: AOAM530W9P+BbeBlCFQVjxAFHV7a/4osaaQfoZ/qd+4mmvTGpPgiGnCx lheqNynTVf/+SBWPwXhKCVz3PnpqyoY= X-Google-Smtp-Source: ABdhPJwrWBFLqA2Zs7EwV8w8yjtDNp89/QNXlX2C+TXKPZ3ikeT7ZMi6/ITMVs5DekMzWQ5qNGvYPFziZo8= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:b4f8:c933:870a:c31d]) (user=glider job=sendgmr) by 2002:a7b:c0d4:: with SMTP id s20mr381932wmh.0.1624971652470; Tue, 29 Jun 2021 06:00:52 -0700 (PDT) Date: Tue, 29 Jun 2021 15:00:48 +0200 Message-Id: <20210629130048.820142-1-glider@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH] 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, Alexander Potapenko Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=UYCFZfkF; spf=pass (imf08.hostedemail.com: domain of 3hBnbYAYKCDETYVQReTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--glider.bounces.google.com designates 209.85.221.74 as permitted sender) smtp.mailfrom=3hBnbYAYKCDETYVQReTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: kx5ihch5ta4s16jqrtq8higej559osum X-Rspamd-Queue-Id: 66B583000095 X-Rspamd-Server: rspam06 X-HE-Tag: 1624971654-312879 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: stable@vger.kernel.org # 5.12+ Signed-off-by: Alexander Potapenko --- mm/kfence/core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/kfence/core.c b/mm/kfence/core.c index 4d21ac44d5d35..fd70089bd2808 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); }