From patchwork Mon Jul 2 07:50:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Borntraeger X-Patchwork-Id: 10500617 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4513560532 for ; Mon, 2 Jul 2018 07:51:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38DC9286EB for ; Mon, 2 Jul 2018 07:51:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C964287AC; Mon, 2 Jul 2018 07:51:03 +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=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable 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 BFCEA286EB for ; Mon, 2 Jul 2018 07:51:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A47EE6B0003; Mon, 2 Jul 2018 03:51:01 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9F6A16B0005; Mon, 2 Jul 2018 03:51:01 -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 8E8636B0006; Mon, 2 Jul 2018 03:51:01 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 29FF66B0003 for ; Mon, 2 Jul 2018 03:51:01 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id w10-v6so5261433eds.7 for ; Mon, 02 Jul 2018 00:51:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:content-transfer-encoding:mime-version; bh=BM3TuM07URYxUCUNrh5n9UK+Mmc5NnR4nQn7iNQbp2M=; b=mkrsvKRVrA3TbL7E4cF05LMlqX7Vtrk0S+SqwZD61pDCdmpe9aPyCXjClIYL7e7o8S SOD4fuN+L0lkEiB42ugi6Nwgr2809lleKXdxKrmIloxjz5SjUIXpicioHqZpkbGJI828 wUQxRYk791kUBhXiSzIdOFFRt/JPdzOglCk4+cmqmF+QcVH97htlSEukfk/G62Yeq5Xp 1AU8qri+B4Bbh/Ijctib3ampS/sp4P87/F0FOEVMNhXktngqmQzNG9zoe6S/eyNo2Erk vt7+zvJX8XPiKMSQK/5epfIljgYdfrncj83xqZ2XcVRY6S1UXYQXpJGIhF1GDaF2sAL5 7QdA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of borntraeger@de.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=borntraeger@de.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com X-Gm-Message-State: APt69E2MsVMfGQ87eRP9IKgFuXP3Q2B5ivJIFtHeifSKumM9ykPn9eZA 1NYNlBeuFwAKKi/xfMs/VIFOQbKqPxCKyt0Iee0i29mAqRmMZvyiiNoL2NSF4cJ+cKj/611LMLy jPdPowb3YwxZyUkJV06dQ+sKrw6hP46t1nqBT0o1imBmN0ltYXLqU/FvWqjWQUHZv5Q== X-Received: by 2002:a50:940b:: with SMTP id p11-v6mr22737526eda.107.1530517860615; Mon, 02 Jul 2018 00:51:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfX9a53tW0FDDMmCLu6B9WFwAcNq+VZVPJyPonto4TR4sL0AEc5arRhh2jNLVGTXSIyj1Kw X-Received: by 2002:a50:940b:: with SMTP id p11-v6mr22737460eda.107.1530517859403; Mon, 02 Jul 2018 00:50:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530517859; cv=none; d=google.com; s=arc-20160816; b=F97Hp9G9opr2Vifx1mQb29BhJhvsyQcKSS25tCGjG7F4TeS7cxm4IsRWN67fhpCOqM ZNL/6KqiZ1+dSa6opb1/crQjUSIQIPR1ar/DZA9c4Lbyl8AymverDhzteghHK/QpVGDV KTZKCPmQaEiVn+3l/bbPncgI+65vEeODVhXwjOYaK7D+VrE/M6BoRLu2+uEKRnRZel0C VSKf1kW9I6S+PN94BABrAwWT3Bg1wMuiIjug14hl+CcREQlWjo18DG4aboyQfJwUWXl8 CvfyuNO361HfRZKuvmJBtd8JHIUqEslua4U2r1x8I2GhMIdEYgCD5TJAV6RxmI5F6fSi GVxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:content-transfer-encoding:message-id:date:subject:cc :to:from:arc-authentication-results; bh=BM3TuM07URYxUCUNrh5n9UK+Mmc5NnR4nQn7iNQbp2M=; b=zY0xo/aY8JWRBq7nZ3jXrFYXraQwLwrXySR2HAzJbFiQyMtfqQMPeVOdHHUS4mouDE 5M2oSctHuU6eXIez4Epz9BAugn27cxJ+1S0phlCzSNVqQhqgkygJr1pr9+hfWWJh8qI9 TNH9DbFmZi59dW22hNDqy8kcQ6fNN/i6mVheOV3kwT7PiSIfDdoC6/S4B4mqOJm+7V11 y3o67Fl7WsJgJtQpYtXzwZFvbUTqFKNQbij3aglepvRt7RiwW10PfjMdHLiZvrlBQ4x7 B0iLENalVUMQ63sNCFay75EGm4SUR5ubHArKATDxsfztHRfwe0hStA6Nbk3AU9LqUHnd Ni9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of borntraeger@de.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=borntraeger@de.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com. [148.163.156.1]) by mx.google.com with ESMTPS id o1-v6si9747341edd.161.2018.07.02.00.50.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Jul 2018 00:50:59 -0700 (PDT) Received-SPF: pass (google.com: domain of borntraeger@de.ibm.com designates 148.163.156.1 as permitted sender) client-ip=148.163.156.1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of borntraeger@de.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=borntraeger@de.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w627i7qK059421 for ; Mon, 2 Jul 2018 03:50:57 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2jy9vvbb7c-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 02 Jul 2018 03:50:57 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 2 Jul 2018 08:50:54 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 2 Jul 2018 08:50:51 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w627onmJ38338762 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 2 Jul 2018 07:50:50 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E5109AE04D; Mon, 2 Jul 2018 08:50:37 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D2D6EAE045; Mon, 2 Jul 2018 08:50:37 +0100 (BST) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 2 Jul 2018 08:50:37 +0100 (BST) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 25651) id 6F6A720F65E; Mon, 2 Jul 2018 09:50:49 +0200 (CEST) From: Christian Borntraeger To: linux-mm@kvack.org, linux-s390@vger.kernel.org, Andrew Morton Cc: kvm@vger.kernel.org, Janosch Frank , David Hildenbrand , Cornelia Huck , linux-kernel@vger.kernel.org, Christian Borntraeger , Martin Schwidefsky , Andrea Arcangeli , Mike Rapoport Subject: [PATCHi v2] mm: do not drop unused pages when userfaultd is running Date: Mon, 2 Jul 2018 09:50:49 +0200 X-Mailer: git-send-email 2.17.0 X-TM-AS-GCONF: 00 x-cbid: 18070207-0012-0000-0000-00000285BB52 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18070207-0013-0000-0000-000020B730F1 Message-Id: <20180702075049.9157-1-borntraeger@de.ibm.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-02_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807020091 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: X-Virus-Scanned: ClamAV using ClamSMTP KVM guests on s390 can notify the host of unused pages. This can result in pte_unused callbacks to be true for KVM guest memory. If a page is unused (checked with pte_unused) we might drop this page instead of paging it. This can have side-effects on userfaultd, when the page in question was already migrated: The next access of that page will trigger a fault and a user fault instead of faulting in a new and empty zero page. As QEMU does not expect a userfault on an already migrated page this migration will fail. The most straightforward solution is to ignore the pte_unused hint if a userfault context is active for this VMA. Cc: Martin Schwidefsky Cc: Andrea Arcangeli Cc: Mike Rapoport Signed-off-by: Christian Borntraeger --- rfc->v2: use userfaultfd_armed mm/rmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/rmap.c b/mm/rmap.c index 6db729dc4c50..e8fa564676b6 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -64,6 +64,7 @@ #include #include #include +#include #include @@ -1481,7 +1482,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, set_pte_at(mm, address, pvmw.pte, pteval); } - } else if (pte_unused(pteval)) { + } else if (pte_unused(pteval) && !userfaultfd_armed(vma)) { /* * The guest indicated that the page content is of no * interest anymore. Simply discard the pte, vmscan