From patchwork Tue Jul 3 17:18:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Borntraeger X-Patchwork-Id: 10504807 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 93F7560325 for ; Tue, 3 Jul 2018 17:19:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7761928D6D for ; Tue, 3 Jul 2018 17:19:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A81628D7F; Tue, 3 Jul 2018 17:19:09 +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 0682B28D77 for ; Tue, 3 Jul 2018 17:19:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0707B6B026E; Tue, 3 Jul 2018 13:19:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 01D606B026F; Tue, 3 Jul 2018 13:19:07 -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 E29C66B0270; Tue, 3 Jul 2018 13:19:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id 82A406B026E for ; Tue, 3 Jul 2018 13:19:07 -0400 (EDT) Received: by mail-ed1-f70.google.com with SMTP id k5-v6so1197555edq.9 for ; Tue, 03 Jul 2018 10:19:07 -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=U9qkDBrKpb7ze4h3FwIKaAVt3MY/pze1lJ1nAWErlho=; b=YI51sb2depPJA4rQkLUu9VLt1s6bYrvkjldc4nMh8BIXzDTLg2C3smiuoKqqiQrgv9 DjjX9t6xZaCX4mvXGLkEiktlK3zcd036d7JbVZXKz8OelFNu3m0kSyrV44WGEDz2961R ICf3i0jHq4MqEGIOjt1onsYkzyYC+xvIndATsLGhDGmsN9xVvRCtDs6Irz7mYv/w2qNK dazZxrOkRlqBUflgn5a+/+w4Zs1WyiQhpW2AA1R5mf0Xi8pxoeS4zYQXhzZXzApYyTke 6cAxC6ZjmUh5/C4uKxC6EgJN1AX1Hf29PbPKrq/4FH/ebJkEC6WH4VXO14zCMMadveMu LW8Q== 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: APt69E2rj8CC6Gokw0iRmvr6jPZz8K7R6KzDeKh/Yiex+9vViED+6O/u d6JXmrRq6JhwTvW/fzN2AuCzAOMSjH159CMsQK66BKZie5wUha4u00I2DcOI7chElllbSv1NqW3 AasBOXRhQfAMs97GpZH+SivetQDhKveq4tF3MkxCQIGFgC9VTvlH2AvVrofuBiZUmeQ== X-Received: by 2002:a50:9182:: with SMTP id g2-v6mr29831861eda.24.1530638347082; Tue, 03 Jul 2018 10:19:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeoxQYfG8LkOllRcTvIuk2ZxEyD1uUvrTTBT4ZVhC3IyA9Xc35R8HIJUnICfoVWAVkQNsrg X-Received: by 2002:a50:9182:: with SMTP id g2-v6mr29831801eda.24.1530638346113; Tue, 03 Jul 2018 10:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530638346; cv=none; d=google.com; s=arc-20160816; b=cyjwgaBUd9wGLevsWVK4IEWteCbq7bvVDjxmlSMwatJJYf58uIc0HCyJ5g890Rm52v 981w+zHFmXGiHkTNfJxbhna6LC4Y1RZcv5BQm+c7ksbmU4dehDRUFa5ezaovSsZh9l/B 6jWlrZ9+v2ZoCiE3dOlYsaBMDKnO2k0tdU4t0HBLVy6XwgUvMfKVWcsomvotIjNA3RC+ 8xX9bTCnsU2RtWn1na+LSwi6Po5zcNXIQIb7uUuHZiFOTzoSY1PQnO9NHlQPRt5z5Eiz Ik57quZxh31XqRqIl0M7eCT2aj5eAx0K/+3obDnXg2z97WGetLRxres87n8zM91wY2uR glhg== 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=U9qkDBrKpb7ze4h3FwIKaAVt3MY/pze1lJ1nAWErlho=; b=FIMYJcpcil2q45aP/OvaNKP5EndAqnFn12kPHKgu7rqh7Z/G76ltpqcckjX8Xx4mEe XmGUPALxgB62RWfHsKl9kM+Ei8tg3qqafJ91uSidEAP9Ja94PJTIEX5f4qJETEcWGuq/ yVDzdEME4vzHgJOv8IvRbN2uV9+5MqDEHmRmZBGEpc8L1j/OzmWSuOm9GC1rmXD4TmMn cGTXy/GqmAHe2XDbmawMek/s/gHR5tJ724PbMx5vsyqPrMWed++YXQqelqbG01ClSKXO sh9DxlLkaLEVkx4gLpa3QC7IsB+mOdaRxb7nOZ2/SXibbmHoCi+UlApDkqtBNN9zHjHr xMRg== 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 x11-v6si1206435edi.316.2018.07.03.10.19.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jul 2018 10:19:06 -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 (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w63HImX4014797 for ; Tue, 3 Jul 2018 13:19:04 -0400 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2k0a7eskbj-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 03 Jul 2018 13:19:03 -0400 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 3 Jul 2018 18:19:00 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 3 Jul 2018 18:18:57 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w63HItJY40173806 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 3 Jul 2018 17:18:55 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 197174C050; Tue, 3 Jul 2018 20:19:21 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 058794C046; Tue, 3 Jul 2018 20:19:21 +0100 (BST) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Tue, 3 Jul 2018 20:19:20 +0100 (BST) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 25651) id 2EFD420F65E; Tue, 3 Jul 2018 19:18:55 +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: [PATCH v3] mm: do not drop unused pages when userfaultd is running Date: Tue, 3 Jul 2018 19:18:54 +0200 X-Mailer: git-send-email 2.17.0 X-TM-AS-GCONF: 00 x-cbid: 18070317-4275-0000-0000-00000294C992 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18070317-4276-0000-0000-0000379C4966 Message-Id: <20180703171854.63981-1-borntraeger@de.ibm.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-03_07:, , 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-1807030197 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 Cc: stable@vger.kernel.org Signed-off-by: Christian Borntraeger --- v2->v3 : improve comment RFC->v2: user userfaultfd_active mm/rmap.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/rmap.c b/mm/rmap.c index 6db729dc4c50..eb477809a5c0 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -64,6 +64,7 @@ #include #include #include +#include #include @@ -1481,11 +1482,16 @@ 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 * will take care of the rest. + * A future reference will then fault in a new zero + * page. When userfaultfd is active, we must not drop + * this page though, as its main user (postcopy + * migration) will not expect userfaults on already + * copied pages. */ dec_mm_counter(mm, mm_counter(page)); /* We have to invalidate as we cleared the pte */