From patchwork Fri Jan 24 23:54:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13950038 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20C58C02181 for ; Fri, 24 Jan 2025 23:56:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 172F62800BE; Fri, 24 Jan 2025 18:56:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1237D2800B0; Fri, 24 Jan 2025 18:56:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EDE532800BE; Fri, 24 Jan 2025 18:56:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C4B372800B0 for ; Fri, 24 Jan 2025 18:56:17 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7F7D5C1532 for ; Fri, 24 Jan 2025 23:56:17 +0000 (UTC) X-FDA: 83044006794.19.8FD615F Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf17.hostedemail.com (Postfix) with ESMTP id 538EC4000D for ; Fri, 24 Jan 2025 23:56:15 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=HreZ+IIN; spf=pass (imf17.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737762975; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=X0po0sWopN9sdAxoG7FE/M7ahK8VIPD0eThxsGOy3dw=; b=tY/LF3798Ta2WQYcVbXgv4YTm8AAReS9HZQ5hel6rIoidPn07/PxKJuQkIEWDnFPFVfgfc juwxTm9BZ6uzE+sMcMw1+i3hHB/QIxjv5l5f9TmBZsOQLIjn2Vv4kJhHnNdA9c3zWDyGSH zNxV0P6o8i6ZyXClSVrV4mku5GWC1bA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737762975; a=rsa-sha256; cv=none; b=V3yCCqyMydQTN/ey0YASNnKaaOZTN3Dc7g42bEzCrnxIwYMUs8rO5aV3rgAbK8TR86FFpA kdvHrcMdivj6Rec06/hZKcR+gjG/G2RkxUeKIjpoMGWk3tf15AliBuoBEBN5EoTyWplVJQ UCiW+J2l1lgoGPajME35ccAWqIKjWQw= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=HreZ+IIN; spf=pass (imf17.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50OIBX66001521; Fri, 24 Jan 2025 23:56:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2023-11-20; bh=X0po0 sWopN9sdAxoG7FE/M7ahK8VIPD0eThxsGOy3dw=; b=HreZ+IINxUUt+Ox8BrN6k 6Z+qo+dQKjtgOpUCTcmokqyKC8EDmnBK2Cf+RCng15P/GkxFg0YXJdOy4fwxNpBY Dg33t34z09UTLSboAUdg1aUmGbgXxjuHDSoaCEy3SrV/28oxHKjTvHW3OIS8Zx5D DGKtvBeW6Ae3gzmirx1E1l76v6cYlLcpkQyY2Q9SyYL+msDRSVRrRQaHj9J2imvK 5KRtFLNDEJ2pS4aQtFeUrnedt0uyCLN7NtseR0U2zF2H23db2kvhKkEO7XVws/uZ ATY/rdXNTX7N0L3xJlOQh/jjZUdGVZNw2s8m51crRzx6N9pzGPxZCreQtHBzT8EX Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44b06j5j48-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:56:03 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OMMu6P036606; Fri, 24 Jan 2025 23:56:02 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4an8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:56:02 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxQG018051; Fri, 24 Jan 2025 23:56:01 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-18; Fri, 24 Jan 2025 23:56:01 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 17/20] mshare: add MSHAREFS_UNMAP Date: Fri, 24 Jan 2025 15:54:51 -0800 Message-ID: <20250124235454.84587-18-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=914 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-ORIG-GUID: rYZnMe-DfE5Cl4XS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y4p14qfCHrTL7VF/jc48samogXh/fs6I8ovvmWKJs3YoYK1Q0KP1Lr6mhGn1/ZW86TDB4H+O4H0iRN1Rq BHVgL1KN 5lcTDCPa34y8Aow/SHrjrOovekP40jYlYCHxZspcWglw6KqxzG8y1GTHafmqE6fqYhG86Ytp1V4kqE2H2GHdO98cbaKKyyMHl8bOEkJK+rNUkqmJebJiW1S9XQaxXPK4zWtmSC8h5whRQ8W9UPlVt7vY7+iuBFfdX1CLAjckRFAZpKVLeT6EV7/AbsQ1WR1JEjZ/wWwik5hm73jj9YR7cuNrUr1HsKD8qB//vE4uV2eHSkcn6sUox1rHKRx8zTGqBjgfYJdvZDAI5DUwsbKJ0OcZcqg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add an ioctl for unmapping objects in an mshare region. Signed-off-by: Anthony Yznaga --- include/uapi/linux/msharefs.h | 7 ++++++ mm/mshare.c | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/include/uapi/linux/msharefs.h b/include/uapi/linux/msharefs.h index fea0afdf000d..f7af1f2b5ee7 100644 --- a/include/uapi/linux/msharefs.h +++ b/include/uapi/linux/msharefs.h @@ -21,6 +21,7 @@ #define MSHAREFS_GET_SIZE _IOR('x', 0, struct mshare_info) #define MSHAREFS_SET_SIZE _IOW('x', 1, struct mshare_info) #define MSHAREFS_CREATE_MAPPING _IOW('x', 2, struct mshare_create) +#define MSHAREFS_UNMAP _IOW('x', 3, struct mshare_unmap) struct mshare_info { __u64 start; @@ -35,4 +36,10 @@ struct mshare_create { __u32 flags; __u32 fd; }; + +struct mshare_unmap { + __u64 addr; + __u64 size; +}; + #endif diff --git a/mm/mshare.c b/mm/mshare.c index d70f10210b46..8f53b8132895 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -241,6 +241,32 @@ msharefs_create_mapping(struct mm_struct *host_mm, struct mshare_data *m_data, return err; } +static long +msharefs_unmap(struct mm_struct *host_mm, struct mshare_data *m_data, + struct mshare_unmap *m_unmap) +{ + unsigned long mshare_start, mshare_end; + unsigned long addr = m_unmap->addr; + unsigned long size = m_unmap->size; + int err; + + mshare_start = m_data->minfo.start; + mshare_end = mshare_start + m_data->minfo.size; + + if ((addr < mshare_start) || (addr >= mshare_end) || + (addr + size > mshare_end)) + return -EINVAL; + + if (mmap_write_lock_killable(host_mm)) + return -EINTR; + + err = do_munmap(host_mm, addr, size, NULL); + + mmap_write_unlock(host_mm); + + return err; +} + static long msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { @@ -248,6 +274,7 @@ msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) struct mm_struct *host_mm = m_data->mm; struct mshare_info minfo; struct mshare_create mcreate; + struct mshare_unmap m_unmap; switch (cmd) { case MSHAREFS_GET_SIZE: @@ -293,6 +320,23 @@ msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return msharefs_create_mapping(host_mm, m_data, &mcreate); + case MSHAREFS_UNMAP: + if (copy_from_user(&m_unmap, (struct mshare_unmap __user *)arg, + sizeof(m_unmap))) + return -EFAULT; + + /* + * validate mshare region + */ + spin_lock(&m_data->m_lock); + if (m_data->minfo.size == 0) { + spin_unlock(&m_data->m_lock); + return -EINVAL; + } + spin_unlock(&m_data->m_lock); + + return msharefs_unmap(host_mm, m_data, &m_unmap); + default: return -ENOTTY; }