From patchwork Fri Dec 6 15:20:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Geffon X-Patchwork-Id: 13897282 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 9D161E77173 for ; Fri, 6 Dec 2024 15:20:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5DA2D8D0005; Fri, 6 Dec 2024 10:20:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C9566B0272; Fri, 6 Dec 2024 10:20:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07EF68D0005; Fri, 6 Dec 2024 10:20:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C8D806B0271 for ; Fri, 6 Dec 2024 10:20:43 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 66C191C8DFF for ; Fri, 6 Dec 2024 15:20:43 +0000 (UTC) X-FDA: 82864895148.17.51D8AE0 Received: from mail-qv1-f73.google.com (mail-qv1-f73.google.com [209.85.219.73]) by imf11.hostedemail.com (Postfix) with ESMTP id 0CC554001B for ; Fri, 6 Dec 2024 15:20:24 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Qn26xMiN; spf=pass (imf11.hostedemail.com: domain of 3RxZTZwcKCAIdighhqpiqqing.eqonkpwz-oomxcem.qti@flex--bgeffon.bounces.google.com designates 209.85.219.73 as permitted sender) smtp.mailfrom=3RxZTZwcKCAIdighhqpiqqing.eqonkpwz-oomxcem.qti@flex--bgeffon.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733498433; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IwVnOnXdfn92wl4sT1YHXRB8FIHmKCEwkprjF00N97k=; b=hZLNTpdxp5NEnaGVXh2pn9wL84bB7CPQX1ZS6w+HHIIhiVoEw0Tqb0fXUmKDCHyH5bGo1P +pVca4zJ/OpG1dMf5c0+/KfMfOypfoLnuTnfNqUUyDSuesLZzX/IbgViTNhwP2rDxHERBt Nu5VmfK03eRBqYxR3U9dKJqdqXLmVc0= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Qn26xMiN; spf=pass (imf11.hostedemail.com: domain of 3RxZTZwcKCAIdighhqpiqqing.eqonkpwz-oomxcem.qti@flex--bgeffon.bounces.google.com designates 209.85.219.73 as permitted sender) smtp.mailfrom=3RxZTZwcKCAIdighhqpiqqing.eqonkpwz-oomxcem.qti@flex--bgeffon.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733498433; a=rsa-sha256; cv=none; b=mPQFF98dkXFuU9vP1bxtEdic0qZ/nKOqV87y9Yw46wnU5QieWgvmoOQVFMwfv3T+cwHpfI AGxTPqhVDaLxhegd2ln0j2fYLoapeU/eJBMKNnqhJ97lbojFgrV3i9qgmcO33z7FiMjtb6 L+0GCF2taaz3YPn6e3i0O/8IO9CPO6c= Received: by mail-qv1-f73.google.com with SMTP id 6a1803df08f44-6d884999693so37405496d6.0 for ; Fri, 06 Dec 2024 07:20:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733498440; x=1734103240; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IwVnOnXdfn92wl4sT1YHXRB8FIHmKCEwkprjF00N97k=; b=Qn26xMiNF/M46doMCJXHR9nVcKxz8l3tN9YoLcC4warbF1J9+bgH0rauJzdQL7SsKr VL7uLV6qrYCFdSLD3d1b5wXwysD8zrXEP/VtIoq7DAPInt6ymkL3kD+C/mEDJhdjguVR Lz/4xrhY9uO+Qn1dthvWnmA5ilWWkBGjXbwNYt4FzrEzrVTy2ilKZYk4thUSvb83Bc9r WPsSBiyOzEc2//JBCrDvQHYvKJRKWnL7vT/c9iiuOSxfPGyRzaqE3Wt65BxwsanHx7lg 3HysVfajsEdfDz7FIAsBopS/aqwksm4Cx4kBNJIrcjNZH5PROzcBfc1FYqFitgVAWfTN 4YrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733498440; x=1734103240; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IwVnOnXdfn92wl4sT1YHXRB8FIHmKCEwkprjF00N97k=; b=TdMZN2NuBg+oQo6frkbs/Y8OhyrqilDolSGjQgAFuUzYYQJ6k/StzNDUb/Y0gYzFfj jXfAL5p5TJSKzLr3a+s68XKHnWBnUMTL/9PGt4zJZJEWN6tHIqWH+lS2FNlWqIkRUei3 xX8DLOqTKsMEoxYjATMdi0jqaoZKLqT7g8H3JtKLSfbSi55E1bmWJq5O2UpEkQVAqWBX 528EdX2ogwnR6z5hWlJ9nvd8XVg4uMkrif3wQyPbw/NwScSpvcZi8NHvNwgc3wsx66n8 T5xenKPz6E+74FxDx8RbVS+qGAuMrszkF2favBU7c2V1DIuBGxPCLTxjLRG+0gHK5V8a iuwQ== X-Gm-Message-State: AOJu0YzxpUsPTpJoUr3PNmImSQ/KLdskJfdQEBmGMN96z0kOCwvAh6WS lGaY0J1sU9V4uALeQY9BrQZiJeOcKFBmUGWCp5c/C4U7dzo4RxUhmbJlvzy0unzYDPho8hLd8I6 fVRRryw== X-Google-Smtp-Source: AGHT+IEfH1FXtnHp81uHQNCbhvflcG0KCGwOxAvecsfDiGH/fvZvEhEAXyUWb5dx7T3rn+eUqooSkCPdnl8A X-Received: from qvkj21.prod.google.com ([2002:a0c:e015:0:b0:6d8:a4c0:2078]) (user=bgeffon job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6214:d68:b0:6d8:b3a7:759e with SMTP id 6a1803df08f44-6d8e726ed48mr55069936d6.46.1733498439696; Fri, 06 Dec 2024 07:20:39 -0800 (PST) Date: Fri, 6 Dec 2024 10:20:31 -0500 In-Reply-To: <20241206152032.1222067-1-bgeffon@google.com> Mime-Version: 1.0 References: <20241206152032.1222067-1-bgeffon@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241206152032.1222067-2-bgeffon@google.com> Subject: [PATCH 1/2] mremap: Fix new_addr being used as a hint with MREMAP_DONTUNMAP From: Brian Geffon To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Brian Geffon , Marco Vanotti X-Rspamd-Queue-Id: 0CC554001B X-Stat-Signature: idn3zuir6j4s6rqsbf4oorzdx9kzmomn X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1733498424-619663 X-HE-Meta: U2FsdGVkX1+dDmSWstYu2qnmd2pVDXLnz/pQeNkCkWFtQ66Rz8MOfa8vBiJ4TtkYV2YoicrvRgbv7tCOYHNjke5eF/DItBWSn424WbO+wVFKMeoiZ7WvxcgZKsmtWrff8hn7qpcEH+gRA9eHa5xSe6flMtKenQCFGdH1f0WjALtttkb1FGhWoZF/0yzio+dAmzwGPrfU3BhGdigZD8V2EYOt5IhOzQ/lx0Qz+7pzIT/fihPms67hYN7mhNu6a2rhdqRj2OcbQMti7QqdcF7xesMrMPUAPrfxLg16lRDmLKbKKT3KeBbGo3m8b7WwYo7kQsY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EyB31yFjAL6C3Kt6dnghGdcgS+rIYclPbqXzL5RNeqTGSvbnD9je0cDfbi1DyOT5p1jOOzCPmjr7Q3ttAmhOBMaY8WfLEUDqS4PPoB7zuGRxUNao9SbHEsF9JAC9cfLCIAW8B4ITTlqvvHJL6PKxi/i8MHI1UCZj9JD8rPbDRNcq8bFxC4tyP//Wcs1mAM5imw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000553, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Two non-mutually exclusive paths can land in mremap_to, MREMAP_FIXED and MREMAP_DONTUNMAP which are called from mremap(). In the case of MREMAP_FIXED we must validate the new_addr to ensure that the new address is valid. In the case of MREMAP_DONTUNMAP without MREMAP_FIXED a new address is specified as a hint, just like it would be in the case of mmap. In this second case we don't need to perform any checks because get_unmapped_area() will align new_addr, just like it would in the case of mmap. Signed-off-by: Brian Geffon Reported-by: Marco Vanotti --- mm/mremap.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/mm/mremap.c b/mm/mremap.c index 60473413836b..286ffdb883df 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -912,15 +912,27 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len, unsigned long ret; unsigned long map_flags = 0; - if (offset_in_page(new_addr)) - return -EINVAL; + /* + * Two non-mutually exclusive paths can land in mremap_to, MREMAP_FIXED + * and MREMAP_DONTUNMAP which are called from mremap(). In the case of + * MREMAP_FIXED we must validate the new_addr to ensure that the new + * address is valid. In the case of MREMAP_DONTUNMAP without MREMAP_FIXED + * a new address is specified as a hint, just like it would be in the + * case of mmap. In this second case we don't need to perform any checks + * because get_unmapped_area() will align new_addr, just like it would in + * the case of mmap. + */ + if (flags & MREMAP_FIXED) { + if (offset_in_page(new_addr)) + return -EINVAL; - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len) - return -EINVAL; + if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len) + return -EINVAL; - /* Ensure the old/new locations do not overlap */ - if (addr + old_len > new_addr && new_addr + new_len > addr) - return -EINVAL; + /* Ensure the old/new locations do not overlap */ + if (addr + old_len > new_addr && new_addr + new_len > addr) + return -EINVAL; + } /* * move_vma() need us to stay 4 maps below the threshold, otherwise From patchwork Fri Dec 6 15:20:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Geffon X-Patchwork-Id: 13897281 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 C825CE7717B for ; Fri, 6 Dec 2024 15:20:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CD8A6B0274; Fri, 6 Dec 2024 10:20:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 191066B026C; Fri, 6 Dec 2024 10:20:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DEC8A6B0274; Fri, 6 Dec 2024 10:20:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id AAD7E6B026C for ; Fri, 6 Dec 2024 10:20:43 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 59D7316172F for ; Fri, 6 Dec 2024 15:20:43 +0000 (UTC) X-FDA: 82864896156.28.A88F964 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf28.hostedemail.com (Postfix) with ESMTP id 6003FC001E for ; Fri, 6 Dec 2024 15:20:21 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=eDGm9GBt; spf=pass (imf28.hostedemail.com: domain of 3SBZTZwcKCAMejhiirqjrrjoh.frpolqx0-ppnydfn.ruj@flex--bgeffon.bounces.google.com designates 209.85.160.202 as permitted sender) smtp.mailfrom=3SBZTZwcKCAMejhiirqjrrjoh.frpolqx0-ppnydfn.ruj@flex--bgeffon.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733498423; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8zF6cyo4V+yV1OddWsDU7llWFhEXM57i4QvxWba9u5g=; b=cZDMaMwxB3bARDjFu5U5KDFL1DTttUyuTjcc3HVwBgIcwIJ+JrVZuqrPtV3T80bgxN60xd ukB07dRFEWMlY+1gvsQ8dfx9aIWPYhFSFMeoougX43zoXtAG2A835kPLaqfCphH4gRQrgK JGRbo0Vxhmq0NF5DE7xifyGKtiu1/zc= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=eDGm9GBt; spf=pass (imf28.hostedemail.com: domain of 3SBZTZwcKCAMejhiirqjrrjoh.frpolqx0-ppnydfn.ruj@flex--bgeffon.bounces.google.com designates 209.85.160.202 as permitted sender) smtp.mailfrom=3SBZTZwcKCAMejhiirqjrrjoh.frpolqx0-ppnydfn.ruj@flex--bgeffon.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733498423; a=rsa-sha256; cv=none; b=Z5K3J6XDu1uWwL43Yt4hfEwv2YgDHY3C1LnfVZTArB7m68nTNY/cK9FiJc+sbxkG9Yfr1C wa6nA4LCuJ9fo8JsudrzE99GGqDD1sKT1NTUZzwLqegqZ8hiHy1R6/nGIrakFAP1nQu4xS obiX0xUwm5OG1hOBizIkOXseydWuNFE= Received: by mail-qt1-f202.google.com with SMTP id d75a77b69052e-4669bf7cef7so44183511cf.1 for ; Fri, 06 Dec 2024 07:20:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733498440; x=1734103240; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8zF6cyo4V+yV1OddWsDU7llWFhEXM57i4QvxWba9u5g=; b=eDGm9GBtPi0zuNA0u0CyZUB/U/MgOsjVMgF/s2am7NhfcgmVFZb4kMOz1kU7hM5dDi IqxrYuLwF1WyqVxaTkK7MqXLaEGJuZq1cgDu7K57sxwaPeylVuGbX7DfxDt81I90uSOw fF6ZjxsiGzi1gq5Nyei/Oi06BGj5TF9TeGrQb4ErPRDK9GtK6HzP4vc0uTq0S257IYho Zyj/+VRUmhrFC1R+gMDjvaWJEKyBxbAUbUBSBMqABcCQFJvJOz4R2Qqfe4sM9Bdk57R1 I428Dj84YaRvecOGeO7APINYfiI5Qvd21Er15XI4X1PojsXDLKquj/f6IYREfDpI7VTq FtQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733498440; x=1734103240; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8zF6cyo4V+yV1OddWsDU7llWFhEXM57i4QvxWba9u5g=; b=a29fYqo38tSyQBdvqcmyjiMowcsZD4tuH4xrvEfL3bIjB4eGj4oxC9Gt6EA42CZC1A CwEDXwZ8BSTy8xH8HIe9kg1D0VZi7+/++0mSgx7zzOP3kNeWHumt0WzBynDiGN7eHf2R oeZUqNmG1bnjOOyBUUaZ58HZUfcaMVqyydVsny/oqiNRwP1gT9rHtoairC5Z18KxQbcZ XFNvK7DeDZstz7A2NuXVi6mY1zrg2w/kLpfpjM3FQjTr4pDgoBtqBO5qQAepg4NKq3nE HjGkJjOkx9s6S5Feya9xxp34yitnamOj79bXwLhlAb2s+wCyetuB+EZRwVFb+v1ifBIM bNBw== X-Gm-Message-State: AOJu0YzrMbX2ocjChbAwmWG+oLybt8hKMs8FRRb3M1eCmXhJoYz/uTck VQ08zOb6cC/umbrmoL0apgt9C2ghOp9QD6PQpYP1SGHbtJphc6fIHWhMt228WPXxBP9xamWaAIo yaUwOEg== X-Google-Smtp-Source: AGHT+IGb3dyB+1mIM9uaJ8shaiN2smOAw7d48MDhvLaY9VwvHL+JlNyqB1itmzCSQbeXEMb+r4xoquxqxwdB X-Received: from qtcw37.prod.google.com ([2002:a05:622a:1925:b0:462:ac63:5263]) (user=bgeffon job=prod-delivery.src-stubby-dispatcher) by 2002:ac8:57cb:0:b0:467:1f3c:4d22 with SMTP id d75a77b69052e-46734e26188mr80292871cf.52.1733498440618; Fri, 06 Dec 2024 07:20:40 -0800 (PST) Date: Fri, 6 Dec 2024 10:20:32 -0500 In-Reply-To: <20241206152032.1222067-1-bgeffon@google.com> Mime-Version: 1.0 References: <20241206152032.1222067-1-bgeffon@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241206152032.1222067-3-bgeffon@google.com> Subject: [PATCH 2/2] selftests: mm: Add a new MREMAP_DONTUNMAP self test From: Brian Geffon To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Brian Geffon X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6003FC001E X-Rspam-User: X-Stat-Signature: fwdzede1o8kojacwj64oiiwbwhcsmgmi X-HE-Tag: 1733498421-957763 X-HE-Meta: U2FsdGVkX1+PqdHeTepmduEusvW12XxxikakKwDQRk02zbT5VPj3v0YQdJHBZa/57UHyTpsazCnhZTRkHjUFUnd3scvgJYOX7biQ6/W5kH59c8NR7LHjCbTFxwX2hSLmNsnvO6jtB539lXaVeRQKz7HKNcRWCRM6wjPZb4yIWfY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a0a51gabK8kSZcqhaU22ClGl1zJXdqAMNpMxTJIsqNm2mWaRzK5l5STLxtik3fdQM5aSMFKGblvmtr/VSwqZPFBnKpsLlQYxQugfc30Ewl7fVXyIxIeuXYdnyAk8oKiOuNDHr++DadAZdqc0Zhhw+GMbdBYhQGE2WfhvHOrnHonwxgoXu+kjtCN90TrdJPrJx8ai+rMLbdg5FAR1SDP2hdE2A8FrpjnbRc/4Hpb2BTbZVGquQC9P+3u7V3BZ0eQazFryDDtGQfSam1fz/lrv0/YROGWGFUnPKJ7tRBXAPvr0nTa/C55DC/I8HGWk/N/5eEtYJolel6navT78INu9jpSGV+fgNMh X-Bogosity: Ham, tests=bogofilter, spamicity=0.000790, 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 a new selftest which validates that a new_addr as a hint behaves in the same way as mmap. Signed-off-by: Brian Geffon --- tools/testing/selftests/mm/mremap_dontunmap.c | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/mremap_dontunmap.c b/tools/testing/selftests/mm/mremap_dontunmap.c index 1d75084b9ca5..ccce97c68019 100644 --- a/tools/testing/selftests/mm/mremap_dontunmap.c +++ b/tools/testing/selftests/mm/mremap_dontunmap.c @@ -224,6 +224,44 @@ static void mremap_dontunmap_simple_fixed() ksft_test_result_pass("%s\n", __func__); } +// This test validates MREMAP_DONTUNMAP using a newaddr hint without +// MREMAP_FIXED. +static void mremap_dontunmap_simple_newaddr_hint() +{ + unsigned long num_pages = 5; + + // This dest hint is intentionally not aligned. + void *new_addr_hint = (void*)0x999900010; + + void *source_mapping = + mmap(NULL, num_pages * page_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + BUG_ON(source_mapping == MAP_FAILED, "mmap"); + memset(source_mapping, 'a', num_pages * page_size); + + void *remapped_mapping = + mremap(source_mapping, num_pages * page_size, num_pages * page_size, + MREMAP_DONTUNMAP | MREMAP_MAYMOVE, + new_addr_hint); + BUG_ON(remapped_mapping == MAP_FAILED, "mremap"); + + // And the source mapping will have had its ptes dropped. + BUG_ON(check_region_contains_byte + (source_mapping, num_pages * page_size, 0) != 0, + "source should have no ptes"); + + // And the remapped area will be filled with 'a's. + BUG_ON(check_region_contains_byte + (remapped_mapping, num_pages * page_size, 'a') != 0, + "dest should have remapped content"); + + BUG_ON(munmap(source_mapping, num_pages * page_size) == -1, + "unable to unmap source mapping"); + BUG_ON(munmap(remapped_mapping, num_pages * page_size) == -1, + "unable to unmap source mapping"); + ksft_test_result_pass("%s\n", __func__); +} + // This test validates that we can MREMAP_DONTUNMAP for a portion of an // existing mapping. static void mremap_dontunmap_partial_mapping() @@ -348,7 +386,7 @@ int main(void) ksft_finished(); } - ksft_set_plan(5); + ksft_set_plan(6); // Keep a page sized buffer around for when we need it. page_buffer = @@ -359,6 +397,7 @@ int main(void) mremap_dontunmap_simple(); mremap_dontunmap_simple_shmem(); mremap_dontunmap_simple_fixed(); + mremap_dontunmap_simple_newaddr_hint(); mremap_dontunmap_partial_mapping(); mremap_dontunmap_partial_mapping_overwrite();