Received: by 2002:a17:90a:b81:0:0:0:0 with SMTP id 1csp988994pjr; Fri, 30 Aug 2019 10:52:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzyVyGOIg4oBbZehId/189tzBYiO9UreUgNUBrz+bRXkUdNh7ZGccxUzMi0zoG8g4Pc3VvM X-Received: by 2002:a17:902:778e:: with SMTP id o14mr803180pll.167.1567187529484; Fri, 30 Aug 2019 10:52:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567187529; cv=none; d=google.com; s=arc-20160816; b=Si1s4iVIKar3M9QwhZwbNeph8/kP+nTh4YijgHIpU9Ki3wkrnUnBKaLG/CX7+Xfo0x Aw6OqN/YoUbERfH/FHE9CysMgcMO0sK1v0WHBJ6H0aVXn84nkZad/0WTvYMMZDBxQz/a tB0Qiwr1nZwuB4npLR/W1qgYxYBrPBN5CTlMbJ0Nyi0rzg8azhE8Ks0htsGQ50sTzNT8 jSsyQndLRAVKMRGGXXVW+xmc6CqEijhExQQJeShX+xnRohJaNthJwKHWbiQrMD2uw/90 DMIxgjKhP0G0q+WjudG7DdSULMSZ+hThMSg+HdVIWo753My4jBLxGAReHeleHvFyxSxb +urA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=a9y5rfT6nLtA1XdTe+7F8mFNtN6YI5hHOXo6XezMGeM=; b=LVSvzNY9NDnF+d/mm0bj1irs2MaHelwXVxj0tyR65iJjqLDWwkrOkD+phqCGveobv0 Ndywlb0SaIz82eMoyVmjg8ZWSILoFmOZlPO+m1bQ0At0oite0q9emvNMa9bW398By7Dm fcJ+WL3MYrOp7whhdCUY6wzp0rgorApXhfUGE9h4AabBVK3OfpZHlA6lCz4xMT4///kB 10diS0KcFPay5UAdffuPd6meHDHHDCeZmk3TiqlMwoCq6lmEAlsPHkq/MfBzBoLGKydB E4YBoi+9WIbcLrCjvtpnPAAFvkuBhevuU34S1x3CvhIux42ZyudyluhCw+Z/y/X+FmL8 qlfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MHOAWosS; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 28si4836852pgk.331.2019.08.30.10.51.54; Fri, 30 Aug 2019 10:52:09 -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; dkim=pass header.i=@chromium.org header.s=google header.b=MHOAWosS; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728067AbfH3Rtk (ORCPT + 99 others); Fri, 30 Aug 2019 13:49:40 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:34452 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727246AbfH3Rtj (ORCPT ); Fri, 30 Aug 2019 13:49:39 -0400 Received: by mail-wm1-f67.google.com with SMTP id y135so4894113wmc.1 for ; Fri, 30 Aug 2019 10:49:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=a9y5rfT6nLtA1XdTe+7F8mFNtN6YI5hHOXo6XezMGeM=; b=MHOAWosS69n1MZDxUnmAZoQlakafemLqnOX8xOYY8UiBq/bvmqmNbOLhBAEZGOx/H3 EppFwORAEbQmjiKohgFOV1fCDNDfgXbB/5fpFe0bcwhibf+L5BgSkJ4IsPQsKiDRwwO5 ORSa/SlDl7oy4nJLHwtYjPeFduAKi9JbeFOoM= 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=a9y5rfT6nLtA1XdTe+7F8mFNtN6YI5hHOXo6XezMGeM=; b=rIz4TjAn0HkaBqQ8eCKxIyflgjAd7+PC9rP1JvMts6gHiRuEASfHiuXSMuBOOxo24g lQFKbIGjGQqM9CDFP+fcAle2SYSblSVlbwIJVkG/kIKwYsiZIoB0IEg5w/oDTIV0VWBb InjSUj6iKtgmzqtC7k9OELQUbgGcrxDT768Ilj9eEtpXdaoA+JN9JeUp78xIaQPns9AE 1F3m7RhI+PHpzAZYkZpewQ9d4qtPHozaj/PYO5nrki+VckeesJg1wgOjNrOOtRvhgVH8 P/S+M9Az7C74yj77OuWuWEexBgwCRMo5f+U3AIQ21tGnGmfCc/5BTmRAs/O4jiqrtGX4 fS8Q== X-Gm-Message-State: APjAAAVdg6byUSNapT1f5lX5MILa1B/6tI36aHUyEEHI//1AD3wn7cVT mypyFDeg9KXjp41RbmXH+tpqNa9hk4p6+Z5zvgwJ9g== X-Received: by 2002:a1c:f702:: with SMTP id v2mr20309772wmh.114.1567187377255; Fri, 30 Aug 2019 10:49:37 -0700 (PDT) MIME-Version: 1.0 References: <20190829212417.257397-1-davidriley@chromium.org> <20190830060857.tzrzgoi2hrmchdi5@sirius.home.kraxel.org> <20190830111605.twzssycagmjhfa45@sirius.home.kraxel.org> In-Reply-To: <20190830111605.twzssycagmjhfa45@sirius.home.kraxel.org> From: David Riley Date: Fri, 30 Aug 2019 10:49:25 -0700 Message-ID: Subject: Re: [PATCH] drm/virtio: Use vmalloc for command buffer allocations. To: Gerd Hoffmann Cc: dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, David Airlie , Daniel Vetter , Gurchetan Singh , =?UTF-8?Q?St=C3=A9phane_Marchesin?= , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Gerd, On Fri, Aug 30, 2019 at 4:16 AM Gerd Hoffmann wrote: > > Hi, > > > > > - kfree(vbuf->data_buf); > > > > + kvfree(vbuf->data_buf); > > > > > > if (is_vmalloc_addr(vbuf->data_buf)) ... > > > > > > needed here I gues? > > > > > > > kvfree() handles vmalloc/kmalloc/kvmalloc internally by doing that check. > > Ok. > > > - videobuf_vmalloc_to_sg in drivers/media/v4l2-core/videobuf-dma-sg.c, > > assumes contiguous array of scatterlist and that the buffer being converted > > is page aligned > > Well, vmalloc memory _is_ page aligned. True, but this function gets called for all potential enqueuings (eg resource_create_3d, resource_attach_backing) and I was concerned that some other usage in the future might not have that guarantee. But if that's overly being paranoid, I'm willing to backtrack on that. > sg_alloc_table_from_pages() does alot of what you need, you just need a > small loop around vmalloc_to_page() create a struct page array > beforehand. That feels like an extra allocation when under memory pressure and more work, to not gain much -- there still needs to be a function that iterates through all the pages. But I don't feel super strongly about it and can change it if you think that it will be less maintenance overhead. > Completely different approach: use get_user_pages() and don't copy the > execbuffer at all. This one I'd rather not do unless we can show that the copy is actually a problem. As it stands I expect this to be a fallback instead of the regular case, and if it's not then the VMs need to revisit how long the control queue size is. Right now most execbuffers end up being copied into a single contiguous buffer which results in 3 descriptors of the virtio queue. If vmalloc ends up being used (which is only a fallback because vmemdup_user tries kmalloc first still), then there'll be 66 descriptors for a 256KB buffer. I think that's fine for exceptional cases, but not ideal if it was commonplace. Chia-I suggested that we could have a flag for the ioctl execbuffer indicating that the buffer is BO to solve that, but again I'd prefer to see that it's actually a problem. I'll also be moving the sg table construction out of the critical section and properly accounting for the required number of descriptors before entering it in response to his comments. Thanks, Dave