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=-5.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 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 5061FC43461 for ; Wed, 9 Sep 2020 14:51:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DDDCC2068D for ; Wed, 9 Sep 2020 14:51:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="XbQz4n9i" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726714AbgIIOuq (ORCPT ); Wed, 9 Sep 2020 10:50:46 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:47550 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729935AbgIIMbT (ORCPT ); Wed, 9 Sep 2020 08:31:19 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 089CJwer171227; Wed, 9 Sep 2020 08:29:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=GkaEv/0DUgjoFJ/sLWVerb24X+/pHjQgNqP/DNe1tXI=; b=XbQz4n9iTHtJDGQO9CZAgLFI2HTH0DExHrpy9r8Jb6UgN/j9t+yJW4DDEJ/r6mXI2D1e kEueEF6svz/bwwdJsy4ZKnHZmJiGpPZeQ2ru7yXD1mb1H3zWTzlGZA1e1M0hHMGQpwti 1OaYI6tidGwSMZ6jHjA2ujxFfweEL++pxbQmD88za0Sd+bgLMk9cweQCaPZVFHV35cDX YuuiNfDVXOOefxWa8DlE744vBqJTgFub2JvXbc4IqpnQzeu010RHZNYF+vuCC+9BalTI VKOHs8iCEkMfwoe3+X4Unbc8lgOi0i/jim59CEBNL0QrsBBm0haWZaGWerQhf2XpTpM+ Mg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 33exyar9ak-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 08:29:15 -0400 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 089CKbKB173414; Wed, 9 Sep 2020 08:29:14 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 33exyar97k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 08:29:14 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 089CMkts028029; Wed, 9 Sep 2020 12:29:10 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 33c2a8ch08-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 12:29:10 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 089CT8mO22217190 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 9 Sep 2020 12:29:08 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD7B64204F; Wed, 9 Sep 2020 12:29:06 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7957C42045; Wed, 9 Sep 2020 12:29:05 +0000 (GMT) Received: from thinkpad (unknown [9.171.79.102]) by d06av24.portsmouth.uk.ibm.com (Postfix) with SMTP; Wed, 9 Sep 2020 12:29:05 +0000 (GMT) Date: Wed, 9 Sep 2020 14:29:04 +0200 From: Gerald Schaefer To: Dave Hansen Cc: Jason Gunthorpe , John Hubbard , LKML , linux-mm , linux-arch , Andrew Morton , Linus Torvalds , Russell King , Mike Rapoport , Catalin Marinas , Will Deacon , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Jeff Dike , Richard Weinberger , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Arnd Bergmann , Andrey Ryabinin , linux-x86 , linux-arm , linux-power , linux-sparc , linux-um , linux-s390 , Alexander Gordeev , Vasily Gorbik , Heiko Carstens , Christian Borntraeger , Claudio Imbrenda Subject: Re: [RFC PATCH v2 1/3] mm/gup: fix gup_fast with dynamic page table folding Message-ID: <20200909142904.00b72921@thinkpad> In-Reply-To: <0dbc6ec8-45ea-0853-4856-2bc1e661a5a5@intel.com> References: <20200907180058.64880-1-gerald.schaefer@linux.ibm.com> <20200907180058.64880-2-gerald.schaefer@linux.ibm.com> <0dbc6ec8-45ea-0853-4856-2bc1e661a5a5@intel.com> X-Mailer: Claws Mail 3.17.6 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-09-09_06:2020-09-09,2020-09-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 malwarescore=0 spamscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 lowpriorityscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009090103 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 8 Sep 2020 07:30:50 -0700 Dave Hansen wrote: > On 9/7/20 11:00 AM, Gerald Schaefer wrote: > > Commit 1a42010cdc26 ("s390/mm: convert to the generic get_user_pages_fast > > code") introduced a subtle but severe bug on s390 with gup_fast, due to > > dynamic page table folding. > > Would it be fair to say that the "fake" page table entries s390 > allocates on the stack are what's causing the trouble here? That might > be a nice thing to open up with here. "Dynamic page table folding" > really means nothing to me. Sorry, I guess my previous reply does not really explain "what the heck is dynamic page table folding?". On s390, we can have different number of page table levels for different processes / mms. We always start with 3 levels, and update dynamically on process demand to 4 or 5 levels, hence the dynamic folding. Still, the PxD_SIZE/SHIFT is defined statically, so that e.g. pXd_addr_end() will not reflect this dynamic behavior. For the various pagetable walkers using pXd_addr_end() (w/o READ_ONCE logic) this is no problem. With static folding, iteration over the folded levels will always happen at pgd level (top-level folding). For s390, we stay at the respective level and iterate there (dynamic middle-level folding), only return to pgd level if there really were 5 levels. This only works well as long there are real pagetable pointers involved, that can also be used for iteration. For gup_fast, or any other future pagetable walkers using the READ_ONCE logic w/o lock, that is not true. There are pointers involved to local pXd values on the stack, because of the READ_ONCE logic, and our middle-level iteration will suddenly iterate over such stack pointers instead of pagetable pointers. This will be addressed by making the pXd_addr_end() dynamic, for which we need to see the pXd value in order to determine its level / type. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gerald Schaefer Date: Wed, 09 Sep 2020 12:29:04 +0000 Subject: Re: [RFC PATCH v2 1/3] mm/gup: fix gup_fast with dynamic page table folding Message-Id: <20200909142904.00b72921@thinkpad> List-Id: References: <20200907180058.64880-1-gerald.schaefer@linux.ibm.com> <20200907180058.64880-2-gerald.schaefer@linux.ibm.com> <0dbc6ec8-45ea-0853-4856-2bc1e661a5a5@intel.com> In-Reply-To: <0dbc6ec8-45ea-0853-4856-2bc1e661a5a5@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Dave Hansen Cc: Jason Gunthorpe , John Hubbard , LKML , linux-mm , linux-arch , Andrew Morton , Linus Torvalds , Russell King , Mike Rapoport , Catalin Marinas , Will Deacon , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Jeff Dike , Richard Weinberger , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Arnd Bergmann , Andrey Ryabinin , linux-x86 , linux-arm , linux-power , linux-sparc , linux-um , linux-s390 , Alexander Gordeev , Vasily Gorbik , Heiko Carstens , Christian Borntraeger , Claudio Imbrenda On Tue, 8 Sep 2020 07:30:50 -0700 Dave Hansen wrote: > On 9/7/20 11:00 AM, Gerald Schaefer wrote: > > Commit 1a42010cdc26 ("s390/mm: convert to the generic get_user_pages_fast > > code") introduced a subtle but severe bug on s390 with gup_fast, due to > > dynamic page table folding. > > Would it be fair to say that the "fake" page table entries s390 > allocates on the stack are what's causing the trouble here? That might > be a nice thing to open up with here. "Dynamic page table folding" > really means nothing to me. Sorry, I guess my previous reply does not really explain "what the heck is dynamic page table folding?". On s390, we can have different number of page table levels for different processes / mms. We always start with 3 levels, and update dynamically on process demand to 4 or 5 levels, hence the dynamic folding. Still, the PxD_SIZE/SHIFT is defined statically, so that e.g. pXd_addr_end() will not reflect this dynamic behavior. For the various pagetable walkers using pXd_addr_end() (w/o READ_ONCE logic) this is no problem. With static folding, iteration over the folded levels will always happen at pgd level (top-level folding). For s390, we stay at the respective level and iterate there (dynamic middle-level folding), only return to pgd level if there really were 5 levels. This only works well as long there are real pagetable pointers involved, that can also be used for iteration. For gup_fast, or any other future pagetable walkers using the READ_ONCE logic w/o lock, that is not true. There are pointers involved to local pXd values on the stack, because of the READ_ONCE logic, and our middle-level iteration will suddenly iterate over such stack pointers instead of pagetable pointers. This will be addressed by making the pXd_addr_end() dynamic, for which we need to see the pXd value in order to determine its level / type. 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=-5.0 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 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 5BD70C43461 for ; Wed, 9 Sep 2020 12:32:28 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6302021D81 for ; Wed, 9 Sep 2020 12:32:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="XbQz4n9i" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6302021D81 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4BmhHD1568zDqVr for ; Wed, 9 Sep 2020 22:32:24 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=gerald.schaefer@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=XbQz4n9i; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4BmhDG45fSzDqQw for ; Wed, 9 Sep 2020 22:29:50 +1000 (AEST) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 089CJwer171227; Wed, 9 Sep 2020 08:29:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=GkaEv/0DUgjoFJ/sLWVerb24X+/pHjQgNqP/DNe1tXI=; b=XbQz4n9iTHtJDGQO9CZAgLFI2HTH0DExHrpy9r8Jb6UgN/j9t+yJW4DDEJ/r6mXI2D1e kEueEF6svz/bwwdJsy4ZKnHZmJiGpPZeQ2ru7yXD1mb1H3zWTzlGZA1e1M0hHMGQpwti 1OaYI6tidGwSMZ6jHjA2ujxFfweEL++pxbQmD88za0Sd+bgLMk9cweQCaPZVFHV35cDX YuuiNfDVXOOefxWa8DlE744vBqJTgFub2JvXbc4IqpnQzeu010RHZNYF+vuCC+9BalTI VKOHs8iCEkMfwoe3+X4Unbc8lgOi0i/jim59CEBNL0QrsBBm0haWZaGWerQhf2XpTpM+ Mg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 33exyar9ak-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 08:29:15 -0400 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 089CKbKB173414; Wed, 9 Sep 2020 08:29:14 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 33exyar97k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 08:29:14 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 089CMkts028029; Wed, 9 Sep 2020 12:29:10 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 33c2a8ch08-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 12:29:10 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 089CT8mO22217190 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 9 Sep 2020 12:29:08 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD7B64204F; Wed, 9 Sep 2020 12:29:06 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7957C42045; Wed, 9 Sep 2020 12:29:05 +0000 (GMT) Received: from thinkpad (unknown [9.171.79.102]) by d06av24.portsmouth.uk.ibm.com (Postfix) with SMTP; Wed, 9 Sep 2020 12:29:05 +0000 (GMT) Date: Wed, 9 Sep 2020 14:29:04 +0200 From: Gerald Schaefer To: Dave Hansen Subject: Re: [RFC PATCH v2 1/3] mm/gup: fix gup_fast with dynamic page table folding Message-ID: <20200909142904.00b72921@thinkpad> In-Reply-To: <0dbc6ec8-45ea-0853-4856-2bc1e661a5a5@intel.com> References: <20200907180058.64880-1-gerald.schaefer@linux.ibm.com> <20200907180058.64880-2-gerald.schaefer@linux.ibm.com> <0dbc6ec8-45ea-0853-4856-2bc1e661a5a5@intel.com> X-Mailer: Claws Mail 3.17.6 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-09-09_06:2020-09-09, 2020-09-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 malwarescore=0 spamscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 lowpriorityscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009090103 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Zijlstra , Dave Hansen , linux-mm , Paul Mackerras , linux-sparc , Alexander Gordeev , Claudio Imbrenda , Will Deacon , linux-arch , linux-s390 , Vasily Gorbik , Christian Borntraeger , Richard Weinberger , linux-x86 , Russell King , Jason Gunthorpe , Ingo Molnar , Catalin Marinas , Andrey Ryabinin , Heiko Carstens , Arnd Bergmann , John Hubbard , Jeff Dike , linux-um , Borislav Petkov , Andy Lutomirski , Thomas Gleixner , linux-arm , linux-power , LKML , Andrew Morton , Linus Torvalds , Mike Rapoport Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Tue, 8 Sep 2020 07:30:50 -0700 Dave Hansen wrote: > On 9/7/20 11:00 AM, Gerald Schaefer wrote: > > Commit 1a42010cdc26 ("s390/mm: convert to the generic get_user_pages_fast > > code") introduced a subtle but severe bug on s390 with gup_fast, due to > > dynamic page table folding. > > Would it be fair to say that the "fake" page table entries s390 > allocates on the stack are what's causing the trouble here? That might > be a nice thing to open up with here. "Dynamic page table folding" > really means nothing to me. Sorry, I guess my previous reply does not really explain "what the heck is dynamic page table folding?". On s390, we can have different number of page table levels for different processes / mms. We always start with 3 levels, and update dynamically on process demand to 4 or 5 levels, hence the dynamic folding. Still, the PxD_SIZE/SHIFT is defined statically, so that e.g. pXd_addr_end() will not reflect this dynamic behavior. For the various pagetable walkers using pXd_addr_end() (w/o READ_ONCE logic) this is no problem. With static folding, iteration over the folded levels will always happen at pgd level (top-level folding). For s390, we stay at the respective level and iterate there (dynamic middle-level folding), only return to pgd level if there really were 5 levels. This only works well as long there are real pagetable pointers involved, that can also be used for iteration. For gup_fast, or any other future pagetable walkers using the READ_ONCE logic w/o lock, that is not true. There are pointers involved to local pXd values on the stack, because of the READ_ONCE logic, and our middle-level iteration will suddenly iterate over such stack pointers instead of pagetable pointers. This will be addressed by making the pXd_addr_end() dynamic, for which we need to see the pXd value in order to determine its level / type. 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=-5.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 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 6116BC43461 for ; Wed, 9 Sep 2020 12:31:10 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E016021D91 for ; Wed, 9 Sep 2020 12:31:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="sXel8UU4"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="XbQz4n9i" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E016021D91 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=E+j1YjWH3A8ALnLmHfpdM9Wm8iY79pHHpbCfctEA5iI=; b=sXel8UU4PjXMgIkuSfJX3dzFg 52lgnNFDQYVPYbq017Wl3KGXxmHmgG40hE2JLKxD1PeuaHs5VU5BXBwTJqjvUkkAekw/aUYKZnrLG fRT/nhxHG8FAtK7tGOzfX+cLZTy0TQvByEoPgpPDS8UDuOQxa5wQkvsF5mY5iTn6LRlqeq/yNZv0k w3bpnRuzEMDUNNY8oBR7lQaLU7GFHWVd2QdvF/ozcIshfqqhyrV24WLGB3f7mEk8/BstRLp7+eUrL BDLLV/n8icBffoodKXK6yrojNVEaW0waZKCmnoeJozkQa43dW7ZXBqGSonx16aH/4PzIAWCG9JlKH eJGZo0htQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFzEU-0004wr-97; Wed, 09 Sep 2020 12:29:50 +0000 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5] helo=mx0a-001b2d01.pphosted.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFzEQ-0004ve-U6; Wed, 09 Sep 2020 12:29:47 +0000 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 089CJwer171227; Wed, 9 Sep 2020 08:29:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=GkaEv/0DUgjoFJ/sLWVerb24X+/pHjQgNqP/DNe1tXI=; b=XbQz4n9iTHtJDGQO9CZAgLFI2HTH0DExHrpy9r8Jb6UgN/j9t+yJW4DDEJ/r6mXI2D1e kEueEF6svz/bwwdJsy4ZKnHZmJiGpPZeQ2ru7yXD1mb1H3zWTzlGZA1e1M0hHMGQpwti 1OaYI6tidGwSMZ6jHjA2ujxFfweEL++pxbQmD88za0Sd+bgLMk9cweQCaPZVFHV35cDX YuuiNfDVXOOefxWa8DlE744vBqJTgFub2JvXbc4IqpnQzeu010RHZNYF+vuCC+9BalTI VKOHs8iCEkMfwoe3+X4Unbc8lgOi0i/jim59CEBNL0QrsBBm0haWZaGWerQhf2XpTpM+ Mg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 33exyar9ak-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 08:29:15 -0400 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 089CKbKB173414; Wed, 9 Sep 2020 08:29:14 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 33exyar97k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 08:29:14 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 089CMkts028029; Wed, 9 Sep 2020 12:29:10 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 33c2a8ch08-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 12:29:10 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 089CT8mO22217190 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 9 Sep 2020 12:29:08 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD7B64204F; Wed, 9 Sep 2020 12:29:06 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7957C42045; Wed, 9 Sep 2020 12:29:05 +0000 (GMT) Received: from thinkpad (unknown [9.171.79.102]) by d06av24.portsmouth.uk.ibm.com (Postfix) with SMTP; Wed, 9 Sep 2020 12:29:05 +0000 (GMT) Date: Wed, 9 Sep 2020 14:29:04 +0200 From: Gerald Schaefer To: Dave Hansen Subject: Re: [RFC PATCH v2 1/3] mm/gup: fix gup_fast with dynamic page table folding Message-ID: <20200909142904.00b72921@thinkpad> In-Reply-To: <0dbc6ec8-45ea-0853-4856-2bc1e661a5a5@intel.com> References: <20200907180058.64880-1-gerald.schaefer@linux.ibm.com> <20200907180058.64880-2-gerald.schaefer@linux.ibm.com> <0dbc6ec8-45ea-0853-4856-2bc1e661a5a5@intel.com> X-Mailer: Claws Mail 3.17.6 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-09-09_06:2020-09-09, 2020-09-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 malwarescore=0 spamscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 lowpriorityscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009090103 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200909_082947_056178_1FD7B929 X-CRM114-Status: GOOD ( 27.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Zijlstra , Benjamin Herrenschmidt , Dave Hansen , linux-mm , Paul Mackerras , linux-sparc , Alexander Gordeev , Claudio Imbrenda , Will Deacon , linux-arch , linux-s390 , Vasily Gorbik , Christian Borntraeger , Richard Weinberger , linux-x86 , Russell King , Jason Gunthorpe , Ingo Molnar , Catalin Marinas , Andrey Ryabinin , Heiko Carstens , Arnd Bergmann , John Hubbard , Jeff Dike , linux-um , Borislav Petkov , Andy Lutomirski , Thomas Gleixner , linux-arm , linux-power , LKML , Michael Ellerman , Andrew Morton , Linus Torvalds , Mike Rapoport Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 8 Sep 2020 07:30:50 -0700 Dave Hansen wrote: > On 9/7/20 11:00 AM, Gerald Schaefer wrote: > > Commit 1a42010cdc26 ("s390/mm: convert to the generic get_user_pages_fast > > code") introduced a subtle but severe bug on s390 with gup_fast, due to > > dynamic page table folding. > > Would it be fair to say that the "fake" page table entries s390 > allocates on the stack are what's causing the trouble here? That might > be a nice thing to open up with here. "Dynamic page table folding" > really means nothing to me. Sorry, I guess my previous reply does not really explain "what the heck is dynamic page table folding?". On s390, we can have different number of page table levels for different processes / mms. We always start with 3 levels, and update dynamically on process demand to 4 or 5 levels, hence the dynamic folding. Still, the PxD_SIZE/SHIFT is defined statically, so that e.g. pXd_addr_end() will not reflect this dynamic behavior. For the various pagetable walkers using pXd_addr_end() (w/o READ_ONCE logic) this is no problem. With static folding, iteration over the folded levels will always happen at pgd level (top-level folding). For s390, we stay at the respective level and iterate there (dynamic middle-level folding), only return to pgd level if there really were 5 levels. This only works well as long there are real pagetable pointers involved, that can also be used for iteration. For gup_fast, or any other future pagetable walkers using the READ_ONCE logic w/o lock, that is not true. There are pointers involved to local pXd values on the stack, because of the READ_ONCE logic, and our middle-level iteration will suddenly iterate over such stack pointers instead of pagetable pointers. This will be addressed by making the pXd_addr_end() dynamic, for which we need to see the pXd value in order to determine its level / type. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Wed, 9 Sep 2020 14:29:04 +0200 From: Gerald Schaefer Subject: Re: [RFC PATCH v2 1/3] mm/gup: fix gup_fast with dynamic page table folding Message-ID: <20200909142904.00b72921@thinkpad> In-Reply-To: <0dbc6ec8-45ea-0853-4856-2bc1e661a5a5@intel.com> References: <20200907180058.64880-1-gerald.schaefer@linux.ibm.com> <20200907180058.64880-2-gerald.schaefer@linux.ibm.com> <0dbc6ec8-45ea-0853-4856-2bc1e661a5a5@intel.com> MIME-Version: 1.0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-um" Errors-To: linux-um-bounces+geert=linux-m68k.org@lists.infradead.org To: Dave Hansen Cc: Peter Zijlstra , Benjamin Herrenschmidt , Dave Hansen , linux-mm , Paul Mackerras , linux-sparc , Alexander Gordeev , Claudio Imbrenda , Will Deacon , linux-arch , linux-s390 , Vasily Gorbik , Christian Borntraeger , Richard Weinberger , linux-x86 , Russell King , Jason Gunthorpe , Ingo Molnar , Catalin Marinas , Andrey Ryabinin , Heiko Carstens , Arnd Bergmann , John Hubbard , Jeff Dike , linux-um , Borislav Petkov , Andy Lutomirski , Thomas Gleixner , linux-arm , linux-power , LKML , Michael Ellerman , Andrew Morton , Linus Torvalds , Mike Rapoport On Tue, 8 Sep 2020 07:30:50 -0700 Dave Hansen wrote: > On 9/7/20 11:00 AM, Gerald Schaefer wrote: > > Commit 1a42010cdc26 ("s390/mm: convert to the generic get_user_pages_fast > > code") introduced a subtle but severe bug on s390 with gup_fast, due to > > dynamic page table folding. > > Would it be fair to say that the "fake" page table entries s390 > allocates on the stack are what's causing the trouble here? That might > be a nice thing to open up with here. "Dynamic page table folding" > really means nothing to me. Sorry, I guess my previous reply does not really explain "what the heck is dynamic page table folding?". On s390, we can have different number of page table levels for different processes / mms. We always start with 3 levels, and update dynamically on process demand to 4 or 5 levels, hence the dynamic folding. Still, the PxD_SIZE/SHIFT is defined statically, so that e.g. pXd_addr_end() will not reflect this dynamic behavior. For the various pagetable walkers using pXd_addr_end() (w/o READ_ONCE logic) this is no problem. With static folding, iteration over the folded levels will always happen at pgd level (top-level folding). For s390, we stay at the respective level and iterate there (dynamic middle-level folding), only return to pgd level if there really were 5 levels. This only works well as long there are real pagetable pointers involved, that can also be used for iteration. For gup_fast, or any other future pagetable walkers using the READ_ONCE logic w/o lock, that is not true. There are pointers involved to local pXd values on the stack, because of the READ_ONCE logic, and our middle-level iteration will suddenly iterate over such stack pointers instead of pagetable pointers. This will be addressed by making the pXd_addr_end() dynamic, for which we need to see the pXd value in order to determine its level / type. _______________________________________________ linux-um mailing list linux-um@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-um