From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9FEEC433B4 for ; Wed, 12 May 2021 02:25:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 51188616EA for ; Wed, 12 May 2021 02:25:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 51188616EA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C26B06B0036; Tue, 11 May 2021 22:25:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD7616B006E; Tue, 11 May 2021 22:25:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DB736B0070; Tue, 11 May 2021 22:25:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0150.hostedemail.com [216.40.44.150]) by kanga.kvack.org (Postfix) with ESMTP id 7E3066B0036 for ; Tue, 11 May 2021 22:25:48 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2E096A8D5 for ; Wed, 12 May 2021 02:25:48 +0000 (UTC) X-FDA: 78130988376.39.425106F Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by imf05.hostedemail.com (Postfix) with ESMTP id 4EF12E0011C5 for ; Wed, 12 May 2021 02:25:41 +0000 (UTC) Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14C2PAF2080885; Wed, 12 May 2021 02:25:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : references : message-id : date : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=uLORpbAPD2FI4iiF3WB7kjX8gM/ODXvLBZOynY3w+kM=; b=fE4bZVuBjiSKul5g/YMGgebb7B7uYSfNC7ge97EEgMz0EFjmblQxo+7vqK6wF+1N3/B4 BzKTvEmReaby1QcuulpQlxYrvLPZ+OpD7Vsc3uRMxNl1sbK7mFK36taMks2NbweYxyCK OaF0p6oWABwK9e3oLK48K5QvqWBnlA3pUbYcuVw9TeMiws2LyISxSs8+xTQvXvpZsodU K7BGVuzKYJr2y2x4ykBoUqJ8nOB/liUBd2kI3yC4vguxtJAPrngfnnq2VwNiKhTxi8fk OL6aJVvhyixthTBT7v7kYyvqmQ3ybwan31WyXVFq7hjyC8HTuEjC9Jvv2NJG2pM+DMTo jw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 38e285fvfx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 May 2021 02:25:44 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14C2JcDK032783; Wed, 12 May 2021 02:25:44 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2172.outbound.protection.outlook.com [104.47.73.172]) by userp3030.oracle.com with ESMTP id 38dfry7gee-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 May 2021 02:25:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NuHP7v2bHZYXKsWCf9PBlV3qjbFGXVGovsXyFUkNLVDj8lc5mjNOAyXqdV6qrijmtKtpkyKv1Y/+ZuAHypRq/RvaFyS0sA5Qtd9zxKukeS+hcf/kfUoOumwN3SAY2s/LQkCeQv5PwG4Pfnp2pJqtN2yPckpzCQdLW9sayNIzWz6hxaulkBA8vXNS3NkupvyRNiBroWjcQVPWmbr1psnEpKEwm0nlDaR3HYTEyfrzFBIQ5usMFGO2sF+gKCzC0RSllkBiyqqsp/91VNMeG99V+uL1uGwNzXD7Vw1ms9yLdrtsnxkkOBhr5JHo2lGUNlcasb72bd3FT73PofHRUGYVyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uLORpbAPD2FI4iiF3WB7kjX8gM/ODXvLBZOynY3w+kM=; b=MtVZoHFIDjQOKXkgiUUqclk2fO7jsb+6C0ahlQ/gr8Pe0gMTAXz9UAFFjCXfTcr0Bogznf/Vxd2oh0OoAektV4Py0BgU3BLbkle92eCSP2DO5aYT3vKe0XcMZPO349e4Iz7oFTzOxRaqHskDe2ndBEJGMWaIi++SwEiTteXAvVrA/cmmJ6UvK2CraElsyY9/3pyMpc9a26bTmEr7xhh4SC6kJ1FOroB+X8gdsyNlEF8PRuf2sZ16Fn04/akIeapyQTEfvehQGlQ2FMtW6YyP7Xo5z7wNsMceCb159itGKBXlPzRYq/ZP/G1PPMFF2hp3qHdMap+GAFvh6NidOmavdQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uLORpbAPD2FI4iiF3WB7kjX8gM/ODXvLBZOynY3w+kM=; b=KMcO0Fl0pm0wFwtP1ubbrn9ZBwZKwQ8F9GjGIqb/e9LmF30D1FGsyNGamw1C4krAFaAVrlstFvnWq77GZSaXapCrBJAItGofuyjLR52STgzJ9KG18xU4VOibk/801OD+lkdKiqV+yPMaTZqB9yXOVQP7vwOFWL68iMblbGj+3WI= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BY5PR10MB3986.namprd10.prod.outlook.com (2603:10b6:a03:1fb::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24; Wed, 12 May 2021 02:25:41 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::4407:2ff6:c0a:5d90]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::4407:2ff6:c0a:5d90%8]) with mapi id 15.20.4108.031; Wed, 12 May 2021 02:25:41 +0000 Subject: Re: resv_huge_page underflow with userfaultfd test From: Mike Kravetz To: Mina Almasry , Linux-MM , Axel Rasmussen , aarcange@redhat.com, peterx@redhat.com References: Message-ID: <096e28e2-5937-beb2-57f7-d112f9b54d97@oracle.com> Date: Tue, 11 May 2021 19:25:39 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: MWHPR1701CA0017.namprd17.prod.outlook.com (2603:10b6:301:14::27) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.2.112] (50.38.35.18) by MWHPR1701CA0017.namprd17.prod.outlook.com (2603:10b6:301:14::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Wed, 12 May 2021 02:25:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 69225fdf-c894-40b2-0369-08d914ed3d16 X-MS-TrafficTypeDiagnostic: BY5PR10MB3986: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9vSzNO4Z9A9Ks25gyJvE+q1nIpJPuyv11wL7U41gr+dLMpdWKIevChF1ikVmg71Vd3AGlNHM0XP4NqgRjFckgSW5cCU2WIxUlKNRPaP2TXbKrWMJN46vwCB+GIzcH52MedABSkz231WV6eXczGVVzh9SVVGxcvOQoLV4o7fgdIS87BRT4hggihNkpfFE3XETApki2L3K957+noQ3QmJQftJnS/7IE+F3tFbwa15AesTS9ZqpP5yEcdcB3CsDa0QSLYrf6dV9+x4ur1BzhUmcXVFq0dWs87I9wlvbvCwPMHxlwUOWEKsWtHbwkP5dG4OaArqSoVPL2pQCBobz+haAcvMhGc5gLs27cmgJO+zrCnYxzHENaZSZr+z8DjHB1rC9U6f+Jaqsli8C4HXrawRgM5wv6mKVFXSI+vsLRZcu9kJ7g/+vVQh4zhQ4xKiRy0cxlY7HOLnrnYKtfHSTO1KZWdWhS9TrwA9u/nr4UU0IScURsr+FX9FD82voS764tx2jWa3wlpBU9F+NpnW4jQ3P9lJf+CzpPGXAhlpIk8UE4Mrkmgk/Yv8LdZbGREzOlg36g68h14JFgV+CTh6+sXTCmxpn20Sb9CJvriHauDjKvV/Nl/iE9J0tUOjMp6T5FkMnnX+WXzRGrUAuJEfgSrOipEPLyyYnq13DxtCayADWDUxdR/PovkkNpjz7OFbvi99xHgrcYId/0gsfnAvvmn1g4bV4hhPxFVTON31OJnBjxP0aY/b4qcbkq5KtLTuDUWhw X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(396003)(136003)(346002)(366004)(376002)(39860400002)(6486002)(31686004)(31696002)(2616005)(86362001)(53546011)(8676002)(44832011)(26005)(83380400001)(5660300002)(956004)(38350700002)(316002)(38100700002)(36756003)(186003)(16526019)(16576012)(52116002)(66946007)(2906002)(110136005)(8936002)(66556008)(478600001)(66476007)(14583001)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?WTV1NmhEN20rYTMxZnBaQklxOTlxTjVBSXpEaUZiVGdxSGF3VitmMEs3ZUU3?= =?utf-8?B?a2lKc08zcHJoNmVXbHUrQXU3RDJtMGpjV0RZREZyYmp4aWlTWVZFSjVtME9v?= =?utf-8?B?a3p6RnBLdWRnZmorY3dON1Z4SU5hNjNzbGUvMEx0KzE5Uytadk9TdDFZS1J3?= =?utf-8?B?NkhlNG5EREgzZkEwS3BXRzNtaGh3QURLNlZGMmxJRzBkVG1vTmFVOUwyRmJ1?= =?utf-8?B?ajVtN2tCYnNQdGFKZWJYV2YzRE9JeFBzSmJGWTRzY3dHYXRvZnJmLzlYVU8x?= =?utf-8?B?dE5Dd2gwbEdwWW4zZTROU1plOW9OWDZ3TjlEZ2dTVnNQSlNkSWM3VTBwUE5Z?= =?utf-8?B?N2dJcGFHNFIxT1pvckJ5bWRDbkJUUlg4SmViV0YvNjhCMzV4QmhkL3FQd0JU?= =?utf-8?B?V0E2a3J5dlpETFhqR3JFUExqV0hSdy9yYkNhN3B5SFVUYU94T092WnNSVHQr?= =?utf-8?B?MDdxN2RDZmMwdVZwKzlNWk16a2xuZVpINE9PUDFSK3dOZWZrb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VVzl3MUMwQ3dKcHN4dHoyZy9kdnNXMm1VMEQw?= =?utf-8?B?b25JRWw4Mml0SFEzbUE3Q0wraVIyTk5JOWg2bVhZdXkyRmZQblU4VHpSZFNS?= =?utf-8?B?Njk4YTUrSHVQdjlhUkNINW5jMjNOV1BjUnpNS3NJUkw4TU1pOVFWWmlVQnlk?= =?utf-8?B?MHQzQ3Y0TVhUZ2NQSGIweWdxMzB0U0pLbzF5UFJqSTZnR3BTOEpVUForRXhB?= =?utf-8?B?ajNtNEVvMGxQRHBDbmNRSDVyeGJZY2x3cXp2Q2RZWEhwNlEra1dlaWcxNnJI?= =?utf-8?B?VUU5emNDbGpxZkt1aGFTTmtMZlhqdXNvS2JqWE9nNE1rMXpOZkljRmJ6aFFn?= =?utf-8?Q?RTglC8TBiTwUzD5SJ8kyC1Z8JdnSLEsp64tzhWr?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 69225fdf-c894-40b2-0369-08d914ed3d16 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2021 02:25:41.7140 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: hKODdR/LCkcYcJMikJxFG0AOYx5d+oG6JOvvGbuAw9dzZLULfVQcGKOxoxu5yrXXl5LLGELdl19LQxFXTydyAQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB3986 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9981 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 adultscore=0 bulkscore=0 mlxscore=0 suspectscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105120016 X-Proofpoint-GUID: rhhGPPDcupjEyDgNtls9WqylnUvEXVwR X-Proofpoint-ORIG-GUID: rhhGPPDcupjEyDgNtls9WqylnUvEXVwR X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9981 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 clxscore=1015 impostorscore=0 phishscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105120016 X-Rspamd-Queue-Id: 4EF12E0011C5 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2020-01-29 header.b=fE4bZVuB; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=KMcO0Fl0; spf=none (imf05.hostedemail.com: domain of mike.kravetz@oracle.com has no SPF policy when checking 156.151.31.86) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-Rspamd-Server: rspam04 X-Stat-Signature: rniczntx3m5dwseccwr88ia1nf671gfw Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf05; identity=mailfrom; envelope-from=""; helo=userp2130.oracle.com; client-ip=156.151.31.86 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620786341-916175 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: On 5/10/21 5:33 PM, Mike Kravetz wrote: > On 5/7/21 2:21 PM, Mina Almasry wrote: >> I ran into a bug that I'm not sure how to solve so I'm wondering if >> anyone has suggestions on what the issue could be and how to >> investigate. I added the WARN_ON_ONCE() here to catch instances of >> resv_huge_pages underflowing: >> > > I am fairly confident the issue is with hugetlb_mcopy_atomic_pte. It > does not detect/handle the case where a page cache page already exists > when in MCOPY_ATOMIC_NORMAL mode. If you add a printk/warning after the > failure of huge_add_to_page_cache, these will generally correspond to > the underflow. From a reservation POV, if the page exists in the cache > the reservation was already consumed. The call to alloc_huge_page will > 'consume' another reservation which can lead to the underflow. As you > noted, this underflow gets cleaned up in the error path. However, we > should prevent it from happening as we do not want anyone making > decisions on that underflow value. > > hugetlb_mcopy_atomic_pte should check for a page in the cache and if it > exists use it in MCOPY_ATOMIC_NORMAL. This code is quite tricky and my > first simple attempt at this did not work. I am happy to continue > working on this. However, if you or anyone else want to jump in and fix > feel free. I looked at this a bit more today and am not exactly sure of the expected behavior. The situation is: - UFFDIO_COPY is called for hugetlb mapping - the dest address is in a shared mapping - there is a page in the cache associated with the address in the shared mapping Currently, the code will fail when trying to update the page cache as the entry already exists. The shm code appears to do the same. Quick question. Is this the expected behavior? Or, would you expect the UFFDIO_COPY to update the page in the page cache, and then resolve the fault/update the pte? -- Mike Kravetz