Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp97340pxf; Wed, 10 Mar 2021 22:06:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyOINw3G2+oNSfzWPfEL6b0GUe+vTatNfBEH7xMHzHYOOO3YZRaCfcOrK3z5UNx7dYpM0GH X-Received: by 2002:aa7:c403:: with SMTP id j3mr6813115edq.137.1615442777641; Wed, 10 Mar 2021 22:06:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615442777; cv=none; d=google.com; s=arc-20160816; b=XeGDs5L6MvDHROfhr83KnuwNquX1324HgG0j2av7TUy7Bzsc7aKqUJIzp7n78UhbRP 4HndH5u9qrYSiVXQRY2Oa5L1q4jP4LVHOHC/FhiXLMcqr8m4xxCJAX2DQypjQ2jN+XTh flj1VSwvWreRCVNQL195bUIgglqzrQf7b/P9S04PIPlstU7DVNhwodHaj2AhzQeuu8nS Zs7VK0mY6ewuYHi3w/WLqAadFD+vPZmvyvMxpG7/Fm9Ikn2tQBKM+ApL3t8rS27JHf6Q 8EQRH6LYjzJq640MKN2ZVFdD8g4xnb62/Rf8oIKSiv0UBe8BX2tW2Yb6OySKZfIDepf9 dcTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:ironport-sdr:ironport-sdr; bh=0VX15KhDrMjSaJU3B2v3jOyHEDmiH//o0GjF+0UbH4U=; b=NF0PoMPJQ9cI5nicCKRRppwKFyRjG1bA1khN2kfoItotpmpOjznJfdY93KF/7QnRX6 5wWRqsPqfryOEsEtDJ1GlKrN7vCf1y0ZlRCOERwLQquZsTazzhwBU+3/LmCboCK0efuC OGxsbqFDJdjfC8UCw+Dsg5sTqbvRnJiml/0lc2HaXodOOBMpYsy2sU6RQuNkkGlymTo3 v0lSCCGHu14r4WiwhPXFcfnjyuuSp6HvOXGyAbb8kDI2uO7n70jhgCMRX97YTQlzQU3b FyW65tm6ObCImEzKEDl7CktGzVaq8jVweS4IfjRSnevh/on9ueN5RY616J6NdDuNpUH3 WXEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q21si1105888ejo.166.2021.03.10.22.05.55; Wed, 10 Mar 2021 22:06:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229910AbhCKGAH (ORCPT + 99 others); Thu, 11 Mar 2021 01:00:07 -0500 Received: from mga01.intel.com ([192.55.52.88]:37638 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229923AbhCKF7u (ORCPT ); Thu, 11 Mar 2021 00:59:50 -0500 IronPort-SDR: c2VSedUMAZFnUAZbYA7/YLuaR9uuYdS+2H6WSyob17GSzOtcS7GWG/d8oLEG5nPafo4ZX0KLw6 16Km3OGIUalw== X-IronPort-AV: E=McAfee;i="6000,8403,9919"; a="208432971" X-IronPort-AV: E=Sophos;i="5.81,239,1610438400"; d="scan'208";a="208432971" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Mar 2021 21:59:50 -0800 IronPort-SDR: du9lyukxeF00i+Ix2NYJrOSRrhlfdBckq7UR+OhFYQ6il5kUCXljzaM2Uv5W/lpYr6TQzAI03b RQEWJrNe20xA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,239,1610438400"; d="scan'208";a="603404106" Received: from unknown (HELO [10.239.154.55]) ([10.239.154.55]) by fmsmga005.fm.intel.com with ESMTP; 10 Mar 2021 21:59:43 -0800 Subject: Re: [PATCH v6] i2c: virtio: add a virtio i2c frontend driver To: Arnd Bergmann , Jason Wang Cc: Linux I2C , virtualization@lists.linux-foundation.org, "linux-kernel@vger.kernel.org" , "Michael S. Tsirkin" , Wolfram Sang , Wolfram Sang , Andy Shevchenko , conghui.chen@intel.com, kblaiech@mellanox.com, jarkko.nikula@linux.intel.com, Sergey Semin , Mike Rapoport , loic.poulain@linaro.org, Tali Perry , =?UTF-8?Q?Uwe_Kleine-K=c3=b6nig?= , Bjorn Andersson , yu1.wang@intel.com, shuo.a.liu@intel.com, Viresh Kumar , Stefan Hajnoczi , Paolo Bonzini References: <9a2086f37c0a62069b67c39a3f75941b78a0039c.1614749417.git.jie.deng@intel.com> <43b0842b-8b0f-1979-ed07-d6124e3a6b79@redhat.com> From: Jie Deng Message-ID: Date: Thu, 11 Mar 2021 13:59:42 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/3/10 16:27, Arnd Bergmann wrote: > On Wed, Mar 10, 2021 at 4:59 AM Jason Wang wrote: >> On 2021/3/10 10:22 上午, Jie Deng wrote: >>> On 2021/3/4 17:15, Jason Wang wrote: >>>> >>>>> + } >>>>> + >>>>> + if (msgs[i].flags & I2C_M_RD) >>>>> + memcpy(msgs[i].buf, req->buf, msgs[i].len); >>>> >>>> Sorry if I had asked this before but any rason not to use msg[i].buf >>>> directly? >>>> >>>> >>> The msg[i].buf is passed by the I2C core. I just noticed that these >>> bufs are not >>> always allocated by kmalloc. They may come from the stack, which may >>> cause >>> the check "sg_init_one -> sg_set_buf -> virt_addr_valid" to fail. >>> Therefore the >>> msg[i].buf is not suitable for direct use here. >> Right, stack is virtually mapped. > Maybe there is (or should be) a way to let the i2c core code handle > the bounce buffering in this case. This is surely not a problem that > is unique to this driver, and I'm sure it has come up many times in > the past. > > I see that there is a i2c_get_dma_safe_msg_buf() helper for this > purpose, but it has to be called by the driver rather than the core, > so the driver still needs to keep track of each address when it > sends multiple i2c_msg at once, but maybe it can all be done > inside the sg_table instead of yet another structure. > > At least this one avoids copying data that is marked with the > I2C_M_DMA_SAFE flag. > > Arnd Make sense. Thanks Arnd. I will try to use those helper functions. Regards, Jie