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=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 10F13C11F6A for ; Wed, 30 Jun 2021 09:36:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8A48A61C9A for ; Wed, 30 Jun 2021 09:36:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A48A61C9A 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 9A8268D019A; Wed, 30 Jun 2021 05:36:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 958218D017A; Wed, 30 Jun 2021 05:36:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D1908D019A; Wed, 30 Jun 2021 05:36:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0185.hostedemail.com [216.40.44.185]) by kanga.kvack.org (Postfix) with ESMTP id 518058D017A for ; Wed, 30 Jun 2021 05:36:23 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 28C498249980 for ; Wed, 30 Jun 2021 09:36:23 +0000 (UTC) X-FDA: 78309884646.25.A53F6FB Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) by imf27.hostedemail.com (Postfix) with ESMTP id E0D777000081 for ; Wed, 30 Jun 2021 09:36:22 +0000 (UTC) Received: by mail-qk1-f173.google.com with SMTP id 65so1783783qko.5 for ; Wed, 30 Jun 2021 02:36:22 -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=GEgU3Qsu25wJx0lOWqm5ObxEM7r3CS36BBtaj2uR8gKOZfyUMgJ8GBahwZi7a6H1qp ZadvEvIodiRJB2e8fB7znhNTX9R0yvaysX7E3ycfLG027rlgZvxnzYCko5ucxDBr6EFy KLSNOVDytuZyaaTHicCww+JkBSm5wB0T5CSL5PkbIKhcFpR5ENTNP/PL493D2mOXMO65 +dMBC6drgvcawR6RMCgQ05XDcP2OLTbXJudPGg9sYTdBbuNGPmaFcBRyngrREB2jN2gj 17L7MUQByT8Lb/TzDu3g5iAqHGgjUZNpofHzJvWLqjxItcumGZlXujQytyE/xtvV52Id goCQ== X-Gm-Message-State: AOAM533k7jqMFy7hJkT7rlPoYa4zk3f6I/WL6dEdmhPR5MXZAVS+ZcI3 8WkLaqRkJq3zokg5X+C+XwMxVqqbx0vWgddhRhXZ/w== 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 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=kJvavOsD; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of glider@google.com designates 209.85.222.173 as permitted sender) smtp.mailfrom=glider@google.com X-Stat-Signature: im4uirjktt19pufwurou3c7ef83yy3we X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E0D777000081 X-HE-Tag: 1625045782-431063 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: 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