Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp7754851imm; Thu, 28 Jun 2018 08:51:50 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK6aNH6lgpWw5AWPGqFtBWakCan9+fvBbidHXoRy3PEuIpNx5fyQnA1HzefnrDS+IDCQnG4 X-Received: by 2002:a17:902:bf43:: with SMTP id u3-v6mr11004533pls.322.1530201110715; Thu, 28 Jun 2018 08:51:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530201110; cv=none; d=google.com; s=arc-20160816; b=wuHSn4J1t6tNl8bmiw78iah/nQ8tHIpG+BmjRXvSf9ji1skW4FsNZ7dw8HlveFdb17 2zFaIfnzlCOk4VgSYKichrAN9HWen1KiO/Tq9MkJY4nf215vXhGlRAIy20JxHKj2cvda XgSkRFPOKHxu+GVqCVmzqw+n+bl2vPB1SBkr96L3fGzJ5quIDnWrwI1ka0j/lTr377w+ cLmdrouP1fqiE1tR9XIWCjehtaNNXoknsJH1N/5LQ8c7k2L/bNzbKcq1c4M8B/+SQIKQ GYk6D8T2FOknN7NO6cxak59X8Gp6oRviwyGx6Rn1f9DgIK7QIIARnzJ4cymZsx/8V5ey kDyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:arc-authentication-results; bh=hZR25obLRGvSyz8VKTy0Xd7XpQTLBaC+reFBH9uUmiM=; b=xE6BE6zo9zBvzs7UPya7IXr+jzYpP9oraMzIFHNSIFVa3m6iLBawfz9mLPfFxqmHN4 nQvR+IAb7VCXxnKkzbwQ3MJGxKfCV95WDEfxa3bavWhlkV3vusLQPlxtRcpqUwKcE9JI pRcEML6m5do11gXPL9P4LHWxxn11HUOdiKv8mSJiiK1tvfpfE1/9oOEZ+1um0iYDm4l3 aRTzQZGiOGO8FvLSUVOeFD5nMpJI4fmgbijMRPyzhuS9tWXgFkGT3i1aB2Q5rXRhwH3R N3fvKIfWMSfKRw2JDbk/bplOlBcAZa06xIhCQhbEmz7hPYFq7frAIpF0Rc81+6Bji4WH MnmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k11-v6si5920661pgo.43.2018.06.28.08.51.35; Thu, 28 Jun 2018 08:51:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965097AbeF1Mj0 (ORCPT + 99 others); Thu, 28 Jun 2018 08:39:26 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:42982 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934394AbeF1MjX (ORCPT ); Thu, 28 Jun 2018 08:39:23 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w5SCdFOU088964 for ; Thu, 28 Jun 2018 08:39:23 -0400 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 2jvwqt67nt-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 28 Jun 2018 08:39:22 -0400 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 28 Jun 2018 13:39:21 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp02.uk.ibm.com (192.168.101.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 28 Jun 2018 13:39:18 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w5SCdHVx34406506 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 28 Jun 2018 12:39:17 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E4D7EA4059; Thu, 28 Jun 2018 13:39:06 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D3221A4057; Thu, 28 Jun 2018 13:39:06 +0100 (BST) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 28 Jun 2018 13:39:06 +0100 (BST) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 25651) id F294620F660; Thu, 28 Jun 2018 14:39:16 +0200 (CEST) From: Christian Borntraeger To: linux-mm@kvack.org, linux-s390@vger.kernel.org Cc: kvm@vger.kernel.org, Janosch Frank , David Hildenbrand , Cornelia Huck , linux-kernel@vger.kernel.org, Christian Borntraeger , Martin Schwidefsky , Andrea Arcangeli Subject: [PATCH/RFC] mm: do not drop unused pages when userfaultd is running Date: Thu, 28 Jun 2018 14:39:16 +0200 X-Mailer: git-send-email 2.17.0 X-TM-AS-GCONF: 00 x-cbid: 18062812-0008-0000-0000-0000024CD855 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18062812-0009-0000-0000-000021B35228 Message-Id: <20180628123916.96106-1-borntraeger@de.ibm.com> Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7BIT MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-06-28_06:,, 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-1806280145 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: stable@vger.kernel.org Signed-off-by: Christian Borntraeger --- mm/rmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/rmap.c b/mm/rmap.c index 6db729dc4c50..3f3a72aa99f2 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1481,7 +1481,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) && !vma->vm_userfaultfd_ctx.ctx) { /* * The guest indicated that the page content is of no * interest anymore. Simply discard the pte, vmscan -- 2.17.0