Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp350530pxv; Wed, 30 Jun 2021 07:06:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrvv1pDHIRH1YzPwf5GfY8pmjLJTP+hslP7ynad9qJD2J0eHrTA7uQ+OFnq1pmFVrqX1Ms X-Received: by 2002:a5e:930d:: with SMTP id k13mr7898426iom.61.1625061970235; Wed, 30 Jun 2021 07:06:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625061970; cv=none; d=google.com; s=arc-20160816; b=qhf640GnkgWpcuZV7kHgK3L53aiCyKVx3dRpbwFxpqQf5mgbTXGf9d2ZIm2/ql4eDR dprLZsBgo3ojY5SdAfXAd9qhs02+hbsltFYi2x09xUtm89jKx/ZilNxdjNCiTczWxMe7 4mBb32nAmN/f9ROPfPbfMhaNpSJlxujYHpyzxMdRl0ZU5go18LVjuWcihh5gVQX4FS1d g9gd33YtuazgCWEYsiCSdUn6z/iRYJri3siPDEBxtwRqvFOjFYn8CPPP/gv5BQSWBRWZ 2JioYteJJaIlvdletHxAd+BU0jEuV2I2GQy++7jvL1k1lxzXLU810ipPqqNLVGAE2Tcg I6cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=c0F//f0x+IlSuTVhD2o09FmJBTCLPD1WCy4S2G9ePpc=; b=PnAyeg+eLx+8JYXHgX/PDCLUILqpIuYCz69S9haigzjuKotLx9Vt39bhFGJtEe5VUt 2VYgpH7YvFGCN+3aNnjsCwLfoNh99RA85zf12v0jjfShnRrCoN5qAC9JG6TZvoJmvRCa LnD7yVLXhYiMw0pXbVFD0lwmxvxaqyp6PXMnqVRFzkF6sojcLMCABy+mXw64MXfmh7vg WuTEcmwv1YNlx0UOY869Un78Os/MBs4iZwUWcFcPRlRsRHPhPwQEDe5DStEqB8M7TTtm S8LlvpzbJb8TDP9uMoW+og7kmoYRyQdjf0AP/RUtpHf6hwn7fh+AV1V9PzVr/48xzUrI mHeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="a/z4bOFf"; 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 d18si16404759ioy.45.2021.06.30.07.05.56; Wed, 30 Jun 2021 07:06:10 -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="a/z4bOFf"; 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 S235803AbhF3OHV (ORCPT + 99 others); Wed, 30 Jun 2021 10:07:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235572AbhF3OGu (ORCPT ); Wed, 30 Jun 2021 10:06:50 -0400 Received: from mail-oo1-xc2c.google.com (mail-oo1-xc2c.google.com [IPv6:2607:f8b0:4864:20::c2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94728C06122E for ; Wed, 30 Jun 2021 07:03:09 -0700 (PDT) Received: by mail-oo1-xc2c.google.com with SMTP id g13-20020a4ac4cd0000b029024c717ed8aeso638398ooq.13 for ; Wed, 30 Jun 2021 07:03:09 -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=c0F//f0x+IlSuTVhD2o09FmJBTCLPD1WCy4S2G9ePpc=; b=a/z4bOFfSrZMHOKq5nfEiUadvfO9+JWMzXVisHQSDedJlx2RH1WWBTmLDfoP3mBcqk 9t5uMt+LafclLyJtVbIYofEIeLsPuQGK+gRNQKyq1jgdZesUWyYgfJUbr7j6j0gwqkGs 9LMkxjqjGFyiXtkz3b272td5PsqwfV+pwgfxudf2tQvTt2/J5+1MfWEHJfXQCJPIP7Xq AuWIshMO2OFbzJwXxyAVl9XrT8q5hc2ejH7LwaZpghqKIBEpexfL1nqL9gIz4cVHw+nN 4XaFnYBXIrDLHFwmghFwT5h3lf8ipJiRDNdEpcABg2X4WP1mH+6MObCP1xcExYBn33p4 59vg== 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=c0F//f0x+IlSuTVhD2o09FmJBTCLPD1WCy4S2G9ePpc=; b=hJj2r1hQLqJSe7mv+f00VWV9a2TOON8dEhLRN7UaKWivYFdnmJxw4og82Jrr5NkTle 7yeOEM9WrKOIxbhvJe5ApQOa2OzrAvUeHfDBds0+gfqXttl1/dWUviMRH/v1yyuXpSO0 tAoKvbebX3HGs4iekLCkclnuvsxjaYlSVNE0ZXdS/0Yx/7bWc7nzGjxSjgX3038Nq8+k dhQY4f2xckDjvByqZD0YgL/zi+OYkklBwyEsmszoiWK2DyKZFkzJRnw/tuS+0plogj7L 0bwqs3aTDc6z/nZ0sb7HFdWtMquIJ/QNZ5xs6NDApaOvKwMll7dDmYzW+jC34rYZ3ayK bCFQ== X-Gm-Message-State: AOAM533EDA1FJGMBVidRNIIA4eI26NP6pxxh9B+XUDO8duJua60G1yLt FxAXDhmGfr2l2C7ZihjSVZb1hOdRiptUtwZ5CE55iQ== X-Received: by 2002:a4a:6049:: with SMTP id t9mr8547439oof.14.1625061788645; Wed, 30 Jun 2021 07:03:08 -0700 (PDT) MIME-Version: 1.0 References: <20210630135313.1072577-1-glider@google.com> <20210630135313.1072577-2-glider@google.com> In-Reply-To: <20210630135313.1072577-2-glider@google.com> From: Marco Elver Date: Wed, 30 Jun 2021 16:02:53 +0200 Message-ID: Subject: Re: [PATCH v3 2/2] kfence: skip all GFP_ZONEMASK 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, jrdr.linux@gmail.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 30 Jun 2021 at 15:53, Alexander Potapenko wrote: > Allocation requests outside ZONE_NORMAL (MOVABLE, HIGHMEM or DNA) cannot s/DNA/DMA/ ... but probably no need to do v4 just for this (everyone knows we're not yet in the business of allocating DNA ;-)). > be fulfilled by KFENCE, because KFENCE memory pool is located in a > zone different from the requested one. > > Because callers of kmem_cache_alloc() may actually rely on the > allocation to reside in the requested zone (e.g. memory allocations done > with __GFP_DMA must be DMAable), skip all allocations done with > GFP_ZONEMASK and/or respective SLAB flags (SLAB_CACHE_DMA and > SLAB_CACHE_DMA32). > > Fixes: 0ce20dd84089 ("mm: add Kernel Electric-Fence infrastructure") > Cc: Andrew Morton > Cc: Dmitry Vyukov > Cc: Marco Elver > Cc: Greg Kroah-Hartman > Cc: Souptick Joarder > Cc: stable@vger.kernel.org # 5.12+ > Signed-off-by: Alexander Potapenko With the change below, you can add: Reviewed-by: Marco Elver > --- > > v2: > - added parentheses around the GFP clause, as requested by Marco > v3: > - ignore GFP_ZONEMASK, which also covers __GFP_HIGHMEM and __GFP_MOVABLE > - move the flag check at the beginning of the function, as requested by > Souptick Joarder > --- > mm/kfence/core.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/mm/kfence/core.c b/mm/kfence/core.c > index 33bb20d91bf6a..d51f77329fd3c 100644 > --- a/mm/kfence/core.c > +++ b/mm/kfence/core.c > @@ -740,6 +740,14 @@ void *__kfence_alloc(struct kmem_cache *s, size_t size, gfp_t flags) > if (size > PAGE_SIZE) > return NULL; > > + /* > + * Skip allocations from non-default zones, including DMA. We cannot guarantee that pages > + * in the KFENCE pool will have the requested properties (e.g. reside in DMAable memory). Comments should still be 80 cols, like the rest of the file. :-/ > + */ > + if ((flags & GFP_ZONEMASK) || > + (s->flags & (SLAB_CACHE_DMA | SLAB_CACHE_DMA32))) > + return NULL; > + > /* > * allocation_gate only needs to become non-zero, so it doesn't make > * sense to continue writing to it and pay the associated contention > -- > 2.32.0.93.g670b81a890-goog >