Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp805381ybl; Fri, 6 Dec 2019 06:33:03 -0800 (PST) X-Google-Smtp-Source: APXvYqw+YNcp8gik6Wv4FQ7Re8mETC4zUxeO6VB9aw2O4ZhIpLcX0XtMLL1uz7opfPKA8MN3P/SI X-Received: by 2002:aca:1a10:: with SMTP id a16mr6862827oia.9.1575642782910; Fri, 06 Dec 2019 06:33:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575642782; cv=none; d=google.com; s=arc-20160816; b=qXmpT+klFeDNP6ANc2MrF827SlGIDUNUeceLbVkt8UsL4ecl+hZHEB8NIdqix7AerT OmKzzDRK8kv9RJL5evn4yc5MMlFqE2/tCGZSCOPKPQR6AW2pOExs6Oy3Tv8W8jQKq3D3 QSIiijJa036M3ENiGMn1SYxcA6GTwSBcQb1QGdyz9Dc8108ze83Uha75b4/Vv7AcOWqI xa1O7y8/5R9meUmk+Agsiidbo549rujTNhAKW0IzOFWL88tQoIm/TDusicIlqP5ytk2C BRh1HEMDK+Ss4f9Ig/MMEsgglCmxYGDg/KmoEZma3ruryxlUK396e9UV3G9V3TdUmiTq ml1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:from:references:cc:to:subject; bh=8ZClJFkDqwz6MuzDPEIncUCAVjFV0hrBg8Rr/NFHn8I=; b=cZScGatyXFxUJOelzpC2MA8njy3S+KJFQuo7bPUlCqOFnsuHhRssU+4O8kEluduhec fUCiJi0on5X3SWDLgVm55xnw7F8b7rqQZ01pHrW/hs0HkVU2V1KNh2U9pOmLEQWkWcGv JnBohcoRZSYmNotfpbPRDyh0PITocGjJnIhGGD3ZzPUVW+N8zpH5kBpO1WMacf8HnZDL b8S+WSBHE7kAUFyLG12RxKTBaPspuwPVwAMgTtMUAotfvYGqin/7xsbZxK8lYxyGQc0+ QG83jL7Ff04vJ/dJipj1ZM3JIb8LXQk1cpmYwEh5ddhrFkxMMbMSpT+PO9+mqbxItRYX 1qew== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j204si6940269oif.253.2019.12.06.06.32.50; Fri, 06 Dec 2019 06:33:02 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726350AbfLFOcP (ORCPT + 99 others); Fri, 6 Dec 2019 09:32:15 -0500 Received: from mx2.suse.de ([195.135.220.15]:60550 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726262AbfLFOcP (ORCPT ); Fri, 6 Dec 2019 09:32:15 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5489EAF55; Fri, 6 Dec 2019 14:32:10 +0000 (UTC) Subject: Re: [PATCH STABLE 4.4 5/8] mm: prevent get_user_pages() from overflowing page refcount To: Ajay Kaher , "stable@vger.kernel.org" Cc: "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Linus Torvalds , Jann Horn , Matthew Wilcox , "stable@kernel.org" , Srivatsa Bhat , "srivatsa@csail.mit.edu" , Vasavi Sirnapalli , "Kirill A. Shutemov" References: <20191108093814.16032-1-vbabka@suse.cz> <20191108093814.16032-6-vbabka@suse.cz> <519D18AF-DD01-4107-96D2-D8E33058B2CB@vmware.com> <68445EC7-1814-48C4-B88C-9C1E00489418@vmware.com> From: Vlastimil Babka Autocrypt: addr=vbabka@suse.cz; prefer-encrypt=mutual; keydata= mQINBFZdmxYBEADsw/SiUSjB0dM+vSh95UkgcHjzEVBlby/Fg+g42O7LAEkCYXi/vvq31JTB KxRWDHX0R2tgpFDXHnzZcQywawu8eSq0LxzxFNYMvtB7sV1pxYwej2qx9B75qW2plBs+7+YB 87tMFA+u+L4Z5xAzIimfLD5EKC56kJ1CsXlM8S/LHcmdD9Ctkn3trYDNnat0eoAcfPIP2OZ+ 9oe9IF/R28zmh0ifLXyJQQz5ofdj4bPf8ecEW0rhcqHfTD8k4yK0xxt3xW+6Exqp9n9bydiy tcSAw/TahjW6yrA+6JhSBv1v2tIm+itQc073zjSX8OFL51qQVzRFr7H2UQG33lw2QrvHRXqD Ot7ViKam7v0Ho9wEWiQOOZlHItOOXFphWb2yq3nzrKe45oWoSgkxKb97MVsQ+q2SYjJRBBH4 8qKhphADYxkIP6yut/eaj9ImvRUZZRi0DTc8xfnvHGTjKbJzC2xpFcY0DQbZzuwsIZ8OPJCc LM4S7mT25NE5kUTG/TKQCk922vRdGVMoLA7dIQrgXnRXtyT61sg8PG4wcfOnuWf8577aXP1x 6mzw3/jh3F+oSBHb/GcLC7mvWreJifUL2gEdssGfXhGWBo6zLS3qhgtwjay0Jl+kza1lo+Cv BB2T79D4WGdDuVa4eOrQ02TxqGN7G0Biz5ZLRSFzQSQwLn8fbwARAQABtCBWbGFzdGltaWwg QmFia2EgPHZiYWJrYUBzdXNlLmN6PokCVAQTAQoAPgIbAwULCQgHAwUVCgkICwUWAgMBAAIe AQIXgBYhBKlA1DSZLC6OmRA9UCJPp+fMgqZkBQJcbbyGBQkH8VTqAAoJECJPp+fMgqZkpGoP /1jhVihakxw1d67kFhPgjWrbzaeAYOJu7Oi79D8BL8Vr5dmNPygbpGpJaCHACWp+10KXj9yz fWABs01KMHnZsAIUytVsQv35DMMDzgwV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Bbv6jnF7zP Nzftr4l8RuJoywDIiJpdaNpSlXKpj/K6KrnyAI/joYc7 Message-ID: Date: Fri, 6 Dec 2019 15:32:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <68445EC7-1814-48C4-B88C-9C1E00489418@vmware.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/6/19 5:15 AM, Ajay Kaher wrote: > > > On 03/12/19, 6:28 PM, "Vlastimil Babka" wrote: >>>> >>>> [ 4.4 backport: there's get_page_foll(), so add try_get_page()-like checks >>>> in there, enabled by a new parameter, which is false where >>>> upstream patch doesn't replace get_page() with try_get_page() >>>> (the THP and hugetlb callers). >>> >>> Could we have try_get_page_foll(), as in: >>> https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fstable%2F1570581863-12090-3-git-send-email-akaher%40vmware.com%2F&data=02%7C01%7Cakaher%40vmware.com%7Cb6592f0fbec040aa045f08d777f06a9f%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C637109746821395444&sdata=cYBj3SvEikPbiHsVZj3zCys8t9ISLiHKzAlsSqiZRW8%3D&reserved=0 >>> >>> + Code will be in sync as we have try_get_page() >>> + No need to add extra argument to try_get_page() >>> + No need to modify the callers of try_get_page() > > Any reason for not using try_get_page_foll(). Ah, sorry, I missed that previously. It's certainly possible to do it that way, I just didn't care so strongly to rewrite the existing SLES patch. It's a stable backport for a rather old LTS, not a codebase for further development. >>>> In gup_pte_range(), we don't expect tail pages, so just check >>>> page ref count instead of try_get_compound_head() >>> >>> Technically it's fine. If you want to keep the code of stable versions in sync >>> with latest versions then this could be done in following ways (without any >>> modification in upstream patch for gup_pte_range()): >>> >>> Apply 7aef4172c7957d7e65fc172be4c99becaef855d4 before applying >>> 8fde12ca79aff9b5ba951fce1a2641901b8d8e64, as done here: >>> https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fstable%2F1570581863-12090-4-git-send-email-akaher%40vmware.com%2F&data=02%7C01%7Cakaher%40vmware.com%7Cb6592f0fbec040aa045f08d777f06a9f%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C637109746821395444&sdata=gTJMJ3Yx6G0ng46TQsBzCS2DowwP7YtIjluKJuqvN6o%3D&reserved=0 > >> Yup, I have considered that, and deliberately didn't add that commit >> 7aef4172c795 ("mm: handle PTE-mapped tail pages in gerneric fast gup >> implementaiton") as it's part of a large THP refcount rework. In 4.4 we >> don't expect to GUP tail pages so I wanted to keep it that way - >> minimally, the compound_head() operation is a unnecessary added cost, >> although it would also work. > >