Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3461194pxk; Mon, 5 Oct 2020 10:11:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaqMt/wsUvCHDT3nkjfN9cGjQa/f3kZHMpYEp0fx+wVpjcbT7qw6pI1kO07NH422me2OgB X-Received: by 2002:a17:906:a59:: with SMTP id x25mr675005ejf.489.1601917914341; Mon, 05 Oct 2020 10:11:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601917914; cv=none; d=google.com; s=arc-20160816; b=HZnyFKpIgGxT3+JVXkbO8YOEPg4hGeen0CcOzrNJ0AteYDSsYB1lsxoyYdd5yAzLes WgjQcXVCjRS9xW+/K5ZBG8r4DF3aiJe4npRkFQS+TE903tj934dKkFwlqFlsNPYdps2R rDFhUchIEH+TK3WSR8B1ln54Eb7hPQ5CYZ9JsXbLGpv2Oyv911ymaG0LgUbek9/Bsbjv AB/AaDM5xjuSkSJ0ApTVdE0KMsq8Em9kPoAB9ptVnNGW1YmYMNeQTM0KtamGdez2uZFh 6yqkaxG9PAjqQwMgYI0yt9YCh3L/vt+yicivZWm/ZOFXxHtKiC+BE7aOnW9Q0QjPgUNu l9KA== 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=e75sgfE0gBHuZ+sQh5xSznZKqRTfepXZ5BM13ORNfbc=; b=DCF6dLn6orLNgcbpZJzf9C3f1wDptkhOXCy++yoDTabHB7PIHsZpXc9xJtCTRgMuAJ inrXdvA31Xtwj2AgRIsKm99Cwcbzvw1cElFpsEjbyTiwvWmbJ3VnHC6zzb8+S5iQN/XV Rjx9s1fsCypm550MDinnjdLrSiBQCClgWGASKp7cha42gLzw4CaENnI141rVa+yrpZsW VvIR6ghahQK0sCnCb59nq2+1HFbpn6gB45z6UOxURPQh5xmXbrzCNxqOBAk1GEuYOIKW Em5gDuFlhHNpQtYBxzoRnaCYC3AiWpnNtilI0RYK1E9k85jK+0VsICK11p66nWv9NawI B+8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YVj4GC3J; 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 x99si343300ede.160.2020.10.05.10.11.13; Mon, 05 Oct 2020 10:11:54 -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=YVj4GC3J; 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 S1728037AbgJEQtw (ORCPT + 99 others); Mon, 5 Oct 2020 12:49:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727101AbgJEQtv (ORCPT ); Mon, 5 Oct 2020 12:49:51 -0400 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30F7FC0613A7 for ; Mon, 5 Oct 2020 09:49:51 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id 33so10117311edq.13 for ; Mon, 05 Oct 2020 09:49:51 -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=e75sgfE0gBHuZ+sQh5xSznZKqRTfepXZ5BM13ORNfbc=; b=YVj4GC3JL8go1+BQzjpqRqC+/HErXCrcVSbeTGXkmGNDW0inx8fYasntI3xi6q8VOM hJVNYfqKZPCzxROaMECiKmwLcdalUc1GdONuilK01tVtKa891PSDahBolGt9vJKkkSOL B0hyh8ssSuuwmiS2dIotXfe6KCbVlfk7jvA1blxGgHgJbdflFwobWNcvSrGx058Q/beR KU4kN/C5m3lc95eHwZLfKb3lf2wCsj5934cQIzfTnG9+JSUg0kYxuitggcx40qWKFVgI 77FMQRT8Q4W2BepuQvyuFCNaAX2Na1W5CNqAiuR2rDWjdrpuNHqtkwhLe9xKwKVBWEBG M3gA== 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=e75sgfE0gBHuZ+sQh5xSznZKqRTfepXZ5BM13ORNfbc=; b=f/5b8wIosChX0rJ6WD8jmevG4v61vV1XzZMZ9c8pcGuZGLEhKXxr8s3YetdSBPBQq5 jE9qDPCbQwbERZ284XqX9VnROV6GB4CEEazbL3Cbxtw8esMPFv3RnaNqIDSKpVglToij hz4q1CQMUrKFEYaJP0kK96j3EP4NXbAjFpu60dBMuYJkkvZz+NgF9bd5YtRdFiwX3UCz XJaNfbjLYaH7Xl7V2IOrQG0w1lx1a3AHoILkevOZ9QAwmN8mY9EBDMg714xnnD1wcwbP wr6gCeQdKP7Mb4rsjFuizI5WZRxbPcLEusYd1EUBsVy7+lIANS05TX6g7hBQ5uuT79y3 T1fA== X-Gm-Message-State: AOAM530UxRPqBx9Eg+RB087MCBe81XTflpmSYVat+WFCEzMQn0EIE2PP 6I+kwIYfkGKqqOl/cYh4jlRmAV+yQpJ2OusC7cf9Zg== X-Received: by 2002:a50:ccd2:: with SMTP id b18mr555817edj.51.1601916589473; Mon, 05 Oct 2020 09:49:49 -0700 (PDT) MIME-Version: 1.0 References: <20200921132611.1700350-1-elver@google.com> <20200921132611.1700350-2-elver@google.com> <20200929142411.GC53442@C02TD0UTHF1T.local> <20200929150549.GE53442@C02TD0UTHF1T.local> In-Reply-To: From: Jann Horn Date: Mon, 5 Oct 2020 18:49:23 +0200 Message-ID: Subject: Re: [PATCH v3 01/10] mm: add Kernel Electric-Fence infrastructure To: Alexander Potapenko Cc: Mark Rutland , Marco Elver , Andrew Morton , "H. Peter Anvin" , "Paul E. McKenney" , Andrey Konovalov , Andrey Ryabinin , Andy Lutomirski , Borislav Petkov , Catalin Marinas , Christoph Lameter , Dave Hansen , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Hillf Danton , Ingo Molnar , Jonathan Cameron , Jonathan Corbet , Joonsoo Kim , Kees Cook , Pekka Enberg , Peter Zijlstra , SeongJae Park , Thomas Gleixner , Vlastimil Babka , Will Deacon , "the arch/x86 maintainers" , "open list:DOCUMENTATION" , LKML , kasan-dev , Linux ARM , Linux Memory Management List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 5, 2020 at 6:01 PM Alexander Potapenko wrote: > > On Tue, Sep 29, 2020 at 5:06 PM Mark Rutland wrote: > > > > On Tue, Sep 29, 2020 at 04:51:29PM +0200, Marco Elver wrote: > > > On Tue, 29 Sep 2020 at 16:24, Mark Rutland wrote: > > > [...] > > > > > > > > From other sub-threads it sounds like these addresses are not part of > > > > the linear/direct map. Having kmalloc return addresses outside of the > > > > linear map is going to break anything that relies on virt<->phys > > > > conversions, and is liable to make DMA corrupt memory. There were > > > > problems of that sort with VMAP_STACK, and this is why kvmalloc() is > > > > separate from kmalloc(). > > > > > > > > Have you tested with CONFIG_DEBUG_VIRTUAL? I'd expect that to scream. > > > > > > > > I strongly suspect this isn't going to be safe unless you always use an > > > > in-place carevout from the linear map (which could be the linear alias > > > > of a static carevout). > > > > > > That's an excellent point, thank you! Indeed, on arm64, a version with > > > naive static-pool screams with CONFIG_DEBUG_VIRTUAL. > > > > > > We'll try to put together an arm64 version using a carveout as you suggest. > > > > Great, thanks! > > > > Just to be clear, the concerns for DMA and virt<->phys conversions also > > apply to x86 (the x86 virt<->phys conversion behaviour is more forgiving > > in the common case, but still has cases that can go wrong). > > To clarify, shouldn't kmalloc/kmem_cache allocations used with DMA be > allocated with explicit GFP_DMA? > If so, how practical would it be to just skip such allocations in > KFENCE allocator? AFAIK GFP_DMA doesn't really mean "I will use this allocation for DMA"; it means "I will use this allocation for DMA using some ancient hardware (e.g. stuff on the ISA bus?) that only supports 16-bit physical addresses (or maybe different limits on other architectures)". There's also GFP_DMA32, which means the same thing, except with 32-bit physical addresses. You can see in e.g. __dma_direct_alloc_pages() that the GFP_DMA32 and GFP_DMA flags are only used if the hardware can't address the full physical address space supported by the CPU.