Received: by 10.223.185.116 with SMTP id b49csp2887667wrg; Mon, 12 Feb 2018 17:21:45 -0800 (PST) X-Google-Smtp-Source: AH8x225QrTJJmv6ddJB4Nb8Qfhl9jUvnSRgcDaXrAJyqk+NT7pk5H/757ywma7er9cTMHPYvtuch X-Received: by 2002:a17:902:6504:: with SMTP id b4-v6mr7726006plk.451.1518484905437; Mon, 12 Feb 2018 17:21:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518484905; cv=none; d=google.com; s=arc-20160816; b=Wvu8jwZ0hYfTjoksQoebZDsWkolUHeNMAdEjdu6uXrwNwe7O1Mcx+cu4fhD0aMQ6Kx /1ftgbzoP6Rw1qj1zDj7ae7W5ycg4XaGJ64JW8AS72A/CZSrBXG14lfbHG9X6EXBabsS tBIecuQvfpA+xXG/esH1BKgnWiq0qsm43I1MlpY54J6zYyMw+RHvbu5ElsB0qXptC2/R 459eoxy/MjcjZsy80OKNZGPP4CQKTOxVgv4zfv3rzS1OlWyA9+jWX5qS16C4Ql0L6hol +PtVus4piyivlV9dmjfJReXAP/sbvXxxNrTIXgpLuDHPIiYnfa9U+8Q1k+2byZqrFWRZ 1FTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dmarc-filter :dkim-signature:dkim-signature:arc-authentication-results; bh=pUWdrfvAFC/GIBHWttgD1GWI8RXzXadeGg8OV1dDg6c=; b=SwSDQZ6l9mDVV7hgNkbcX/hTJEByhenS4XlTc0vq4hH9egxEfZ9AUnVsisUU/pbZ+4 as7UATW2Ohm2B+uayijJtjqIgqzXpxl1pfjysGqvnDn2jvdXBTQnaJVmHpovcq8ELL0G U1DNJqNzWkftk27+fwarjdB2bxMHUo0oO3u9ehWLgU7RZ/RNLFoLSXC3RTocKQkT7nNU 73TGpBR7J8HKHcSp08pyzxY7Wot3R5K2yixMBf+OjzetZ+zNyO8+jLqLd2IgQfazmFjC k3ltRRkDIw6UtcisNzCi1vc+LBPdgm7O+atgbc3RFAgWvoRzdQa7ypjUnehQJSEdMntQ J+LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=V6RFQnWT; dkim=pass header.i=@codeaurora.org header.s=default header.b=e++O1XQ/; 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 i64-v6si6672129pli.142.2018.02.12.17.21.30; Mon, 12 Feb 2018 17:21:45 -0800 (PST) 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=@codeaurora.org header.s=default header.b=V6RFQnWT; dkim=pass header.i=@codeaurora.org header.s=default header.b=e++O1XQ/; 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 S933130AbeBMBUl (ORCPT + 99 others); Mon, 12 Feb 2018 20:20:41 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:45938 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932736AbeBMBUk (ORCPT ); Mon, 12 Feb 2018 20:20:40 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 2175B60F76; Tue, 13 Feb 2018 01:20:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1518484840; bh=IHIjZnh33pU5kN+3hCjf6VrmKnQh1PQcIyuhsJvKZ0U=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=V6RFQnWTWXrG4fC88ZS15l0wbroKEoljJdELcAJ8o9LyCESb512v8k5No8pGJecYU DIZBaGBxXW0aqrVZ5psvauZxmQDfI5tgqHknIN5rL5PutjeqKMf4TKHm0x2PiorTL5 sxRlT0tP41v8TWoFL95wTyqKhELBOkxYHXYbcqtY= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from lmark-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: lmark@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 19AA16055B; Tue, 13 Feb 2018 01:20:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1518484839; bh=IHIjZnh33pU5kN+3hCjf6VrmKnQh1PQcIyuhsJvKZ0U=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=e++O1XQ/aUnpNIu97it6LNiviVA2UIux4VymxN2d1KcfyyZsQXttM4aiKydpqRbkY mY9KibN1L8nDghw+fAb84owlXvSstCFiatqa2v5cHbWwrtkSP4eyoLiCBPdj8VcW+d TYOlpCJY5+K3rlnl08RCokHwUV7pswnYm/rF97hw= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 19AA16055B Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=lmark@codeaurora.org Date: Mon, 12 Feb 2018 17:20:38 -0800 (PST) From: Liam Mark X-X-Sender: lmark@lmark-linux.qualcomm.com To: Laura Abbott cc: Sumit Semwal , Martijn Coenen , Todd Kjos , =?ISO-8859-15?Q?Arve_Hj=F8nnev=E5g?= , linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org, linaro-mm-sig@lists.linaro.org Subject: Re: [PATCH] staging: android: ion: Restrict cache maintenance to dma mapped memory In-Reply-To: <6c61b218-c56d-659a-47f8-2cd5d44d28ca@redhat.com> Message-ID: References: <6c61b218-c56d-659a-47f8-2cd5d44d28ca@redhat.com> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 12 Feb 2018, Laura Abbott wrote: > On 02/09/2018 10:21 PM, Liam Mark wrote: > > The ION begin_cpu_access and end_cpu_access functions use the > > dma_sync_sg_for_cpu and dma_sync_sg_for_device APIs to perform cache > > maintenance. > > > > Currently it is possible to apply cache maintenance, via the > > begin_cpu_access and end_cpu_access APIs, to ION buffers which are not > > dma mapped. > > > > The dma sync sg APIs should not be called on sg lists which have not been > > dma mapped as this can result in cache maintenance being applied to the > > wrong address. If an sg list has not been dma mapped then its dma_address > > field has not been populated, some dma ops such as the swiotlb_dma_ops ops > > use the dma_address field to calculate the address onto which to apply > > cache maintenance. > > > > Fix the ION begin_cpu_access and end_cpu_access functions to only apply > > cache maintenance to buffers which have been dma mapped. > > > I think this looks okay. I was initially concerned about concurrency and > setting the dma_mapped flag but I think that should be handled by the > caller synchronizing map/unmap/cpu_access calls (we might need to re-evaluate > in the future) I had convinced myself that concurrency wasn't a problem, but you are right it does need to be re-evaluated. For example the code could be at the point after the dma unmap call has completed but before dma_mapped has been set to false, and if userspace happened to slip in a call to begin/end cpu access cache maintenance would happen on memory which isn't dma mapped. So at least this would need to be addressed, maybe for this issue just move the setting of dma_mapped to the start of the ion_unmap_dma_buf function. I can clean this up and any other concurrency issues we can identify. > > I would like to hold on queuing this for just a little bit until I > finish working on the Ion unit test (doing this in the complete opposite > order of course). I'm assuming this passed your internal tests Liam? Yes it has passed my internal ION unit tests, though I haven't given the change to internal ION clients yet. Liam Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project