Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp8590058ybn; Tue, 1 Oct 2019 10:13:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxBMBrve8iUKMxd2TdrNx6m84qMrq6cQ9PKbdQcMpYJlBmAvwhKuV4pgJNDveV04eDO7/Ed X-Received: by 2002:a50:91d8:: with SMTP id h24mr26501843eda.61.1569950026398; Tue, 01 Oct 2019 10:13:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569950026; cv=none; d=google.com; s=arc-20160816; b=UxAkok/RhskcKRe8MYfQzIDb9hXcX9f2H1xbr5VwPwzNZ/Mz3Rne9N5bDzuvzTdO8b PwwlLLKDtiIXkd+A1DeBa5EntDjQ+EG0gXQelkvZxIo9LYStV64KejdLLLizSxD3p1NW +feeiD9X3Ownuv19RwqqCHeM0NS2BXjeyEkrz1M1qNziJJluKxt1qvO09vvB+dEGAcb+ 7Lni5V8i8C6++zUH1bKii/uaP3QyLksF7oBu16V31gZoYoS8p/i1dimx3kYCGQFSZGqd g6CfCiwyzS1oc4qz7BQwArU3yrC1m2GmyomLxLuT7fgscZB2wWPN18x5hD+tRyjiR43x JLFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=J6dBLTJUr1ayorS1X/wuqaZamfgYcdnHpuqJt5uSLPg=; b=T2A/Jim07h328dOECsPU8QRh0eGMRJyPERr41R3+5cRKf1xzyHpPacNLI6DGs/RX/S I0bsSCIq5JiyfhMfmltbH12ATDMwbPZOuGNF5HXzNIxQ+dWEEiKp15ot9bhL51eXfRy3 1T1f+Edb0ytNlFO0QHmhDfgjG6SX29XS3R44ERkr9y63K2T4IKDUHcP3hA8GiJWjPeGS UZ2y7OvWF8xfvwoOQ3F5yXw2bUUJfC5IMP3gTohwYHh1YGizkkGeoFkaoCwNhjINk0S/ ValjhYrezN76s8VYFnRaW9WXJYhOhB/zJYh3YzD/OPvLnvhHRjFGWa8f0oKb7fQ2ehq2 zJiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=cnvMiLlr; 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 27si9715580edz.186.2019.10.01.10.13.22; Tue, 01 Oct 2019 10:13:46 -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; dkim=pass header.i=@ziepe.ca header.s=google header.b=cnvMiLlr; 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 S1728343AbfJARMX (ORCPT + 99 others); Tue, 1 Oct 2019 13:12:23 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:32977 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725792AbfJARMW (ORCPT ); Tue, 1 Oct 2019 13:12:22 -0400 Received: by mail-qt1-f193.google.com with SMTP id r5so22600882qtd.0 for ; Tue, 01 Oct 2019 10:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=J6dBLTJUr1ayorS1X/wuqaZamfgYcdnHpuqJt5uSLPg=; b=cnvMiLlrbSLAifWEHOvBwxzT/fH3OP1qfY0QYVJqjT7CBvTdigVRkukRjuB8NkrLNZ 8KYD+X2WgyhuliBIf8/T1cQ0Xmlo/FKfQZtQIJKMuQ5vFWTYbCy+WTKAtTSNgDT0LhEx /t9qYP+L3X32XiOMlIXFWAPWWTASSOp/duXjDQktUr9lbAMx86p3OLeqSdruGLsC9Y3t 7neZ7EXhN1DvxRNFajaGMt5Rg5GNucsHob5c8rmbGeG6Ymmp/rS9yQ6LNrWgSPXJ7xWE 3cbVNJuTqgFTUwTlAy+nQHcEptUmtJH6P55Hb5sPVJ8AWU26EJHikwwKQ8XqiM7RSYpu BIhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=J6dBLTJUr1ayorS1X/wuqaZamfgYcdnHpuqJt5uSLPg=; b=AIn6HinkYcgsc0IhwZ9dHdse1DOsopudlfYbgUYG4rym8td3c3y+rlgkbvXzdhjeVt T/AowArI5GTWfI9Uxueb3z1jJeLLXkuL6dUbsv1Uugu2bATeTFrAIQCw/ejQUYDuPjBO f7wA9uVIyxmZgkc9j3WcaKHOe9RtY6BMeKS1wfJVNHhPjoy+K3dM6Jc8oiO0FTv782mj Jj7vgm4e4VFj5gql027P3HZxA3hLO2CKwMeNxmNxAHPondmJ5s+juFzNQqdxaJCFLokJ dl/ydp+s9tO9SgkWe1PsjZKVoOQMElgY0GlHf11aCneFTw8kCmBzAvhCrfWMFnDctytz AJpw== X-Gm-Message-State: APjAAAU0K3Wq57uZtbklTIWrZeK35Pv5yuzOsDrrHvcmiOWwrimCMcFf hM8ZriAqSORkbFfXJPv7XA9TNg== X-Received: by 2002:ac8:134c:: with SMTP id f12mr1701472qtj.162.1569949941698; Tue, 01 Oct 2019 10:12:21 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-162-113-180.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.113.180]) by smtp.gmail.com with ESMTPSA id v7sm8755483qte.29.2019.10.01.10.12.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 01 Oct 2019 10:12:21 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1iFLhE-0003Fi-QM; Tue, 01 Oct 2019 14:12:20 -0300 Date: Tue, 1 Oct 2019 14:12:20 -0300 From: Jason Gunthorpe To: Alan Mikhak Cc: linux-kernel@vger.kernel.org, martin.petersen@oracle.com, alexios.zavras@intel.com, ming.lei@redhat.com, gregkh@linuxfoundation.org, tglx@linutronix.de, christophe.leroy@c-s.fr, Palmer Dabbelt , Paul Walmsley Subject: Re: [PATCH] scatterlist: Validate page before calling PageSlab() Message-ID: <20191001171220.GF22532@ziepe.ca> References: <1569885755-10947-1-git-send-email-alan.mikhak@sifive.com> <20191001121623.GA22532@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 01, 2019 at 10:09:48AM -0700, Alan Mikhak wrote: > On Tue, Oct 1, 2019 at 5:16 AM Jason Gunthorpe wrote: > > > > On Mon, Sep 30, 2019 at 04:22:35PM -0700, Alan Mikhak wrote: > > > From: Alan Mikhak > > > > > > Modify sg_miter_stop() to validate the page pointer > > > before calling PageSlab(). This check prevents a crash > > > that will occur if PageSlab() gets called with a page > > > pointer that is not backed by page struct. > > > > > > A virtual address obtained from ioremap() for a physical > > > address in PCI address space can be assigned to a > > > scatterlist segment using the public scatterlist API > > > as in the following example: > > > > > > my_sg_set_page(struct scatterlist *sg, > > > const void __iomem *ioaddr, > > > size_t iosize) > > > { > > > sg_set_page(sg, > > > virt_to_page(ioaddr), > > > (unsigned int)iosize, > > > offset_in_page(ioaddr)); > > > sg_init_marker(sg, 1); > > > } > > > > > > If the virtual address obtained from ioremap() is not > > > backed by a page struct, virt_to_page() returns an > > > invalid page pointer. However, sg_copy_buffer() can > > > correctly recover the original virtual address. Such > > > addresses can successfully be assigned to scatterlist > > > segments to transfer data across the PCI bus with > > > sg_copy_buffer() if it were not for the crash in > > > PageSlab() when called by sg_miter_stop(). > > > > I thought we already agreed in general that putting things that don't > > have struct page into the scatter list was not allowed? > > > > Jason > > Thanks Jason for your comment. > > Cost of adding page structs to a large PCI I/O address range can be > quite substantial. Allowing PCI I/O pages without page structs may be > desirable. Perhaps it is worth considering this cost. This is generally agreed, but nobody has figured out a solution. > Scatterlist has no problem doing its memcpy() from pages without a > page struct that were obtained from ioremap(). It is only at Calling memcpy on pointers from ioremap is very much not allowed. Code has to use the iomem safe memcpy. Jason