Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp1376120rwl; Thu, 5 Jan 2023 12:39:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXu7mh7i8yMAr/RXFElOIsMjIWdmKz6ZPvD4N6yE+6iWVjovp951lXbeikRYLPR6Hm39S66T X-Received: by 2002:a17:907:7094:b0:844:1d1d:1fa with SMTP id yj20-20020a170907709400b008441d1d01famr47954619ejb.23.1672951179904; Thu, 05 Jan 2023 12:39:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1672951179; cv=pass; d=google.com; s=arc-20160816; b=B4/LB5CqJMBMwZaIIBlahPEv/Fiub3ZKtfO8RMG8OI92xgtQdzkWrPm0KPiEx28cfE zFkZ/GhtuaOvKeLfKF8oiUMJyuLRPaEd/WGeMXBeplk50GQ37cGhgPVfoLFHpTO+Acgs yZd+gFwrdiTM1FaG685Kem7rEwSFMn8aZgJcYEjMGV/+rt8AXTjse8FitpOX5uPEMQyD gL1Pqy12kRHsgrVMMzHeq+IIqFiusl30rWQD7LxOcb7WCx4SDmOi/jqoWAKWD71pDbU4 GhIjTf7dg6WhDVmc+DnZf0BjxGPqNT4oyKfUAAlUU62n1spMz2hSha4STistl8JhS2XZ uhUw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to:content-disposition :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UCPTyArg7F67jvZzI6slvdkHUhycB7H9egy0tcCHuoQ=; b=htMqSLjZb9FwSC8OJuMwTtR9q+lNh4ubd1hfG7pUS9tlAU0qg+CHQvv86QsRp7iG5y sD1y8RQeclVyAmkup2fQt8eOUbxduFpbGJu+XF9sEMNAOV//Ld9tbzBVNFWapa/T/Av/ nuO2naaczZZa/6vJmP9QP39fRv1BxvRHZpOhuRUGvo68K/HXT1YghINMxW8+zdbw5Dtr 6WyhZYuy6xXxV1+mY7+dpJ4rkguRsyOVzjLzUEnUQ2CnU9rxUnWHcMIhvTTIsgDTtPOk Ys1eQcYlQiYZWj8rcBIkWsG534alZEQc6tux6hiDhIaJGlix4UnSdKMh38ATWpRH4tyg 7zyg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=nNZCuT66; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i17-20020a1709064fd100b007c13387a548si36039734ejw.26.2023.01.05.12.39.26; Thu, 05 Jan 2023 12:39:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=nNZCuT66; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235062AbjAEUXv (ORCPT + 55 others); Thu, 5 Jan 2023 15:23:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235248AbjAEUXr (ORCPT ); Thu, 5 Jan 2023 15:23:47 -0500 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2089.outbound.protection.outlook.com [40.107.102.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A36536338F; Thu, 5 Jan 2023 12:23:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hV0E5fVOWbJ7HW9JIrnAqORao5WeZzpnRzFV27DmvtlDKSQDFMZlKYF32yB4HeVQaZ+n49PSE+5cLnuQ0iTiXWBz9/Zeqx4sr30OquVGovzkhQHYp++vHLgyTd0SmNPrkc3fIlVmTB+bog18MLERkNgguGk0hG1aCIOTmWEr8Vi4Bjqqg51alG2uoBD0ge7XMx95HToWorbPoVyhpUJ1XNfJR+zSwx0OH1QwVHDmbljDZAgDGU7oyust3mrjj01wd6/dvC/yGry/EJB9s5gVs5FuU6rxOuVWNfBPhEzBpJeSsS7zPV9ykhq0OpwIEKc9oSlF1G2S/0dMYKECm5JL4Q== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UCPTyArg7F67jvZzI6slvdkHUhycB7H9egy0tcCHuoQ=; b=UU7CH06jp5iRqm3rM0KWQkS2G60EYZDYFgswf8pEq7AqmrAWbyox4QMuj108KUhXXwJoFoFrfZiggMlVnHkwV4yX+FIrhS2p47oiy7bx3QRcOgRyZ6QPVyJDpHTZpgh2Zms6Okir/cmQ0Oi4CunPES/rIQ0SpmxXomSvbMwJlW1ZOBMwV+KmO87v0teOaTAfRgt0/b/wZBSH/ssO6pwfBY8imRU4hiPUwaL3Osprv1xqSGUyKOlb7wnkBLLkxv9nEUAbbsjelwRdkQzz7jWDPPvPnIjAyBpUI1rcRF0YTJ8rtcwB2+DeHXeEVxlX7fk+8y82DGULm2RtUHjxz61JVw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UCPTyArg7F67jvZzI6slvdkHUhycB7H9egy0tcCHuoQ=; b=nNZCuT66x0TVO0nQxe51RcT+LHGt9fzL3B3FCgKb57IR9Hpz0eKY+tWbpmklXWV9PUIJctyKzvugUH57LS5jrjfMtFSPUJx8Ap2j1HTKvrRXp2M9Fq8z7IFf6D5BZJSbsyn1ySbU8A1LRTiXlpVtvlLOGHny8tnn1ljrXpuYAm85I0mhX25yjZMhzF9WJ9VtbKpXBXCR/QOoohsFvMYffcKZHfh5JYS3hkTmOgWDAKyt9e4GIXQHQm2/5eQmQWojuWzw7jL3bqzAkYKQUuGzYfeKLVDqeLtMWK1Zo/1UWUbJwfMw7Q/T89XY7/b2E/fMQo07aPs1bfjONbW2C2Q53g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by BY5PR12MB4081.namprd12.prod.outlook.com (2603:10b6:a03:20e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.19; Thu, 5 Jan 2023 20:23:41 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f8b0:df13:5f8d:12a]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f8b0:df13:5f8d:12a%9]) with mapi id 15.20.5944.019; Thu, 5 Jan 2023 20:23:40 +0000 Date: Thu, 5 Jan 2023 16:23:40 -0400 From: Jason Gunthorpe To: Keith Busch Cc: Yishai Hadas , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, axboe@kernel.dk, logang@deltatee.com, hch@lst.de, alex.williamson@redhat.com, leonro@nvidia.com, maorg@nvidia.com Subject: Re: [PATCH] lib/scatterlist: Fix to merge contiguous pages into the last SG properly Message-ID: References: <20230105112339.107969-1-yishaih@nvidia.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: BL1PR13CA0413.namprd13.prod.outlook.com (2603:10b6:208:2c2::28) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|BY5PR12MB4081:EE_ X-MS-Office365-Filtering-Correlation-Id: e9c350a6-819c-4ba5-0d00-08daef5abc0b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qvIVGVyExmJAw3CT9Am3wTKpQDEUVn1b5I/l0XlAoA9c7U1+T/uZdBzaev2B/OEJAdCXzTNJYtM3eS3RBU0X946lyOAsPi//bdMIH/WXMC4DLynUW7LFkhyLr3fLjKFL0pmK69D74hQOoOEKTQ7xvIycUsdKOZd4I4dMTkqZTsRUkBt7i6ND1UKLLiErG5QFMsSQnJHIplNlta0gHiazQgyTg7yvBdWe+KRp3LcIKzI8Nln8PNG35feI0F6dN0CncfKx2raZ96nN9ShJ2Pq0D1JpNV8ze7KkKbpZ7TPpI6YrFQCqLGf0duZJOeAV74XT5OTsypz0MdfAAqvTndolaamzymWDc1wCjVk4CIEhqqXYmawBy3aE+7u9rbdy7GgEB/aWdCwkrckmMGNsbYDZh5M69cYRpvgZiQx5BeAxUyDQsZ9+wqF8dvRtI14UUyfOBBCqXVLYNxk4YJEhtE4yZprDZNfHCAJ3a6rSgdx4vauVaCQPBZLc3H6C/GA9gUaj7hZ1bcUMkupTpgmfFbYd1TYgk3zSw30AcGdoaP900TWu2r+wzYQ1z3RtasWZf5SeMWzy1sYyluDEZ2qYFPDWcVFa93S/Es3hdEmCNxAZ676kwW1Y+2l5iEsUCA/kyhOYRck6+v7/pNt7gcCh/xQzAA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(136003)(346002)(376002)(366004)(396003)(39860400002)(451199015)(83380400001)(186003)(26005)(6512007)(6506007)(107886003)(86362001)(36756003)(2616005)(38100700002)(41300700001)(4326008)(8676002)(6486002)(2906002)(5660300002)(8936002)(478600001)(66556008)(316002)(66946007)(6916009)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?urNajaej1iXcWA5laSdq4kty0P28in/b7eZsq4ko0QiVQQEs43ZAfGKN+D+H?= =?us-ascii?Q?9ustzT66b50JqKcTCzNuWHFEqgmo0hzPEZFWrfqq4GVVSvK1YIzw0Gr9SM5V?= =?us-ascii?Q?0sd8oCCqz7uI2nJo27F/OT16+mpJrmVrYbUyfVOlgAW5p/2wgPEt0N0Az80D?= =?us-ascii?Q?F0nvsvnLjafrqnYQhnjOv//6M7z2QPloW+s8FpPZe5f7qlv1yuUMdwLHRXht?= =?us-ascii?Q?NO0uJhsVJNaY1KMPY1QVYECeH431gQ239hkFIsZoAkOk8DbzM1eGpm2DmHTQ?= =?us-ascii?Q?6aWQmUZWmfdDTtV3D1igFWwtn4k8/4mPr9T0O2i67R8LlbC2ItiFQiPvDtGw?= =?us-ascii?Q?vmVjlSqWwbqkjYV+UhZVaFC7hyO+0mjoXVKI0PJC7FA0GXziWLVKDtvGrDPW?= =?us-ascii?Q?9pCqUn1UatJm/S63rDT0SucL/LA+3nNI+XCJM8NYkeUwiANDvaw1Z0hpUjkd?= =?us-ascii?Q?MiCWNnqUXOIwHZFDlZR/heP8HkgRcc2BTj0Gbcyl/W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uc5DRIV3BvTXq6xSC8icAkKcKWc2PYsCWJ8Ik/?= =?us-ascii?Q?7jx03Qab/kDDmGrwd4fd1U/SRJXPhr9pJaMQow3cxPymwfE/cuhDdPX2m96+?= =?us-ascii?Q?NqQ/05SsFDErtOe0CxIurBjSODbYEiKPiO+UrBl6JULa3FcGYQBw+j+jq3p4?= =?us-ascii?Q?AxTYkzKjQKNxDeTkUzYVomIwwC8MpHE2UNigRF9A?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e9c350a6-819c-4ba5-0d00-08daef5abc0b X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2023 20:23:40.8544 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Xqd2h4h239AUIAfpc/vLEaucaJ+3cgBmrLX+n5YtIqI7509YIZG3v9Do6FSR18Qv X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4081 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 05, 2023 at 01:21:43PM -0700, Keith Busch wrote: > On Thu, Jan 05, 2023 at 04:06:11PM -0400, Jason Gunthorpe wrote: > > On Thu, Jan 05, 2023 at 01:23:39PM +0200, Yishai Hadas wrote: > > > When sg_alloc_append_table_from_pages() calls to pages_are_mergeable() > > > in its 'sgt_append->prv' flow to check whether it can merge contiguous > > > pages into the last SG, it passes the page arguments in the wrong order. > > > > > > The first parameter should be the next candidate page to be merged to > > > the last page and not the opposite. > > > > > > The current code leads to a corrupted SG which resulted in OOPs and > > > unexpected errors when non-contiguous pages are merged wrongly. > > > > > > Fix to pass the page parameters in the right order. > > > > > > Fixes: 1567b49d1a40 ("lib/scatterlist: add check when merging zone device pages") > > > Signed-off-by: Yishai Hadas > > > --- > > > lib/scatterlist.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > rdma is pretty much the only user of this API and this bug is causing > > bad data corruption, so I'm going to take it to the rdma tree and send > > it tomorrow. > > > > Which raises the question why the original patch was done at all, > > nothing ever inputs pgmap pages into this function? > > This just takes any arbitrary user addresses, right? The user could > provide addresses from mmap'ing pci resource files that resolve to pgmap > pages. No, it passes FOLL_LONGTERM and pin_user_pages will not return any pgmaps in that case. Jason