Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp730577imu; Wed, 23 Jan 2019 04:49:46 -0800 (PST) X-Google-Smtp-Source: ALg8bN4MxXhZwOs9XLK6XjXhk+Ax/3dqXabOMURBkkH9PQx3NFwY/Xld7TQuAxKlbbqLqi0x/LgK X-Received: by 2002:a17:902:830a:: with SMTP id bd10mr2081102plb.321.1548247785982; Wed, 23 Jan 2019 04:49:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548247785; cv=none; d=google.com; s=arc-20160816; b=L9POz/WarsHUzfNg3ynlf4LRPfRoDIChk0Ni8YEkodIpDK7qnEKjDhTvC+RAz5Lzj+ b36Vd5z+ysCC/E2Xd8xHkyyKL+UWDyWy2EWlMW0N3YBcLjuFJh7xBd40gFfZy/dSFet/ UCS8RCHatv3KVKZbViDcnN+FXwqQVBvaKuqY1GqCruXmqFxgYKmLa6eZhsqPfogKU9Bx jb07K42L/izfEHHG7Zj7uKw+Pp7aD/uOftPQ+InvL3Ribu+sYMNwwkH0v2fLJxgM95st 4avBSojybyVAwwZCCzj5jlAj40TD9lpdDOs+eWlK10SbSXzRwzG6aODGNUZA3o/DNAQo 6dhA== 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=UEuV0IZGNPx4wPD5B0RND0eWY9Q7+l5E7gAXbSBWa8E=; b=suSczBm+oWlm3OqRjurzytwHL+OzHMbhYEh89EouAJ7cCwOTOVFf7t3uyOzeG0NlJd YDCtowp+MI7jn8OWT3U1vH16F4HN8mF+uSzwGw7NvfCS1OR8V6MUV1LLMMnveB89CmZv v5L4/BHaW7vHQgO5NT14Q8JA6yPAUNRMGSwP9q/61loQ5NHcQc4xo+5qqMKtUQIB7LBo /B2h1EUjcoj55+P1+c7rISQERq/Z2uQq6a+WQzgC8zebW8MYpXy4a7qkDVwvSP+9/uQ5 05jbd+BvLO6YrtskC+wwNY3iTFkwBA7LqLjFLQ1Ink2wq4n1RfjF3AkXHi+Iyrh/j1ML sjYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Q4h02q/o"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si18287880plq.138.2019.01.23.04.49.30; Wed, 23 Jan 2019 04:49: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=@linaro.org header.s=google header.b="Q4h02q/o"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726235AbfAWMrK (ORCPT + 99 others); Wed, 23 Jan 2019 07:47:10 -0500 Received: from mail-ot1-f66.google.com ([209.85.210.66]:42662 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726104AbfAWMrK (ORCPT ); Wed, 23 Jan 2019 07:47:10 -0500 Received: by mail-ot1-f66.google.com with SMTP id v23so1757952otk.9 for ; Wed, 23 Jan 2019 04:47:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=UEuV0IZGNPx4wPD5B0RND0eWY9Q7+l5E7gAXbSBWa8E=; b=Q4h02q/oWVaWJ9NgeMAz6sQ05FxemkRRnvs/ySScJl8lzevOv2OKwFomjeZdoqofgE qTMeRXxdjypmKbULek8aAlNgxTxrH+qdEUktvMvipLu7raZPEHoJVDgLaKxW+hfNfmko RS7RJhPrBDp32K7Qpi690oKHKvjyFXskcpW+o= 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=UEuV0IZGNPx4wPD5B0RND0eWY9Q7+l5E7gAXbSBWa8E=; b=CDKiXCTii6JVvzwDpodZEApGH6tHIbyd18SEPhDttF6gDkzwdxdNBR7QC4UZ8Y0QNl DOJwgUe1ybKUnl0t8vSSDke34LfUdCSFo8yOV9hwihrr79O8kLAJG5mgP5Amw0NqJwq0 kGE+F5iElOmLX32GXzD51BUxTxbke0iOZRWHbXjscXAyhp2rxdt3H7gqcagNiG18gENt VGKxJClE/sVjmyKw2iBvLYCCGfUBFNRESzcXHQCUAoVjaq1AKXBha1Q5SOyTnS+GdBPq IUfa+sQTRdmjazx7be9goH98JHK3FwyoVznWOm2gLybs5jHHBEIk2VfsKCsr2YRn5G8+ OTuw== X-Gm-Message-State: AJcUukfSD2JAiGouwFiyu77nYgqF35vw+YxNgxQHE6TToZTuNY3khwUx KBPK+39UY42EKQXzmsZao679rQ== X-Received: by 2002:a9d:6ac2:: with SMTP id m2mr1274768otq.353.1548247629246; Wed, 23 Jan 2019 04:47:09 -0800 (PST) Received: from leoy-ThinkPad-X240s (li1118-108.members.linode.com. [45.79.19.108]) by smtp.gmail.com with ESMTPSA id b128sm9193462oif.7.2019.01.23.04.47.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Jan 2019 04:47:08 -0800 (PST) Date: Wed, 23 Jan 2019 20:46:58 +0800 From: Leo Yan To: Takashi Iwai Cc: Mark Brown , Jaroslav Kysela , alsa-devel@alsa-project.org, arnd@arndb.de, keescook@chromium.org, bgoswami@codeaurora.org, sr@denx.de, gustavo@embeddedor.com, philburk@google.com, willy@infradead.org, mchehab+samsung@kernel.org, sboyd@kernel.org, vkoul@kernel.org, Baolin Wang , daniel.thompson@linaro.org, mathieu.poirier@linaro.org, srinivas.kandagatla@linaro.org, anna-maria@linutronix.de, corbet@lwn.net, jmiller@neverware.com, ckeepax@opensource.wolfsonmicro.com, joe@perches.com, o-takashi@sakamocchi.jp, colyli@suse.de, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] ALSA: core: Add DMA share buffer support Message-ID: <20190123124658.GE15906@leoy-ThinkPad-X240s> References: <290f6d3a5fe288b87480cc5fa12c5139728daeca.1547787189.git.baolin.wang@linaro.org> <81e894ba-acad-2fd4-996d-8d35edd8825a@perex.cz> <20190118190805.GF6260@sirena.org.uk> <20190121124053.GA12679@sirena.org.uk> <20190122202535.GK7579@sirena.org.uk> 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 Hi all, On Wed, Jan 23, 2019 at 12:58:51PM +0100, Takashi Iwai wrote: > On Tue, 22 Jan 2019 21:25:35 +0100, > Mark Brown wrote: > > > > On Mon, Jan 21, 2019 at 03:15:43PM +0100, Jaroslav Kysela wrote: > > > Dne 21.1.2019 v 13:40 Mark Brown napsal(a): > > > > > > It was the bit about adding more extended permission control that I was > > > > worried about there, not the initial O_APPEND bit. Indeed the O_APPEND > > > > bit sounds like it might also work from the base buffer sharing point of > > > > view, I have to confess I'd not heard of that feature before (it didn't > > > > come up in the discussion when Eric raised this in Prague). > > > > > With permissions, I meant to make possible to restrict the file > > > descriptor operations (ioctls) for the depending task (like access to > > > the DMA buffer, synchronize it for the non-coherent platforms and maybe > > > read/write the actual position, delay etc.). It should be relatively > > > easy to implement using the snd_pcm_file structure. > > > > Right, that's what I understood you to mean. If you want to have a > > policy saying "it's OK to export a PCM file descriptor if it's only got > > permissions X and Y" the security module is going to need to know about > > the mechanism for setting those permissions. With dma_buf that's all a > > bit easier as there's less new stuff, though I've no real idea how much > > of a big deal that actually is. > > There are many ways to implement such a thing, yeah. If we'd need an > implementation that is done solely in the sound driver layer, I can > imagine to introduce either a new ioctl or an open flag (like O_EXCL) > to specify the restricted sharing. That is, a kind of master / slave > model where only the master is allowed to manipulate the stream while > the slave can mmap, read/write and get status. I am lacking security related knowledge, especially for SELinux. So only can give background information but not sure if it's really helpful for discussion. Android web page [1] give some information for this: "The shared memory is referenced using a file descriptor that is generated by the ALSA driver. If the file descriptor is directly associated with a /dev/snd/ driver file, then it can be used by the AAudio service in SHARED mode. But the descriptor cannot be passed to the client code for EXCLUSIVE mode. The /dev/snd/ file descriptor would provide too broad of access to the client, so it is blocked by SELinux. In order to support EXCLUSIVE mode, it is necessary to convert the /dev/snd/ descriptor to an anon_inode:dmabuffer file descriptor. SELinux allows that file descriptor to be passed to the client. It can also be used by the AAudioService. An anon_inode:dmabuffer file descriptor can be generated using the Android Ion memory library." So we work out dmabuf driver for audio buffer, the audio buffer will be exported and attached by using dma-buf framework; then we can return one file descriptor which is generated by dma-buf and this file descriptor is bound with anon inode based on dma-buf core code. If we directly use the device node /dev/snd/ as file descriptor, even though we specify flag O_EXCL when open it, but it still is not an anon inode file descriptor. Thus this is not safe enough and will be blocked by SELinux. On the other hand, this patch wants to use dma-buf framework to provide file descriptor for the audio buffer, and this audio buffer can be one of mutiple audio buffers in the system and it can be shared to any audio client program. Again, I have no less knowledge for SELinux so sorry if I introduce any noise at here. And very appreciate any comments for this. Thanks, Leo Yan [1] https://source.android.com/devices/audio/aaudio