From patchwork Mon Dec 15 11:29:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 5492231 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D04B09F30B for ; Mon, 15 Dec 2014 11:35:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 19328209FD for ; Mon, 15 Dec 2014 11:35:33 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 38767209F9 for ; Mon, 15 Dec 2014 11:35:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Y0Tt5-0001xA-6r; Mon, 15 Dec 2014 11:32:27 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Y0Trw-00015d-Um for linux-arm-kernel@lists.infradead.org; Mon, 15 Dec 2014 11:31:20 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBFBTa58017589 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 15 Dec 2014 06:29:36 -0500 Received: from redhat.com (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id sBFBTWot027224; Mon, 15 Dec 2014 06:29:33 -0500 Date: Mon, 15 Dec 2014 13:29:32 +0200 From: "Michael S. Tsirkin" To: Russell King - ARM Linux Subject: Re: [PATCH 03/18] arm64/uaccess: fix sparse errors Message-ID: <20141215112932.GA27136@redhat.com> References: <1418575877-21488-1-git-send-email-mst@redhat.com> <1418575877-21488-4-git-send-email-mst@redhat.com> <20141215111716.GG20738@arm.com> <20141215112310.GG11285@n2100.arm.linux.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20141215112310.GG11285@n2100.arm.linux.org.uk> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141215_033117_068123_30B74A55 X-CRM114-Status: GOOD ( 22.36 ) X-Spam-Score: -5.0 (-----) Cc: "linux-arch@vger.kernel.org" , Arnd Bergmann , Catalin Marinas , Will Deacon , "linux-kernel@vger.kernel.org" , Christopher Covington , "linux-arm-kernel@lists.infradead.org" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Dec 15, 2014 at 11:23:11AM +0000, Russell King - ARM Linux wrote: > On Mon, Dec 15, 2014 at 11:17:16AM +0000, Will Deacon wrote: > > On Sun, Dec 14, 2014 at 04:52:09PM +0000, Michael S. Tsirkin wrote: > > > virtio wants to read bitwise types from userspace using get_user. At the > > > moment this triggers sparse errors, since the value is passed through an > > > integer. > > > > > > Fix that up using __force. > > > > > > Signed-off-by: Michael S. Tsirkin > > > --- > > > arch/arm64/include/asm/uaccess.h | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h > > > index 3bf8f4e..8d66bcf 100644 > > > --- a/arch/arm64/include/asm/uaccess.h > > > +++ b/arch/arm64/include/asm/uaccess.h > > > @@ -147,7 +147,7 @@ do { \ > > > default: \ > > > BUILD_BUG(); \ > > > } \ > > > - (x) = (__typeof__(*(ptr)))__gu_val; \ > > > + (x) = (__force __typeof__(*(ptr)))__gu_val; \ > > > } while (0) > > > > > > #define __get_user(x, ptr) \ > > > > Acked-by: Will Deacon > > This also means you can do stuff like: > > u32 *p; > __le32 v; > > err = get_user(p, v); > > which is not right. Are you sure? We are casting to __typeof__(*(ptr))), then assigning to x. So if *p and v are different sparse will still warn. > Both the dereferenced pointer type and the destination > type should be compatible, and if one is a bitwise type but the other isn't, > that seems like a valid case to warn. > > I don't see any use of get_user() in drivers/virtio in mainline, so I can't > check further. It's not in drivers/virtio. We have a work around upstream (uses __get_user + access_ok). Try this patch reverting the work-around, you will see the sparse warning: > -- > FTTC broadband for 0.8mile line: currently at 9.5Mbps down 400kbps up > according to speedtest.net. diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index ed71b53..4c83be8 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -1047,9 +1047,7 @@ int vhost_init_used(struct vhost_virtqueue *vq) if (r) return r; vq->signalled_used_valid = false; - if (!access_ok(VERIFY_READ, &vq->used->idx, sizeof vq->used->idx)) - return -EFAULT; - r = __get_user(last_used_idx, &vq->used->idx); + r = get_user(last_used_idx, &vq->used->idx); if (r) return r; vq->last_used_idx = vhost16_to_cpu(vq, last_used_idx);