From patchwork Sat Jan 12 00:36:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Blake Caldwell X-Patchwork-Id: 10760821 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BB37117FB for ; Sat, 12 Jan 2019 00:37:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A969C29F70 for ; Sat, 12 Jan 2019 00:37:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E01529F75; Sat, 12 Jan 2019 00:37:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7305029F70 for ; Sat, 12 Jan 2019 00:37:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F63F8E0006; Fri, 11 Jan 2019 19:36:59 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EF8E38E0001; Fri, 11 Jan 2019 19:36:58 -0500 (EST) 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 CD1D18E0006; Fri, 11 Jan 2019 19:36:58 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-it1-f197.google.com (mail-it1-f197.google.com [209.85.166.197]) by kanga.kvack.org (Postfix) with ESMTP id A2ABC8E0001 for ; Fri, 11 Jan 2019 19:36:58 -0500 (EST) Received: by mail-it1-f197.google.com with SMTP id 135so3209147itk.5 for ; Fri, 11 Jan 2019 16:36:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:in-reply-to:references; bh=G/V5x8DCIe/YBCFLV6oYQSvuz1De4Eq2CvrRknnvIFk=; b=sNY8z4NwyxTdMv1Sdo74C1wSzIZvbOS6a9k66J0VQfDWx7vjlvYRBALZf9m9t+/JlO /W/xVfunCsG0kbSb9ZvTHwInz6QOFiitw/dus2mwGCiEykagt3rNKQKmUKxlcKeN2DlW HtTPukJ7qbovtl0tOInNzEV/VLmk9RJHkHedNBAjokaAdkDOeOG10mDpo2307RxhJRLt BH/j75b9hSQZyfKRmEM0QK5yeehEpXbXi1YozBipvyt2bRxapY5xalHC4i1oMMpd/ytD KWWTPWepShfFTpJMHRRAuoyPCVGBp5elKzjzjtmBDM83UjSf8QL0VosWrow7Bw7Ivvw6 Epaw== X-Gm-Message-State: AJcUukfx1KrxKX9wzNf3UkMsd7326aecv/kFvub6cfuPqcvaGQsN9Frf 3msydRjqopRacmRvEPoQZR9pl5EL2Z3wM/kH4eMCOlyiwD0KJzHRw5cmoGslUrCrSEHWlUuSw9/ ns5SZ4IlziSHKYxXmeHg8aMMdvxxghx3ww5hWpg30HMf4Jzz3q6htJigwjcJI2QyjDechyKoNuy 3inDaHcZaJgjW+duBtfAooEx95HtODm8FmCk9u9YQuIxjm14tIhN0SXTzBY3Rw2nK0dTAJixiDS z4+ThpaN1+roPBA0atD6MZBFVO1aSyZZ2MctokdScM83d8fCdA4CojI+fAokeLbaebMC/Pk1alv kyLVaG4pAdz6pVkQmfSTg4A/m22+KN6ZvlnP8ZwJg3+pAHLIraRd4mthcyj4H0DXgQKfcggFnAV a X-Received: by 2002:a6b:310b:: with SMTP id j11mr9753808ioa.141.1547253418388; Fri, 11 Jan 2019 16:36:58 -0800 (PST) X-Received: by 2002:a6b:310b:: with SMTP id j11mr9753786ioa.141.1547253417329; Fri, 11 Jan 2019 16:36:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547253417; cv=none; d=google.com; s=arc-20160816; b=RsV5DqxUkKO0vCWnoimkU/wJXGSwulExv1P4hYKLl2qHCgjopked4jUXI0O4VRnw3s jSqljjo87333YzXfd4DGHjOLVKYHbgPVst/iLKMERelFTxDDaCU+esMzuJA0xlJwNxOV hJCqlfE36UOXpbX+2nT2qxH6mJYn8rcCdUK8It4ykqF3379TpVF3e/aO23lxzSBg76iY PxoC0FmBPatHFQ9SOzUJ1Vx+qdkACbgezSMwsDI2CybuZEQZILsJ6UDsnmHcLxZUr4at t4M0TfEijQaYIcdFBHCWSjFYJ40rERU8gJQi/1JO94lIyz9rkh1gIR7NRpAfbiILBvsA pw6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=G/V5x8DCIe/YBCFLV6oYQSvuz1De4Eq2CvrRknnvIFk=; b=0sWcN06/ITyiAU8A725J7jHW+9PDurIBBHRnQtuONInQ4ZIqKtKU1VawvQDrFb/dkg S0VR4PtEg+kS1ieD8gGWPkbHNdvuxzmbP+CADhtQ2CoMI57gFwNVlxgrlC3wXS87lN4H b4HS9mFzvQX5XfilPpCz2qZ/sXXGO5RpdSym2WZpeDaEDmp1XdiUeIZQW2kBNyfuknYK iVVQt0hQSiwuEHM5qnAIG16lY9pznjnKctmSTf9BeB5Jkfic1VwQehT0hR2CWFfYjVSe 1M66Ud0ctCoD4TnJ+KLCme0YPRqgDhNhKUxcPqoVUfKCcX5IbeH7DzkGexhnXNFqo+/B fCpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@colorado.edu header.s=google header.b=eEYpg6ec; spf=pass (google.com: domain of blake.caldwell@colorado.edu designates 209.85.220.65 as permitted sender) smtp.mailfrom=blake.caldwell@colorado.edu; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=colorado.edu Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id d78sor5328741itc.28.2019.01.11.16.36.57 for (Google Transport Security); Fri, 11 Jan 2019 16:36:57 -0800 (PST) Received-SPF: pass (google.com: domain of blake.caldwell@colorado.edu designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@colorado.edu header.s=google header.b=eEYpg6ec; spf=pass (google.com: domain of blake.caldwell@colorado.edu designates 209.85.220.65 as permitted sender) smtp.mailfrom=blake.caldwell@colorado.edu; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=colorado.edu DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=colorado.edu; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=G/V5x8DCIe/YBCFLV6oYQSvuz1De4Eq2CvrRknnvIFk=; b=eEYpg6ecLHzn4Fk9wVXnNiDjNOP8o7qVjJ2vPO+s92QeNHcGEsP7ctDTM0Dg9jFuSP ON+BLI4WaiHKH1Z8TohhyzktuNCWeki31M+8dloLiI6B4O55rvrZbrkX9SKTwOUWlMCz 8B9T6Bgk/ljAmzDqIhk8wKwrHnJtWG2auBypL/Z8j7k7LIuXAhmDRXYEPvhOQyvT60R6 QESnlY54j53G9h9eCQrm7mt+z88yeXJZL3U1hu8R60qHG6nmDS6fhRX9subEV1VvRB+T qsZtj4LJ6ZjIMmYKoBQB5wStqPntTZ6QDTUTaqQaFvftYotjqRaH9qMUv1ylkmM7Gs6m bFFw== X-Google-Smtp-Source: ALg8bN720Yk+Gh2tfsHzOkPNX6UAMrZUZc1lnFaM+fEFH4mVvLFCukvvdb7wo+1imSwi45e/w1bfcA== X-Received: by 2002:a24:d1c4:: with SMTP id w187mr2600845itg.141.1547253416968; Fri, 11 Jan 2019 16:36:56 -0800 (PST) Received: from sos1.localdomain (ucb-np1-75.colorado.edu. [128.138.64.75]) by smtp.googlemail.com with ESMTPSA id o63sm1605971ita.8.2019.01.11.16.36.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 16:36:55 -0800 (PST) From: Blake Caldwell To: blake.caldwell@colorado.edu Cc: rppt@linux.vnet.ibm.com, xemul@virtuozzo.com, akpm@linux-foundation.org, mike.kravetz@oracle.com, kirill.shutemov@linux.intel.com, linux-mm@kvack.org, aarcange@redhat.com Subject: [PATCH 4/4] userfaultfd: change the direction for UFFDIO_REMAP to out Date: Sat, 12 Jan 2019 00:36:29 +0000 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Bogosity: Ham, tests=bogofilter, spamicity=0.000125, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Moving a page out of a userfaultfd registered region and into a userland anonymous vma is needed by the use case of uncooperatively limiting the resident size of the userfaultfd region. Reverse the direction of the original userfaultfd_remap() to the out direction. Now after memory has been removed, subsequent accesses will generate uffdio page fault events. Signed-off-by: Blake Caldwell --- Documentation/admin-guide/mm/userfaultfd.rst | 10 ++++++++++ fs/userfaultfd.c | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/mm/userfaultfd.rst b/Documentation/admin-guide/mm/userfaultfd.rst index 5048cf6..714af49 100644 --- a/Documentation/admin-guide/mm/userfaultfd.rst +++ b/Documentation/admin-guide/mm/userfaultfd.rst @@ -108,6 +108,16 @@ UFFDIO_COPY. They're atomic as in guaranteeing that nothing can see an half copied page since it'll keep userfaulting until the copy has finished. +To move pages out of a userfault registered region and into a user vma +the UFFDIO_REMAP ioctl can be used. This is only possible for the +"OUT" direction. For the "IN" direction, UFFDIO_COPY is preferred +since UFFDIO_REMAP requires a TLB flush on the source range at a +greater penalty than copying the page. With +UFFDIO_REGISTER_MODE_MISSING set, subsequent accesses to the same +region will generate a page fault event. This allows non-cooperative +removal of memory in a userfaultfd registered vma, effectively +limiting the amount of resident memory in such a region. + QEMU/KVM ======== diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index cf68cdb..8099da2 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1808,10 +1808,10 @@ static int userfaultfd_remap(struct userfaultfd_ctx *ctx, sizeof(uffdio_remap)-sizeof(__s64))) goto out; - ret = validate_range(ctx->mm, uffdio_remap.dst, uffdio_remap.len); + ret = validate_range(current->mm, uffdio_remap.dst, uffdio_remap.len); if (ret) goto out; - ret = validate_range(current->mm, uffdio_remap.src, uffdio_remap.len); + ret = validate_range(ctx->mm, uffdio_remap.src, uffdio_remap.len); if (ret) goto out; ret = -EINVAL; @@ -1819,7 +1819,7 @@ static int userfaultfd_remap(struct userfaultfd_ctx *ctx, UFFDIO_REMAP_MODE_DONTWAKE)) goto out; - ret = remap_pages(ctx->mm, current->mm, + ret = remap_pages(current->mm, ctx->mm, uffdio_remap.dst, uffdio_remap.src, uffdio_remap.len, uffdio_remap.mode); if (unlikely(put_user(ret, &user_uffdio_remap->remap)))