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=-23.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_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 9578BC11F69 for ; Tue, 29 Jun 2021 16:41:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E0C461DD7 for ; Tue, 29 Jun 2021 16:41:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233888AbhF2Qng (ORCPT ); Tue, 29 Jun 2021 12:43:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232174AbhF2Qn0 (ORCPT ); Tue, 29 Jun 2021 12:43:26 -0400 Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03B6FC061760 for ; Tue, 29 Jun 2021 09:40:48 -0700 (PDT) Received: by mail-oo1-xc35.google.com with SMTP id s10-20020a4aeaca0000b029024c2acf6eecso4592516ooh.9 for ; Tue, 29 Jun 2021 09:40:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uELLVvexdDVZ7QoY/jcBV+gQtVgk5q8UpdZvDzEAtEY=; b=qVLx61deuLJ7bywIsa+tF05uKf/2+b8CeHj0rPEfLWxdLgu89IBSDgt3YkH7vGacMz nyCK9I57XTPgV0vRTioFcpOSilac9+BbCi5wsbe4bm8lYLVU/Sc8/8wSXbRu5cPQdjaC 0vofil/WaPZIPbw6olol4kTB0ZI80Uj436XmmLqwyVcChB9dZIzyJZ296Jj9FUZutGU4 rcNQztRL5FCRQQMVAlPidpfneYrvhUK6sgePq7j2h8OpKgt5Hy6JAqKkB+rZdyOnibu1 kFXJejSoHzMus5qDag0ZkQRBL0bB2BL75ikXCj6nydZtygxeVb3/XsogU093pfqmozl8 Y+DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uELLVvexdDVZ7QoY/jcBV+gQtVgk5q8UpdZvDzEAtEY=; b=hhwQ/0clhp/gFbOpz/QhwvmAkvVbQwdsXvzCVKIWhfORqoHkwX1gyPbqSIZJhfdZ+C u72UlmRKkofHdWzeGOF5MehFRT7GLhF7CFrDrZ956JYil7prJdxVbHwMZqdYYGQzirhQ qMDAU7vcQ5xVqVNom1auO1vBeFojiNKNwWsRav67GbFD6A7lKIPd5HRvp8JnJxOvwBDf tQunTX7OPOM7nblw4LrbURwsodxv6F+kKK/I8IliDqoOS0Kj+t4witD5gk1rjhc3HHph TAo9mfRo/ZlQYeIo8Pz9CT2ltgZSDL2X1YgSX69/doGryCuDkqKYML4T7AWIEzNvX/5D hbYQ== X-Gm-Message-State: AOAM532ZjdOgQSx3i44swtobLA61gXD2QA5IGsrcMrNzYDp5lzJ/EYMR OVQrH6PbauJwIW3JNFEI3mhip8ZjiuqrVqsk3J1Bww== X-Google-Smtp-Source: ABdhPJyfUcuxxTGNuv67eCqzzb2eh7tthiLbron1HVfPakPvQeEyKynR8racWmed8vyHpxzlYhl5tHUQC2/fv76TRms= X-Received: by 2002:a4a:9406:: with SMTP id h6mr4789265ooi.36.1624984847148; Tue, 29 Jun 2021 09:40:47 -0700 (PDT) MIME-Version: 1.0 References: <20210629161738.936790-1-glider@google.com> In-Reply-To: <20210629161738.936790-1-glider@google.com> From: Marco Elver Date: Tue, 29 Jun 2021 18:40:34 +0200 Message-ID: Subject: Re: [PATCH v2] kfence: skip DMA allocations To: Alexander Potapenko Cc: akpm@linux-foundation.org, dvyukov@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org, gregkh@linuxfoundation.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 29 Jun 2021 at 18:17, Alexander Potapenko wrote: > 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 Thanks! > --- > > 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); > } > > -- > 2.32.0.93.g670b81a890-goog >