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, URIBL_BLOCKED,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 46368C11F69 for ; Wed, 30 Jun 2021 09:36:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E28E61C9A for ; Wed, 30 Jun 2021 09:36:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234015AbhF3Jiz (ORCPT ); Wed, 30 Jun 2021 05:38:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234012AbhF3Jiv (ORCPT ); Wed, 30 Jun 2021 05:38:51 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1760EC061756 for ; Wed, 30 Jun 2021 02:36:23 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id f6so1842638qka.0 for ; Wed, 30 Jun 2021 02:36:23 -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:content-transfer-encoding; bh=YK/zuKzkHZUw7vkPacOqzwtQxHzQHK8toR9/3Xi8XcQ=; b=kJvavOsDqqkeQ4CemydJCurCo7x4tLobkVSbycu14OfBqye/Ozw9xlx49rr5CJOSH6 JZIUIUFdX6ezz8Spq61dKM6mFjjGW1QS1hiEiLPTzcIyxXEQSSy2HVbIj/1eGYZiltIL pVADbItRVPPrhh1bvtmkk7hQasfP6kAlnl4x/bIzc/eFN59y+pP7tjzW1pBYPhfOalAA ITsDlapjObokgaeeScXtEBOUN8KD5Abgdc4MELB5pKq5HFo1PjoHI8BgCJmOjdeVWpza 3XxDx5PXx1uTR4yMabufi1P0ammR576k4rLrO2tfzw4ZPTEKGW4NGRZ3fVWpmqehIXPT /JFQ== 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:content-transfer-encoding; bh=YK/zuKzkHZUw7vkPacOqzwtQxHzQHK8toR9/3Xi8XcQ=; b=YcpW1bS93cq5eTN6A7gjauDnNnbI1HDA59RHSewh7K2Ch3KNEduVzgy6CEkI3B89aZ fBOFOb2OX/6Gqa7j8+/JSYeZ3qSvVoAO6BeJfFIaX1BtsSOi5UZlVv7NPkkSrbOkBTIW V7iRYSf+d7FhWoEp0JZdlF1vJ+9iSKCsfrero+19FxKvzYFM2ciNyb1q0z/gIiQ24UcQ ols8Tj62r+gg2Y/I7eWSYQauNcWW1PlX9h6Me39QXoXEmK3/Em9ZbQrHwuHD2pyzaGFY 9H5nTNt02JddduHzhgeaB6IQTaVTT7I/kH/sVa2utkUbklQ7oqySabANHRgF0mTEDZbm fx+A== X-Gm-Message-State: AOAM531MqdsURJbwzaMCKMmp4c5MhgX3bgB+qs+bZkriruW0FkI8CpV9 NeLi/bCthnZOZC5bcTV2hZM2ybwcyI6k8kkGkVAarA== X-Google-Smtp-Source: ABdhPJzsA7rgIHXJqCcVDE8TQTI1dTRKBA5JolE1telOysvTzOsVavirF7XwexYMuCEosJU8X47HQONDn+NdIkeUNp0= X-Received: by 2002:a05:620a:805:: with SMTP id s5mr25245254qks.326.1625045782023; Wed, 30 Jun 2021 02:36:22 -0700 (PDT) MIME-Version: 1.0 References: <20210629161738.936790-1-glider@google.com> In-Reply-To: From: Alexander Potapenko Date: Wed, 30 Jun 2021 11:35:45 +0200 Message-ID: Subject: Re: [PATCH v2] kfence: skip DMA allocations To: Souptick Joarder Cc: Andrew Morton , Dmitry Vyukov , Marco Elver , LKML , Linux-MM , stable@vger.kernel.org, Greg KH Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 30, 2021 at 9:02 AM Souptick Joarder wro= te: > > On Tue, Jun 29, 2021 at 9:47 PM Alexander Potapenko w= rote: > > > > 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 i= n > > 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 > > > > --- > > > > 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, w= hich we > > + * cannot guarantee. > > + */ > > + if ((flags & (__GFP_DMA | __GFP_DMA32)) || > > + (s->flags & (SLAB_CACHE_DMA | SLAB_CACHE_DMA32))) > > + return NULL; > > + > > I prefer to move this check at the top of the function. > Although it won't make much difference except avoiding atomic operations > in case this condition is true. Agreed, we probably shouldn't be expecting a constant flow of allocations from these zones that will be slowed down by this check. On a related note, Marco suggested moving the PAGE_SIZE check to the top of the function as well. It will also make sense to check for GFP_ZONEMASK instead of just GFP DMA f= lags. I couldn't see anyone passing e.g. __GFP_HIGHMEM or __GFP_MOVABLE to kmem_cache_alloc(), but according to mm/slab.c it is possible, so just to be on the safe side we'd better ignore them as well. > > return kfence_guarded_alloc(s, size, flags); > > } > > > > -- > > 2.32.0.93.g670b81a890-goog > > > > --=20 Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg