Received: by 10.192.165.148 with SMTP id m20csp190876imm; Fri, 20 Apr 2018 05:21:48 -0700 (PDT) X-Google-Smtp-Source: AIpwx4807oRHAcwqI2e2L8ZOXEN++MzkSwyuBBSyRklmsAcehnAZEzH03o4LidGDymuKSD4LQlZ5 X-Received: by 10.99.95.130 with SMTP id t124mr8507026pgb.150.1524226908864; Fri, 20 Apr 2018 05:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524226908; cv=none; d=google.com; s=arc-20160816; b=evSIsx7h2HJW8HrN4D9LpgUOqgToSA/4SrsE4Zez7g9cNgAXmYs+hIYLbbBjnJk3QH kh7+VeSiyvUviqpZ+phhnFgrQNLTEysPbiaoTL1ofsPUqYmzZjvLx0LCizuzncBC6rda 2J8h5s6x5K1EIxYSwXaIS+OgQDD+80nRxgbYieGEmLi+WL/z+iEbhMsydQJEKKwOtL08 y1qBNfal369r5T2taJuB5oI3Ldlzq/KsHUXxWN+RGirE2xEQ3XtnyDE457aZ/lo3YDqD EolcvDnrrFfC3p9NUWX6kqNFRvGfdZ9V7H1aAqw7cTYFDb6lLDpOmPhokP03lVs29OAH 3Kcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=54553U1BlLgpWyszW2ypr389v/AMLB5y1L7q9k8Afbw=; b=vGnr61abQyU74lVfgTJ8g+cNvjEZsKYTPjny6jI6x361UecSJnx53v+akM7QY52MbC ZYcAtnKuukAE3kD0cwB6+o+eY/qaELm+ZJ8e8mhrRO7RdoRedVrTqWKa7+xacCAB+j9D CONYdaN8DSveXzVQStzdz/i2w0Yf7ug4SyoMHW9aSL7yoOneepuBkDFWYlCtnRfLSE7e kB8M2Z9KsVvelEJGNtKgLIhx1DBBBLMkK3ncpqwOMZWxPMEF5P/dkhBbfRvHGaZnf0tj ZK9lHCX/vYmH9sIT6CQ5xDQhNh3nbCydDHcVgkWy4snA70Vk91auEZqBrWtklj584Ldp C7iA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j8si4902236pgt.582.2018.04.20.05.21.32; Fri, 20 Apr 2018 05:21:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754779AbeDTMU0 (ORCPT + 99 others); Fri, 20 Apr 2018 08:20:26 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:48848 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754705AbeDTMUY (ORCPT ); Fri, 20 Apr 2018 08:20:24 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4D8C7156FB6; Fri, 20 Apr 2018 12:20:24 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 35EF82166BAE; Fri, 20 Apr 2018 12:20:24 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id w3KCKOdT027651; Fri, 20 Apr 2018 08:20:24 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id w3KCKORK027646; Fri, 20 Apr 2018 08:20:24 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Fri, 20 Apr 2018 08:20:23 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Matthew Wilcox cc: David Miller , Andrew Morton , linux-mm@kvack.org, eric.dumazet@gmail.com, edumazet@google.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, mst@redhat.com, jasowang@redhat.com, virtualization@lists.linux-foundation.org, dm-devel@redhat.com, Vlastimil Babka Subject: Re: [PATCH] kvmalloc: always use vmalloc if CONFIG_DEBUG_VM In-Reply-To: <20180420114712.GB10788@bombadil.infradead.org> Message-ID: References: <3e65977e-53cd-bf09-bc4b-0ce40e9091fe@gmail.com> <20180418.134651.2225112489265654270.davem@davemloft.net> <20180420114712.GB10788@bombadil.infradead.org> User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 20 Apr 2018 12:20:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 20 Apr 2018 12:20:24 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mpatocka@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 20 Apr 2018, Matthew Wilcox wrote: > On Thu, Apr 19, 2018 at 12:12:38PM -0400, Mikulas Patocka wrote: > > Unfortunatelly, some kernel code has bugs - it uses kvmalloc and then > > uses DMA-API on the returned memory or frees it with kfree. Such bugs were > > found in the virtio-net driver, dm-integrity or RHEL7 powerpc-specific > > code. > > Maybe it's time to have the SG code handle vmalloced pages? This is > becoming more and more common with vmapped stacks (and some of our > workarounds are hideous -- allocate 4 bytes with kmalloc because we can't > DMA onto the stack any more?). We already have a few places which do > handle sgs of vmalloced addresses, such as the nx crypto driver: > > if (is_vmalloc_addr(start_addr)) > sg_addr = page_to_phys(vmalloc_to_page(start_addr)) > + offset_in_page(sg_addr); > else > sg_addr = __pa(sg_addr); > > and videobuf: > > pg = vmalloc_to_page(virt); > if (NULL == pg) > goto err; > BUG_ON(page_to_pfn(pg) >= (1 << (32 - PAGE_SHIFT))); > sg_set_page(&sglist[i], pg, PAGE_SIZE, 0); > > Yes, there's the potential that we have to produce two SG entries for a > virtually contiguous region if it crosses a page boundary, and our APIs > aren't set up right to make it happen. But this is something we should > consider fixing ... otherwise we'll end up with dozens of driver hacks. > The videobuf implementation was already copy-and-pasted into the saa7146 > driver, for example. What if the device requires physically contiguous area and the vmalloc area crosses a page? Will you use a bounce buffer? Where do you allocate the bounce buffer from? What if you run out of bounce buffers? Mikulkas