From patchwork Mon Sep 14 13:29:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 11773779 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C89AB618 for ; Mon, 14 Sep 2020 13:29:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 70153208E4 for ; Mon, 14 Sep 2020 13:29:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LNYaV5ht" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 70153208E4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9FFD1900007; Mon, 14 Sep 2020 09:29:52 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9B07A900002; Mon, 14 Sep 2020 09:29:52 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C6A4900007; Mon, 14 Sep 2020 09:29:52 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0235.hostedemail.com [216.40.44.235]) by kanga.kvack.org (Postfix) with ESMTP id 74335900002 for ; Mon, 14 Sep 2020 09:29:52 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1614C6EDFC for ; Mon, 14 Sep 2020 13:29:52 +0000 (UTC) X-FDA: 77261749824.17.low66_58101c227109 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 11A8A18034F4A for ; Mon, 14 Sep 2020 13:29:33 +0000 (UTC) X-Spam-Summary: 1,0,0,0c321bd2e6717b54,d41d8cd98f00b204,ckoenig.leichtzumerken@gmail.com,,RULES_HIT:41:69:152:355:379:541:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1535:1542:1593:1594:1676:1711:1730:1747:1777:1792:2393:2559:2562:2899:3138:3139:3140:3141:3142:3353:3865:3867:4250:4321:4605:5007:6261:6653:9413:10004:10400:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:12986:13894:14096:14097:14181:14394:14659:14687:14721:21080:21444:21451:21627:21666:21990:30054:30064:30069:30070,0,RBL:209.85.208.66:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.18.84.100;04y85x65a6oredsyit6unwgf94gmtop6yoz4anz3j4qp1h8akk587yt1x699moq.e1358w4ti3kqhub83wb9un18xwa4xkqefogyop14cnfqbimt1gs1aehmanzd4qj.4-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: low66_58101c227109 X-Filterd-Recvd-Size: 5403 Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Sep 2020 13:29:32 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id b12so17571175edz.11 for ; Mon, 14 Sep 2020 06:29:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2sgKFqAzyYTWFS7DpgNkPf7xuqkExWpe0vtA6hya4p8=; b=LNYaV5htN1AoGcRr3qutKAdIAJ9K2NpHJmZnCLnFDlG8+zhSr8pFBVrIVZbK7upLCy XuYIA5pbVz06HyYiXjA0CX8OrBfsP8QYVTX6yJ60VAjafiTzs3Dr1q7h1S6WN1SGAvlY UXlmfxZ5/aBJS18uzwRmNUI3/lYVMDzcdWcPZzIRtlGG2B6QiV90AnQEfAOpca3J5cuM fi/i79PCqkzlb/1pkXfPwtPFhCm+AEfUwe9iWPeCcG3ahwbSU9PfGzYe8A8PulfEuuIe /yCSNERBUwZ4Herw4m2hVxb+aHQ2rdJcpWKX6iPZoqfXgRCIkWGGqsSIIr4ud7pRIc3R 2DEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2sgKFqAzyYTWFS7DpgNkPf7xuqkExWpe0vtA6hya4p8=; b=jD/+3XSfknSkSSzzJZr8CKgpiBDkfts1Oa7a2aCWfe/UcvgeWNqTKXNO6u+8tps0VE 8zXyYFriVRFOB8HZTkr0MGu5FNEOLit5A0iqEM6IQsuLlskfy8AE2+WQ/cAsbVaw2JoX F+8OTf6Lu4ChwQ8KgtkdFDAO9M+jC+lkno2T6rJIw4fQkGMXWEFtnJSXy7gvZaJjv5lY Mc2Ry7f1ouu/7q1fWyEZDp0XIGPIlsZJqd/WzD8h70sevh63+6TiaLRKYFBkk1pAx9rA DicwjEsZt4F0CK03k60Fn80KQZa+e1wnk7Z+H+S5cIbmy1l9abA+QmSr5vKT/2vKOpJB YWSw== X-Gm-Message-State: AOAM533+UsgUIUC3m5C+id1jn4pqcOCXFSu3iKalPkKbNeZvdPWxDvOi HeQ0pcz5fcCzUIwvvAk0WhM= X-Google-Smtp-Source: ABdhPJwqz+YzShnzPAVkh+LgWPDH996EZ9R5Asg2qCZETs+L6ijZw4dfeniXkQwebJgtgDxC1+lltA== X-Received: by 2002:aa7:cad3:: with SMTP id l19mr16523629edt.352.1600090171724; Mon, 14 Sep 2020 06:29:31 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:6179:d701:8021:da3d]) by smtp.gmail.com with ESMTPSA id d6sm9575625edm.31.2020.09.14.06.29.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 06:29:30 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: akpm@linux-foundation.org Cc: sumit.semwal@linaro.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/2] mm: introduce vma_set_file function Date: Mon, 14 Sep 2020 15:29:20 +0200 Message-Id: <20200914132920.59183-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200914132920.59183-1-christian.koenig@amd.com> References: <20200914132920.59183-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 11A8A18034F4A X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add the new vma_set_file() function to allow changing vma->vm_file with the necessary refcount dance. Signed-off-by: Christian König Reported-by: kernel test robot Reported-by: kernel test robot --- drivers/dma-buf/dma-buf.c | 16 +++++----------- include/linux/mm.h | 2 ++ mm/mmap.c | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 1699a8e309ef..672f3525ba74 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1163,20 +1163,14 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, return -EINVAL; /* readjust the vma */ - get_file(dmabuf->file); - oldfile = vma->vm_file; - vma->vm_file = dmabuf->file; + oldfile = vma_set_file(vma, dmabuf->file); vma->vm_pgoff = pgoff; ret = dmabuf->ops->mmap(dmabuf, vma); - if (ret) { - /* restore old parameters on failure */ - vma->vm_file = oldfile; - fput(dmabuf->file); - } else { - if (oldfile) - fput(oldfile); - } + /* restore old parameters on failure */ + if (ret) + vma_set_file(vma, oldfile); + return ret; } diff --git a/include/linux/mm.h b/include/linux/mm.h index 1983e08f5906..398a6fdaad1e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2688,6 +2688,8 @@ static inline void vma_set_page_prot(struct vm_area_struct *vma) } #endif +struct file *vma_set_file(struct vm_area_struct *vma, struct file *file); + #ifdef CONFIG_NUMA_BALANCING unsigned long change_prot_numa(struct vm_area_struct *vma, unsigned long start, unsigned long end); diff --git a/mm/mmap.c b/mm/mmap.c index 40248d84ad5f..d3c3c510f643 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -136,6 +136,22 @@ void vma_set_page_prot(struct vm_area_struct *vma) WRITE_ONCE(vma->vm_page_prot, vm_page_prot); } +/* + * Change backing file, only valid to use during initial VMA setup. + */ +struct file *vma_set_file(struct vm_area_struct *vma, struct file *file) +{ + if (file) + get_file(file); + + swap(vma->vm_file, file); + + if (file) + fput(file); + + return file; +} + /* * Requires inode->i_mapping->i_mmap_rwsem */