Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp8587360ybn; Tue, 1 Oct 2019 10:11:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqwq3i0y4v5wOSYWHWn7WKjeRW1DmTLRZUjG/GU54471lHsOHQwopngLgibvnwQPUI2/BjLC X-Received: by 2002:a17:906:49c7:: with SMTP id w7mr25660832ejv.167.1569949892574; Tue, 01 Oct 2019 10:11:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569949892; cv=none; d=google.com; s=arc-20160816; b=jszLq8Wlsm5d5m1hArRfVDqifD9w30VvyIMN4uMMv4KBysKGqJHrTKPeEko0Cn1yFy n9R1BGJZAz/GL6mSSyW/elivAvZY5FtQUs11gYFo2/lMoLa1VoJO4n/2Md9NXiYiARyj cTvj2H5sohV9dz60ADFD7MropTtpWf9EiXhbkXhB00L2aSFk1SJL7eRDKXcEHz0Br/zv PLLEtSfU9/wCfgDAcgtcwtlP3gwI1Xop80lrQdkvKzg3rHdBD+BC12r0FFiLUUd3hdl7 zkw+2Rm+ixKJz1gyRrjjeKV5/nmVHGpwUCXqTICIrpOU5a+N01ACKAaY8ePLxmg9MxR9 mKzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=iP66g09MiSCdy0XNQAORHC/+/yzYTstNbMb+ZKdqlWg=; b=ImodxbJA9T8mxwT6FHXGGC9j/UWx1CN9Jev/TVzw5GSHm1JNFyhR4JWOPenBNiWesX bRhpAFGTDDLGAl/PlCo+4TRXhbcZElXhkLcJA8oQN1u46hsUKL0y/9ReNOqG3zMO77Op eLV+y4q1Tz5yLBTQ3sboDhxbn3M8PAjRa5BLvRk/cLn2Pyv4LlE6II7pY3mbmT2ITgmE /C1NfLY22vNzARuJ+ccq/WeXc8cherMxI/FvYt7CzTKiOJCZrbKp8O9gloojyMU23Jj+ KpB3HPl6zQ4ly1hxao28rNQzt/UfxOHhkwYoCMO3ORNWjU0Tmnmsqz3WDoR7J8/lKN10 EOdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=lLeWSWve; 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 gq15si9501061ejb.209.2019.10.01.10.11.07; Tue, 01 Oct 2019 10:11:32 -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=@sifive.com header.s=google header.b=lLeWSWve; 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 S1727604AbfJARKD (ORCPT + 99 others); Tue, 1 Oct 2019 13:10:03 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:33595 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726741AbfJARKD (ORCPT ); Tue, 1 Oct 2019 13:10:03 -0400 Received: by mail-lj1-f196.google.com with SMTP id a22so14209761ljd.0 for ; Tue, 01 Oct 2019 10:10:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=iP66g09MiSCdy0XNQAORHC/+/yzYTstNbMb+ZKdqlWg=; b=lLeWSWvearlSbNPQ3vT1c8F1vZxuB+G/IN6H7lXXbVUiiYjfglkJc9dzfGfhy1WzUf FYbHY/amFNpMw7IwUtedVOiD6hAIqJMNvNNiYeTftW9BuzqLrd/OG/DaKgjEYhcbdGpm 9GAlVWGOHvAuxqaMsyvm0HATklhfeQ4pN/9NdqWmJtrxxt454Fl6L5Hi5Mg31VjkDIKz tbytySXgp8thodhCMMQVGnIfvjleTD9wTWzvDxqrhew8XzTlY4FyWhQ3oDh5rIZKuGem aG5aNo+If5FyRJohSz/+xTFLJSAnKKWlZwWgLZ3ufptRktZaUM6I6ZG1sR2rRVy9DjQb w6fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=iP66g09MiSCdy0XNQAORHC/+/yzYTstNbMb+ZKdqlWg=; b=fEZD3kyIobZATT1N/Vl2GsrUwn69SywxjzNaWIHaHFXl3juMfQ7kOHqC8JX5xD7qWZ b3/d+DvOb11QdHekeuQTdRBhCdPXQkwOyi/nAxvDhGXH7YFBsz5RscGbw8pVY/Jdoe1m jVX3/BDNTN/CwyLISI8xzfF3ugvsV61AbIZVFAL9TFF3St5stS9bfwcYmrQPlP1RgaaW q4uHZ+4s0owJHs12XaU3fd9mX17Ll8bNL+oWl9tBkLRUnCL5EKma1AxM5q+2ABZ7JsQk rTnKAwvinqMraiaGigbvs1PSdw+b2UzD81VltG0mIkMTK8Qv/gLGtS7MkmzwDAAbvvoO jvrw== X-Gm-Message-State: APjAAAU/97ku36T3qCLOy8AwF2PcfqsDzm2G5aIZlnowkXTe60GIN2bQ qIJPgoCSSR4Qgey1TawKTb//xPtbohbVReelhtuxCB/+AIU= X-Received: by 2002:a2e:a316:: with SMTP id l22mr16644896lje.211.1569949799769; Tue, 01 Oct 2019 10:09:59 -0700 (PDT) MIME-Version: 1.0 References: <1569885755-10947-1-git-send-email-alan.mikhak@sifive.com> <20191001121623.GA22532@ziepe.ca> In-Reply-To: <20191001121623.GA22532@ziepe.ca> From: Alan Mikhak Date: Tue, 1 Oct 2019 10:09:48 -0700 Message-ID: Subject: Re: [PATCH] scatterlist: Validate page before calling PageSlab() To: Jason Gunthorpe 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Scatterlist has no problem doing its memcpy() from pages without a page struct that were obtained from ioremap(). It is only at sg_miter_stop() that the call to PageSlab() prevents such use by crashing. This seems accidental, not by design. Scatterlist API function sg_set_page() allows any page pointer to be assigned even if it has no page struct. It doesn't check if the page pointer is valid. Its description doesn't say that a page struct is required. Regards, Alan