Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp733564pxb; Tue, 2 Feb 2021 17:03:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJy2DjKx4qDuzYD5tYvlB+/uygnv0TQ1NU2Fdpr7dFEEdzRA0rM01CXY20UyjEdR86ByxLo5 X-Received: by 2002:a17:906:ae50:: with SMTP id lf16mr709024ejb.66.1612314202371; Tue, 02 Feb 2021 17:03:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612314202; cv=none; d=google.com; s=arc-20160816; b=BOHw/y5rTHmS8GjCdfTUAoZffTNbNPt8RBToPJY/ypsuJsc+/cIp1zdWzsRaZypTB2 wnqbqMPkoHGDrOaQfcD75iFeBJa7SjS1oNHvl5sZe/EnQ9iRCnq6IVy9Fzjvt3POpZQA aXX4uSdt/jPcEL2yG195mAUg9qZeeTS691dEqhCU01s4Udox5g+qAqBKKiLsOxcGfQPI +Vgo/hJtvwfW/kE7+uMWUL5t1cAdSU3A0Xxex9eZHAH8QX6evdYLrkEK1qn2jLGv3vce csXO/Uip5GFpxhbTW2ikn0NydRtgQl1eFDF4Ozw8pifU2582/nQtHqcwLWrRFg20TwBa wPyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=5KtTzd9k+c9bS2Y/wk34+i/vvyNbysJG7UZJv8N2Wp4=; b=mEaMPeVW6V+JCeiqq56OzdQpu2NJsF0ThRd9clN8VRL6LF6JvQfDVm6Q2cbhr9NrsE QWy9rDMeElFujTnBB054YYLfc4yW2tie4FYxc023aCQkN4SWQ7qGdkmaXTG9UrkNe3pz w/GufNTQnVhkD59vXig1lGCcHXYlzJAzki5PUJbH9TXv6n9meAPUBwB1O23Uie5m24Yl lgAUcOZwUqhncgwjDGhkwZ8BoUNNl1PTiHczIlEls2uWeyEvknws2T7STR77bKemWgr8 Ex/Jcg0nSYILPffjZLPRcokeX27G9U3FaBRYgc1BBFKpeu1oQBnKj8zTT2O+f8nEzcFN kn9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=oNXRZrun; 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 o17si293867edf.247.2021.02.02.17.02.58; Tue, 02 Feb 2021 17:03:22 -0800 (PST) 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=oNXRZrun; 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 S232329AbhBCAcV (ORCPT + 99 others); Tue, 2 Feb 2021 19:32:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232349AbhBCAcT (ORCPT ); Tue, 2 Feb 2021 19:32:19 -0500 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE06FC061786 for ; Tue, 2 Feb 2021 16:31:38 -0800 (PST) Received: by mail-qt1-x84a.google.com with SMTP id g14so15723081qtu.13 for ; Tue, 02 Feb 2021 16:31:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=5KtTzd9k+c9bS2Y/wk34+i/vvyNbysJG7UZJv8N2Wp4=; b=oNXRZrunpy+nJxCNVG2DVespyvOU6v+/PBcSm/lmaxwIlZyPY+Y+aGI83iN/QE12TQ /9B5j+GzglaY+R0ZfttfhxpqWqSdb8Mhk5fb+2BB6mUU3pAKYZ4YkOotTy5PPFko52Yw DjiUxnZm5/e875fNSMeJZUpfPmcgyFUAHmh7OGgzKQMnmFkSDTyR+23aDUO7XbQpLyJ/ ODLwOmX6057PVKLp4hTX/hoK0O+U8lfiVVL2hxkockdBfgWJvRtI34i+fdKn9nJsjv6I DrqX9S8rzdrQ6xlTKqKv6sGUpn32curAQw3IMOe9YcnA/sGJg2xlAFdtgblXQs264SLf TFKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=5KtTzd9k+c9bS2Y/wk34+i/vvyNbysJG7UZJv8N2Wp4=; b=FySsphWgg7G0H1wxUjAghN4mFMzjhh6fRA8XzYD5KQUZTZbx6k2WiaWMcy1N0wo8xv v1Hh7LGnFfSzPa+pAHA1Td5gZw9VOjr+fXbLhSGEpMzdH75xvXXptYUoSrr2QgIJoC7G WB12rvdOCxhbfNroeYs5ZUA2PWRZinfKwPTtNbBVrAVas0niqKKO7DaxgM8uf8kpEx/W 8eKtiXma1IBh+WG7HrMRijltY+TMMS8t2dQ2jN3hVMaFUzT2k47xDKiZc3c+zp8yZh+u 5wegZIUbOJpP+qgKNKPGtVg2bA8OPj7ypo8VTVwYUn3FuotA4s90pnpM4OUojCDLeWMs zCUw== X-Gm-Message-State: AOAM533VIbmlZX6mmliCc120DxND4CKPu91dR3a77ujD6ncVC63f+sRU rv7rRwhZ+EPvuFXwTD62rOWtjQXDVvE= Sender: "surenb via sendgmr" X-Received: from surenb1.mtv.corp.google.com ([2620:15c:211:200:9194:cd6:1ec:3e2d]) (user=surenb job=sendgmr) by 2002:a0c:8365:: with SMTP id j92mr418503qva.19.1612312297983; Tue, 02 Feb 2021 16:31:37 -0800 (PST) Date: Tue, 2 Feb 2021 16:31:34 -0800 In-Reply-To: <20210203003134.2422308-1-surenb@google.com> Message-Id: <20210203003134.2422308-2-surenb@google.com> Mime-Version: 1.0 References: <20210203003134.2422308-1-surenb@google.com> X-Mailer: git-send-email 2.30.0.365.g02bc693789-goog Subject: [PATCH v2 2/2] dma-buf: heaps: Map system heap pages as managed by linux vm From: Suren Baghdasaryan To: sumit.semwal@linaro.org Cc: akpm@linux-foundation.org, hch@infradead.org, lmark@codeaurora.org, labbott@redhat.com, Brian.Starkey@arm.com, john.stultz@linaro.org, christian.koenig@amd.com, cgoldswo@codeaurora.org, orjan.eide@arm.com, robin.murphy@arm.com, jajones@nvidia.com, minchan@kernel.org, hridya@google.com, sspatil@google.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com, surenb@google.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently system heap maps its buffers with VM_PFNMAP flag using remap_pfn_range. This results in such buffers not being accounted for in PSS calculations because vm treats this memory as having no page structs. Without page structs there are no counters representing how many processes are mapping a page and therefore PSS calculation is impossible. Historically, ION driver used to map its buffers as VM_PFNMAP areas due to memory carveouts that did not have page structs [1]. That is not the case anymore and it seems there was desire to move away from remap_pfn_range [2]. Dmabuf system heap design inherits this ION behavior and maps its pages using remap_pfn_range even though allocated pages are backed by page structs. Replace remap_pfn_range with vm_insert_page, following Laura's suggestion in [1]. This would allow correct PSS calculation for dmabufs. [1] https://driverdev-devel.linuxdriverproject.narkive.com/v0fJGpaD/using-ion-memory-for-direct-io [2] http://driverdev.linuxdriverproject.org/pipermail/driverdev-devel/2018-October/127519.html (sorry, could not find lore links for these discussions) Suggested-by: Laura Abbott Signed-off-by: Suren Baghdasaryan --- v1 posted at: https://lore.kernel.org/patchwork/patch/1372409/ changes in v2: - removed VM_PFNMAP clearing part of the patch, per Minchan and Christoph - created prerequisite patch to replace BUG_ON with WARN_ON_ONCE, per Christoph drivers/dma-buf/heaps/system_heap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index 17e0e9a68baf..4983f18cc2ce 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -203,8 +203,7 @@ static int system_heap_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma) for_each_sgtable_page(table, &piter, vma->vm_pgoff) { struct page *page = sg_page_iter_page(&piter); - ret = remap_pfn_range(vma, addr, page_to_pfn(page), PAGE_SIZE, - vma->vm_page_prot); + ret = vm_insert_page(vma, addr, page); if (ret) return ret; addr += PAGE_SIZE; -- 2.30.0.365.g02bc693789-goog