From patchwork Thu May 4 09:58:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Elwell X-Patchwork-Id: 9711333 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 076B660387 for ; Thu, 4 May 2017 09:58:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0D1E285FD for ; Thu, 4 May 2017 09:58:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E50632867A; Thu, 4 May 2017 09:58:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1906A285FD for ; Thu, 4 May 2017 09:58:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Date:Message-ID:Subject: From:To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Czc0TnGxFqOrqy10RGm6LqaiP+HDXtWie2eAU0uC67Q=; b=l983Sc7fY3u7bO nT1hmDygfB5PopqlF6N7lLBoZZoxPVCFhRTwnf/F4jQ9ZTNlJLOyszlPH3hCe3n7fsPGbqHG4iTId EPWyqJBObQms0053/bLw6DlMynpRAPIuGKR4tclA2+sVjkVZFn3ZZb281sHb0s7V4Ntx5G0JFlMnt j6g4xb5u4HLKyaN8uhel0JaFeNAOxexHuIiVfXhoeB6AYsvSXcMOgIo7kZ4u60tNjuAGW9qxyiU8G kINezR2FHuRKKb3ewcbKA78yM5qUDsDXuMB7ld6E6SBTHf82ynzXjfrVbekPwI80rbzgHiS81jWhv uNIwSXyijSjOBPhQMEtQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d6DXB-0007kK-9x; Thu, 04 May 2017 09:58:53 +0000 Received: from mx07-00252a01.pphosted.com ([62.209.51.214]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d6DX6-0007fe-HR for linux-arm-kernel@lists.infradead.org; Thu, 04 May 2017 09:58:50 +0000 Received: from pps.filterd (m0102628.ppops.net [127.0.0.1]) by mx07-00252a01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v449tVnC017081 for ; Thu, 4 May 2017 10:58:19 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.org; h=to : cc : from : subject : message-id : date : mime-version : content-type : content-transfer-encoding; s=pp; bh=pljXe0N2NNg/2u+61qTOSzK9dGPCkrVipvUKMid4JpU=; b=iY8QIapPkPDF+AJaJGRKbLK6qCxyRunv1rIttuA8Y1Cko5HEmPPKYI0EmOg4o2JEfyjW 7PIzyrkXBKxUPf/MAFrAUHYdjO7qv5o1DgL+QzLAYix+CXv5QjthomgvkpJuGNP4wiho i6PF98ZR1BzhmZ6kTlbbC85nyIynINKMsPqTaUMHNs/8SAtlYDYQgAqqsuKtRT+Y7brd vTKfFHcKPCRVpLlxGwuuJuTSJJGITBi0m/jW16fHPaL98vv0nIXm2eRW6T6hpu5107zZ R8uUWL59RHTiG80NogObuHQa+2DxYzYf2xa82FQQMFutTyRqK2slPDFt8Yr81fr4Pfaq fw== Received: from mail-wr0-f197.google.com (mail-wr0-f197.google.com [209.85.128.197]) by mx07-00252a01.pphosted.com with ESMTP id 2a72ne0pgu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=OK) for ; Thu, 04 May 2017 10:58:19 +0100 Received: by mail-wr0-f197.google.com with SMTP id y106so1045646wrb.14 for ; Thu, 04 May 2017 02:58:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi-org.20150623.gappssmtp.com; s=20150623; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=pljXe0N2NNg/2u+61qTOSzK9dGPCkrVipvUKMid4JpU=; b=OEtdBoVr9hnrtnryW5jQtIEg8FVEaCfUJPKrV4O5nEkfwEaO1GGGVKdmzLR1RDm6bn SDmDwjxK01q+pFuQpjhinAjqP/CWcBvp3PJCYHMSrAz7Sn9PTWrhRbjVKiPxjHLvoi10 C+JufbzzifVtXZmt5Fwf3cr7b15Xbh+j/9KM9C8JGZY/LDgLbE+om0Pikfi8eg4o55bt PBOJTbr7hI05aXQaMhAQhaCbDANHKhwT/eVnAhXAnuregTay9Yc5I7yFpERb1h75Ik1o YSHpt2LlRqr2KmPyrVO9/WSSPyEK6V4zDJS7INEiB+6qKNb2c3M6z9yzkl5iisHRlgQ5 zH0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=pljXe0N2NNg/2u+61qTOSzK9dGPCkrVipvUKMid4JpU=; b=VbOX0PGgkkiOZOJkQywCwNMmwBRf7n1JRcU5yxPzpRRkesw2VyYwm3XbPUt2+kb23Y Vyxi6XqiPYVmS5x3X2VLjXdk/ta1PbFgYrViP2iaEZbs0Es+Pcf5vwt92GkqSpyaq+Az KHYhnK2qW3fAc3kKpR82Zg750MsN4IGkqGwLJOQ3QhveRxiM4wKCxbMZFmpxIfQPajA2 DLeF3K2kPRwP0Ni1CX098WN+oUeo2a7voIDqlMp64ByE6+5ZcL3RCdF/rZypaMs5PUzD ovPOzzKh7brZrKY1F2Uof5nF8Axn8rIGIw2sHxkED6E81YPtgzZII/+agt1jDxAe3dHA kpDg== X-Gm-Message-State: AN3rC/4OSQZ4b9dAs2+f2swxfuqEcErn8JHWxg80vi59OAPdNz6SvfEd OQnpke//MRFDKyCjVV51HSyWhMZ25xGwBGk4y+UCGumTBd1xUdOSr3Lwi8ZO46nuRI40IT8XdPR PlTNfxj3Ht8UBYHSLLqxm72lwlQ== X-Received: by 10.223.165.5 with SMTP id i5mr22027950wrb.197.1493891898943; Thu, 04 May 2017 02:58:18 -0700 (PDT) X-Received: by 10.223.165.5 with SMTP id i5mr22027930wrb.197.1493891898700; Thu, 04 May 2017 02:58:18 -0700 (PDT) Received: from ?IPv6:2a00:2381:fdf7:14:71a5:fb06:dd44:d93f? ([2a00:2381:fdf7:14:71a5:fb06:dd44:d93f]) by smtp.gmail.com with ESMTPSA id j44sm912233wre.67.2017.05.04.02.58.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 May 2017 02:58:18 -0700 (PDT) To: Greg Kroah-Hartman From: Phil Elwell Subject: [PATCH] staging: vc04_services: Fix bulk cache maintenance Message-ID: Date: Thu, 4 May 2017 10:58:20 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-04_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_spam_notspam policy=outbound_spam score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705040163 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170504_025848_898109_753D0032 X-CRM114-Status: GOOD ( 15.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devel@driverdev.osuosl.org, daniels@collabora.com, Lee Jones , linux-kernel@vger.kernel.org, Michael Zoran , =?UTF-8?Q?Noralf_Tr=c3=b8nnes?= , linux-rpi-kernel , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP vchiq_arm supports transfers less than one page and at arbitrary alignment, using the dma-mapping API to perform its cache maintenance (even though the VPU drives the DMA hardware). Read (DMA_FROM_DEVICE) operations use cache invalidation for speed, falling back to clean+invalidate on partial cache lines, with writes (DMA_TO_DEVICE) using flushes. If a read transfer has ends which aren't page-aligned, performing cache maintenance as if they were whole pages can lead to memory corruption since the partial cache lines at the ends (and any cache lines before or after the transfer area) will be invalidated. This bug was masked until the disabling of the cache flush in flush_dcache_page(). Honouring the requested transfer start- and end-points prevents the corruption. Fixes: cf9caf192988 ("staging: vc04_services: Replace dmac_map_area with dmac_map_sg") Signed-off-by: Phil Elwell Reported-by: Stefan Wahren Tested-by: Stefan Wahren --- .../interface/vchiq_arm/vchiq_2835_arm.c | 31 +++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c index 3aeffcb..02e9736 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c @@ -501,8 +501,15 @@ int vchiq_platform_init(struct platform_device *pdev, VCHIQ_STATE_T *state) */ sg_init_table(scatterlist, num_pages); /* Now set the pages for each scatterlist */ - for (i = 0; i < num_pages; i++) - sg_set_page(scatterlist + i, pages[i], PAGE_SIZE, 0); + for (i = 0; i < num_pages; i++) { + unsigned int len = PAGE_SIZE - offset; + + if (len > count) + len = count; + sg_set_page(scatterlist + i, pages[i], len, offset); + offset = 0; + count -= len; + } dma_buffers = dma_map_sg(g_dev, scatterlist, @@ -523,20 +530,20 @@ int vchiq_platform_init(struct platform_device *pdev, VCHIQ_STATE_T *state) u32 addr = sg_dma_address(sg); /* Note: addrs is the address + page_count - 1 - * The firmware expects the block to be page + * The firmware expects blocks after the first to be page- * aligned and a multiple of the page size */ WARN_ON(len == 0); - WARN_ON(len & ~PAGE_MASK); - WARN_ON(addr & ~PAGE_MASK); + WARN_ON(i && (i != (dma_buffers - 1)) && (len & ~PAGE_MASK)); + WARN_ON(i && (addr & ~PAGE_MASK)); if (k > 0 && - ((addrs[k - 1] & PAGE_MASK) | - ((addrs[k - 1] & ~PAGE_MASK) + 1) << PAGE_SHIFT) - == addr) { - addrs[k - 1] += (len >> PAGE_SHIFT); - } else { - addrs[k++] = addr | ((len >> PAGE_SHIFT) - 1); - } + ((addrs[k - 1] & PAGE_MASK) + + (((addrs[k - 1] & ~PAGE_MASK) + 1) << PAGE_SHIFT)) + == (addr & PAGE_MASK)) + addrs[k - 1] += ((len + PAGE_SIZE - 1) >> PAGE_SHIFT); + else + addrs[k++] = (addr & PAGE_MASK) | + (((len + PAGE_SIZE - 1) >> PAGE_SHIFT) - 1); } /* Partial cache lines (fragments) require special measures */