Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp163660pxv; Wed, 30 Jun 2021 02:37:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxG7iJYN2QYprNJkPeBU6+fr/f0GMIJyfGNLvAd+Pb11JeI+R2w9hQyTthOwQECO3FKV/Ly X-Received: by 2002:a6b:c989:: with SMTP id z131mr7363329iof.132.1625045851986; Wed, 30 Jun 2021 02:37:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625045851; cv=none; d=google.com; s=arc-20160816; b=WOd0ffvMsW7d8Dq5djk553pk7AHhacu2ADVpL/DqcCtwzdC2Mr9FOrVGi9qbWwmvwd zhw2tHb1psiSCnCWeTBNGrb/5PhQIZJroBMwODm297II/Er0fiaADRF+1zmsgNNQnONe fWVQn5iMdP1zYDl+g9lyrvrTK3PWWUhGTqW8/aVj0szsXLmTKOvJjwj3gYdvdpXppnv6 BYwKgWm+dG8/bD9RsjLfwwpL6VQLhxjD9OU3EvAVuMGSw9bD0lM/XyPXZYE5V9LBUxBy Gn4Z3rah9p5GzrknfO1HrH9R+9uH1mTbLkarIJDr8oV/x/W3OXuESbjg+Y9b0tos4N7l ActQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=YK/zuKzkHZUw7vkPacOqzwtQxHzQHK8toR9/3Xi8XcQ=; b=jbFY5sjA9FVSRggc5yk3dFS0HdEDdgddvSJdgPtLCdi+mRyFQNwtXFu99sCxvCCuRa cL+OHtop9WwwDtPJ3gYsMjlzU2S7fqlFv78no7yl9308UuQSm/D1N4FImb1Tr4oFx+eO tZlSmMw7CemNkgHKphek8YVkQ+RWNdTPRjwNHNgrs2bVCLNUGzoUTRjW58DNk1uNkKu7 QDZurcB7Jr5TuBuMR7qeQaxz3eB5RfYq2cfF/L2uF7WH2d2hK09jbyMP37CWqVgYclXb WFNTjODOx7kQiYsbgUb+/AqvQCoibewbSx9Gq/6y35MXTCAP9vZRE1oU032siAa2U5cW 6R0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kJvavOsD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m1si24114414iow.92.2021.06.30.02.37.20; Wed, 30 Jun 2021 02:37:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kJvavOsD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234044AbhF3Jiz (ORCPT + 99 others); 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-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